diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index 52359f5a79..cf24ae8040 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -1149,6 +1149,26 @@ 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");
+ var rescan = false;
+ if (nomedia) {
+ rescan = rescan || picturesNomedia.mkdir();
+ rescan = rescan || moviesNomedia.mkdir();
+ } else {
+ rescan = rescan || picturesNomedia.delete();
+ rescan = rescan || moviesNomedia.delete();
+ }
+ if (rescan) {
+ updateMediaScanner(new File(pictures, app));
+ updateMediaScanner(new File(movies, app));
+ }
+ }
+
public static boolean inConversationsDirectory(final Context context, String path) {
final File fileDirectory = new File(path).getParentFile();
for (final String type : STORAGE_TYPES) {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 3cb8825346..4a433e7a6e 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -847,6 +847,8 @@ public class XmppConnectionService extends Service {
@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
+ final var nomedia = getBooleanPreference("nomedia", R.bool.default_nomedia);
+ fileBackend.setupNomedia(nomedia);
final String action = Strings.nullToEmpty(intent == null ? null : intent.getAction());
final boolean needsForegroundService = intent != null && intent.getBooleanExtra(SystemEventReceiver.EXTRA_NEEDS_FOREGROUND_SERVICE, false);
if (needsForegroundService) {
diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java
index 8968e83d07..4afbdeb2c4 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConversationsActivity.java
@@ -757,6 +757,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
if (offerToDownloadStickers()) return;
if (openBatteryOptimizationDialogIfNeeded()) return;
if (requestNotificationPermissionIfNeeded()) return;
+ if (askAboutNomedia()) return;
xmppConnectionService.rescanStickers();
}
}
@@ -802,6 +803,24 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio
return false;
}
+ private boolean askAboutNomedia() {
+ if (getPreferences().contains("nomedia")) return false;
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Show media in gallery");
+ builder.setMessage("Would you like to show received and sent media in your system gallery?");
+ builder.setPositiveButton(R.string.yes, (dialog, which) -> {
+ getPreferences().edit().putBoolean("nomedia", false).apply();
+ });
+ builder.setNegativeButton(R.string.no, (dialog, which) -> {
+ getPreferences().edit().putBoolean("nomedia", true).apply();
+ });
+ final AlertDialog dialog = builder.create();
+ dialog.setCanceledOnTouchOutside(false);
+ dialog.show();
+ return true;
+ }
+
private boolean offerToDownloadStickers() {
int offered = getPreferences().getInt("default_stickers_offered", 0);
if (offered > 0) return false;
diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml
index b86c0476fe..89a92ff1b3 100644
--- a/src/main/res/values/defaults.xml
+++ b/src/main/res/values/defaults.xml
@@ -65,4 +65,5 @@
true
86400
true
+ true
diff --git a/src/main/res/xml/preferences_attachments.xml b/src/main/res/xml/preferences_attachments.xml
index 1d093d308a..b2484ea95c 100644
--- a/src/main/res/xml/preferences_attachments.xml
+++ b/src/main/res/xml/preferences_attachments.xml
@@ -32,6 +32,12 @@
android:key="auto_accept_unmetered"
android:title="@string/always_accept_when_unmetered"
android:summary="@string/pref_auto_accept_unmetered_summary" />
+
+
+