Browse Source

Check for (changed) contacts permissions

main
M66B 6 years ago
parent
commit
afd68f3daa
2 changed files with 13 additions and 5 deletions
  1. +4
    -3
      app/src/main/java/eu/faircode/email/AdapterMessage.java
  2. +9
    -2
      app/src/main/java/eu/faircode/email/FragmentMessage.java

+ 4
- 3
app/src/main/java/eu/faircode/email/AdapterMessage.java View File

@ -145,12 +145,12 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private void bindTo(final TupleMessageEx message) {
pbLoading.setVisibility(View.GONE);
if (message.avatar != null) {
if (avatars && message.avatar != null) {
ContentResolver resolver = context.getContentResolver();
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(resolver, Uri.parse(message.avatar));
ivAvatar.setImageDrawable(Drawable.createFromStream(is, "avatar"));
}
ivAvatar.setVisibility(message.avatar == null ? View.GONE : View.VISIBLE);
ivAvatar.setVisibility(!avatars || message.avatar == null ? View.GONE : View.VISIBLE);
if (avatars && message.from != null && message.from.length > 0) {
final long id = message.id;
@ -351,7 +351,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.avatars = (prefs.getBoolean("avatars", true) &&
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED);
ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED);
this.debug = prefs.getBoolean("debug", false);
}


+ 9
- 2
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -19,11 +19,13 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -89,6 +91,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
@ -491,7 +494,9 @@ public class FragmentMessage extends FragmentEx {
setSeen();
if (message.avatar == null) {
if (message.avatar == null ||
ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
ViewGroup.LayoutParams lp = ivAvatar.getLayoutParams();
lp.height = 0;
lp.width = 0;
@ -502,7 +507,9 @@ public class FragmentMessage extends FragmentEx {
ivAvatar.setImageDrawable(Drawable.createFromStream(is, "avatar"));
}
if (message.from == null) {
if (message.from == null ||
ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
ViewGroup.LayoutParams lp = ivContactAdd.getLayoutParams();
lp.height = 0;
lp.width = 0;


Loading…
Cancel
Save