aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-09-26 21:48:57 +0200
committerChristian Schneppe <christian@pix-art.de>2018-09-26 21:48:57 +0200
commitf4ac1f68feac3e3b19ab5932ede9d79dd14bff27 (patch)
treef45948ade6055a72a919685a3c6430969f02b761 /src
parent8cb243536bb1fbe7743ebc428d79b6f99c844444 (diff)
do not show media overview in contact/conference details when missing storage permission
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java4
-rw-r--r--src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java10
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/GridManager.java5
-rw-r--r--src/main/java/de/pixart/messenger/utils/Compatibility.java6
7 files changed, 30 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 92bb84e33..822fa6318 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -1092,7 +1092,9 @@ public class FileBackend {
bitmap = withGifOverlay;
}
}
- cache.put(key, bitmap);
+ if (bitmap != null) {
+ cache.put(key, bitmap);
+ }
return bitmap;
}
diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
index 8fa50bb08..65711ef42 100644
--- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
+++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java
@@ -1,9 +1,6 @@
package de.pixart.messenger.services;
-import android.Manifest;
import android.content.Context;
-import android.content.pm.PackageManager;
-import android.os.Build;
import android.os.PowerManager;
import android.os.SystemClock;
import android.util.Pair;
@@ -21,7 +18,6 @@ import javax.crypto.CipherOutputStream;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
-import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.DownloadableFile;
import de.pixart.messenger.utils.Compatibility;
@@ -128,11 +124,7 @@ public class AbstractConnectionManager {
}
public boolean hasStoragePermission() {
- if (!Config.ONLY_INTERNAL_STORAGE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- return mXmppConnectionService.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
- } else {
- return true;
- }
+ return Compatibility.hasStoragePermission(mXmppConnectionService);
}
public void updateConversationUi(boolean force) {
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index e356acf69..525354957 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1135,7 +1135,7 @@ public class XmppConnectionService extends Service {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
startContactObserver();
}
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
+ if (Compatibility.hasStoragePermission(this)) {
Log.d(Config.LOGTAG, "starting file observer");
new Thread(fileObserver::startWatching).start();
}
diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
index 72168ab89..070914bb8 100644
--- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java
@@ -57,6 +57,7 @@ import de.pixart.messenger.ui.util.GridManager;
import de.pixart.messenger.ui.util.MucDetailsContextMenuHelper;
import de.pixart.messenger.ui.util.MyLinkify;
import de.pixart.messenger.ui.util.SoftKeyboardUtils;
+import de.pixart.messenger.utils.Compatibility;
import de.pixart.messenger.utils.EmojiWrapper;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.StringUtils;
@@ -337,6 +338,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (this.mTheme != theme) {
recreate();
}
+ binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
}
@Override
@@ -521,9 +523,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (uuid != null) {
this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
if (this.mConversation != null) {
- final int limit = GridManager.getCurrentColumnCount(this.binding.media);
- xmppConnectionService.getAttachments(this.mConversation, limit, this);
- this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, mConversation));
+ if (Compatibility.hasStoragePermission(this)) {
+ final int limit = GridManager.getCurrentColumnCount(this.binding.media);
+ xmppConnectionService.getAttachments(this.mConversation, limit, this);
+ this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, mConversation));
+ }
updateView();
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index 3aabf08e4..1dfc80e3c 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -51,6 +51,7 @@ import de.pixart.messenger.ui.adapter.MediaAdapter;
import de.pixart.messenger.ui.interfaces.OnMediaLoaded;
import de.pixart.messenger.ui.util.Attachment;
import de.pixart.messenger.ui.util.GridManager;
+import de.pixart.messenger.utils.Compatibility;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.IrregularUnicodeDetector;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
@@ -289,6 +290,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
this.showDynamicTags = preferences.getBoolean(SettingsActivity.SHOW_DYNAMIC_TAGS, false);
this.showLastSeen = preferences.getBoolean("last_activity", false);
}
+ binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
mMediaAdapter.setAttachments(Collections.emptyList());
}
@@ -676,9 +678,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
processFingerprintVerification(mPendingFingerprintVerificationUri);
mPendingFingerprintVerificationUri = null;
}
- final int limit = GridManager.getCurrentColumnCount(this.binding.media);
- xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this);
- this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
+ if (Compatibility.hasStoragePermission(this)) {
+ final int limit = GridManager.getCurrentColumnCount(this.binding.media);
+ xmppConnectionService.getAttachments(account, contact.getJid().asBareJid(), limit, this);
+ this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
+ }
populateView();
}
}
diff --git a/src/main/java/de/pixart/messenger/ui/util/GridManager.java b/src/main/java/de/pixart/messenger/ui/util/GridManager.java
index 717fef526..ae615b051 100644
--- a/src/main/java/de/pixart/messenger/ui/util/GridManager.java
+++ b/src/main/java/de/pixart/messenger/ui/util/GridManager.java
@@ -22,6 +22,11 @@ public class GridManager {
@Override
public void onGlobalLayout() {
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ final int availableWidth = recyclerView.getMeasuredWidth();
+ if (availableWidth == 0) {
+ Log.e(Config.LOGTAG, "GridManager: available width was 0; probably because layout was hidden");
+ return;
+ }
final ColumnInfo columnInfo = calculateColumnCount(context, recyclerView.getMeasuredWidth(), desiredSize);
Log.d(Config.LOGTAG, "final count " + columnInfo.count);
if (recyclerView.getAdapter().getItemCount() != 0) {
diff --git a/src/main/java/de/pixart/messenger/utils/Compatibility.java b/src/main/java/de/pixart/messenger/utils/Compatibility.java
index 640a74083..3ebc7c4f6 100644
--- a/src/main/java/de/pixart/messenger/utils/Compatibility.java
+++ b/src/main/java/de/pixart/messenger/utils/Compatibility.java
@@ -2,12 +2,14 @@ package de.pixart.messenger.utils;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.annotation.BoolRes;
+import android.support.v4.content.ContextCompat;
import java.util.Arrays;
import java.util.Collections;
@@ -26,6 +28,10 @@ public class Compatibility {
"vibrate_on_notification");
private static final List<String> UNUESD_SETTINGS_PRE_TWENTYSIX = Collections.singletonList("more_notification_settings");
+ public static boolean hasStoragePermission(Context context) {
+ return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
+ }
+
public static boolean twentySix() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}