From 9b9174143193a9b7eecfbe8e66074121550f14fb Mon Sep 17 00:00:00 2001 From: Arne Date: Wed, 8 Jan 2025 16:00:01 +0100 Subject: [PATCH] Change to files and backup folder to Documents/monocles chat/ --- .../persistance/FileBackend.java | 32 ++++++++----------- .../services/XmppConnectionService.java | 2 +- .../ui/ConversationFragment.java | 11 +++---- .../settings/AttachmentsSettingsFragment.java | 2 +- .../chat/DownloadDefaultStickers.java | 2 +- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 2e48ec6c7a..9db588f912 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -193,7 +193,7 @@ public class FileBackend { final File conversationsDownloadDirectory = new File( Environment.getExternalStoragePublicDirectory( - Environment.DIRECTORY_DOWNLOADS), + Environment.DIRECTORY_DOCUMENTS), context.getString(R.string.app_name)); return new File(conversationsDownloadDirectory, "Backup"); } @@ -1124,23 +1124,18 @@ public class FileBackend { public File getStorageLocation(final Message message, final String filename, final String mime) { final File parentDirectory; if (Strings.isNullOrEmpty(mime)) { - parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + parentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat"); } else if (mime.startsWith("image/")) { - parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); + parentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/pictures"); } else if (mime.startsWith("video/")) { - parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); + parentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/videos"); } else if (MediaAdapter.DOCUMENT_MIMES.contains(mime)) { - parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS); + parentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/documents"); } else { - parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + parentDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat"); } final File appDirectory = - new File(parentDirectory, mXmppConnectionService.getString(R.string.app_name)); + new File(String.valueOf(parentDirectory)); if (message == null || message.getStatus() == Message.STATUS_DUMMY || (message.getConversation() instanceof Conversation && ((Conversation) message.getConversation()).storeInCache())) { final var mediaCache = new File(mXmppConnectionService.getCacheDir(), "/media"); return new File(mediaCache, filename); @@ -1150,11 +1145,10 @@ public class FileBackend { } public void setupNomedia(final boolean nomedia) { - final var pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); - final var app = mXmppConnectionService.getString(R.string.app_name); - final var picturesNomedia = new File(new File(pictures, app), ".nomedia"); - final var movies = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); - final var moviesNomedia = new File(new File(movies, app), ".nomedia"); + final var pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/pictures"); + final var picturesNomedia = new File(new File(String.valueOf(pictures)), ".nomedia"); + final var movies = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/videos"); + final var moviesNomedia = new File(new File(String.valueOf(movies)), ".nomedia"); var rescan = false; if (nomedia) { rescan = rescan || picturesNomedia.mkdir(); @@ -1164,8 +1158,8 @@ public class FileBackend { rescan = rescan || moviesNomedia.delete(); } if (rescan) { - updateMediaScanner(new File(pictures, app)); - updateMediaScanner(new File(movies, app)); + updateMediaScanner(new File(String.valueOf(pictures))); + updateMediaScanner(new File(String.valueOf(movies))); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index cb75792142..ad206a85f4 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -761,7 +761,7 @@ public class XmppConnectionService extends Service { uri = DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri)); return new File(FileUtils.getPath(getBaseContext(), uri)); } else { - return new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + dir); + return new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/monocles chat" + "/" + dir); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 0bf86c8b45..0b267eb926 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -321,16 +321,15 @@ public class ConversationFragment extends XmppFragment private Toast messageLoaderToast; private ConversationsActivity activity; private boolean reInitRequiredOnStart = true; - private int identiconWidth = -1; private File savingAsSticker = null; private EmojiSearch emojiSearch = null; private EmojiSearchOld emojiSearchOld = null; - File dirStickers = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Stickers"); + File dirStickers = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/monocles chat" + File.separator + "Stickers"); //Gifspaths private File[] files; private String[] filesPaths; private String[] filesNames; - File dirGifs = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + "Stickers" + File.separator + "Animoji"); + File dirGifs = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/monocles chat" + File.separator + "Stickers" + File.separator + "Animoji"); private KeyboardHeightProvider.KeyboardHeightListener keyboardHeightListener = null; private KeyboardHeightProvider keyboardHeightProvider = null; @@ -3417,7 +3416,7 @@ public class ConversationFragment extends XmppFragment if (dir.startsWith("content://")) { intent.putExtra("android.provider.extra.INITIAL_URI", Uri.parse(dir)); } else { - new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + dir + "/User Pack").mkdirs(); + new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/monocles chat" + "/" + dir + "/User Pack").mkdirs(); Uri uri; if (Build.VERSION.SDK_INT >= 29) { Intent tmp = ((StorageManager) activity.getSystemService(Context.STORAGE_SERVICE)).getPrimaryStorageVolume().createOpenDocumentTreeIntent(); @@ -5530,10 +5529,10 @@ public class ConversationFragment extends XmppFragment } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RECORDINGS); + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/recordings"); } else { parentDirectory = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS + "/monocles chat" + "/recordings"); } } final File conversationsDirectory = new File(parentDirectory, getString(R.string.app_name)); diff --git a/src/main/java/eu/siacs/conversations/ui/fragment/settings/AttachmentsSettingsFragment.java b/src/main/java/eu/siacs/conversations/ui/fragment/settings/AttachmentsSettingsFragment.java index ea0998c82f..42e991c704 100644 --- a/src/main/java/eu/siacs/conversations/ui/fragment/settings/AttachmentsSettingsFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/fragment/settings/AttachmentsSettingsFragment.java @@ -48,7 +48,7 @@ public class AttachmentsSettingsFragment extends XmppPreferenceFragment { final var p = PreferenceManager.getDefaultSharedPreferences(requireActivity()); final var stickerDir = findPreference("sticker_directory"); if (Build.VERSION.SDK_INT >= 29) { - stickerDir.setSummary(p.getString("sticker_directory", "Pictures/Stickers")); + stickerDir.setSummary(p.getString("sticker_directory", "Documents/monocles chat/Stickers")); stickerDir.setOnPreferenceClickListener((pref) -> { final var intent = ((StorageManager) requireActivity().getSystemService(Context.STORAGE_SERVICE)).getPrimaryStorageVolume().createOpenDocumentTreeIntent(); startActivityForResult(Intent.createChooser(intent, "Choose sticker location"), 0); diff --git a/src/monocleschat/java/de/monocles/chat/DownloadDefaultStickers.java b/src/monocleschat/java/de/monocles/chat/DownloadDefaultStickers.java index 798ef10058..9debf69c7b 100644 --- a/src/monocleschat/java/de/monocles/chat/DownloadDefaultStickers.java +++ b/src/monocleschat/java/de/monocles/chat/DownloadDefaultStickers.java @@ -183,7 +183,7 @@ public class DownloadDefaultStickers extends Service { uri = DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri)); return new File(FileUtils.getPath(getBaseContext(), uri)); } else { - return new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + dir); + return new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/monocles chat" + "/" + dir); } }