do not show media overview in contact/conference details when missing storage permission

This commit is contained in:
Daniel Gultsch 2018-09-17 21:24:25 +02:00
parent 09eca8478e
commit bd128335d3
7 changed files with 32 additions and 13 deletions

View file

@ -259,7 +259,9 @@ public class FileBackend {
bitmap = withGifOverlay;
}
}
if (bitmap != null) {
cache.put(key, bitmap);
}
return bitmap;
}

View file

@ -110,11 +110,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) {

View file

@ -992,7 +992,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();
}

View file

@ -57,6 +57,7 @@ import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.MucDetailsContextMenuHelper;
import eu.siacs.conversations.ui.util.MyLinkify;
import eu.siacs.conversations.ui.util.SoftKeyboardUtils;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.EmojiWrapper;
import eu.siacs.conversations.utils.StringUtils;
import eu.siacs.conversations.utils.StylingHelper;
@ -290,6 +291,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (this.mTheme != theme) {
recreate();
}
binding.mediaWrapper.setVisibility(Compatibility.hasStoragePermission(this) ? View.VISIBLE : View.GONE);
}
@Override
@ -486,9 +488,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (uuid != null) {
this.mConversation = xmppConnectionService.findConversationByUuid(uuid);
if (this.mConversation != null) {
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));
this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, mConversation));
}
updateView();
}
}

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui;
import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
@ -11,6 +12,7 @@ import android.preference.PreferenceManager;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
@ -45,6 +47,7 @@ import eu.siacs.conversations.ui.interfaces.OnMediaLoaded;
import eu.siacs.conversations.ui.util.Attachment;
import eu.siacs.conversations.ui.util.GridManager;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.IrregularUnicodeDetector;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.XmppUri;
@ -217,6 +220,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());
}
@ -489,9 +493,11 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
mPendingFingerprintVerificationUri = null;
}
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));
this.binding.showMedia.setOnClickListener((v) -> MediaBrowserActivity.launch(this, contact));
}
populateView();
}
}

View file

@ -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) {

View file

@ -2,12 +2,14 @@ package eu.siacs.conversations.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.PreferenceGroup;
import android.preference.PreferenceManager;
import android.support.annotation.BoolRes;
import android.support.v4.content.ContextCompat;
import java.util.Arrays;
import java.util.Collections;
@ -28,6 +30,10 @@ public class Compatibility {
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;
}