Added option to show round avatars

This commit is contained in:
M66B
2019-04-25 08:37:48 +02:00
parent 2a4ff4b49d
commit d643f1cc48
4 changed files with 40 additions and 6 deletions

View File

@@ -35,6 +35,7 @@ import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
@@ -81,6 +82,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@@ -144,6 +147,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean contacts;
private boolean search;
private boolean avatars;
private boolean circular;
private boolean flags;
private boolean preview;
private boolean autohtml;
@@ -730,9 +734,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void bindContactInfo(ContactInfo info, TupleMessageEx message) {
if (info.hasPhoto())
ivAvatar.setImageBitmap(info.getPhotoBitmap());
else
if (info.hasPhoto()) {
Bitmap bm = info.getPhotoBitmap();
if (circular) {
RoundedBitmapDrawable d = RoundedBitmapDrawableFactory.create(context.getResources(), bm);
d.setCircular(true);
ivAvatar.setImageDrawable(d);
} else
ivAvatar.setImageBitmap(info.getPhotoBitmap());
} else
ivAvatar.setImageResource(R.drawable.baseline_person_24);
ivAvatar.setVisibility(avatars ? View.VISIBLE : View.GONE);
tvFrom.setText(info.getDisplayName(name_email));
@@ -3070,6 +3080,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
this.avatars = (prefs.getBoolean("avatars", true) ||
prefs.getBoolean("identicons", false));
this.circular = prefs.getBoolean("circular", false);
this.flags = prefs.getBoolean("flags", true);
this.preview = prefs.getBoolean("preview", false);
this.autohtml = prefs.getBoolean("autohtml", false);

View File

@@ -78,6 +78,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swThreading;
private SwitchCompat swAvatars;
private SwitchCompat swIdenticons;
private SwitchCompat swCircular;
private SwitchCompat swNameEmail;
private SwitchCompat swSubjectItalic;
private SwitchCompat swFlags;
@@ -119,7 +120,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private Group grpNotification;
static String[] OPTIONS_RESTART = new String[]{
"startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
"startup", "date", "threading", "avatars", "identicons", "circular", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext",
"authentication", "debug"
@@ -128,7 +129,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private final static String[] ADVANCED_OPTIONS = new String[]{
"enabled", "schedule_start", "schedule_end",
"metered", "download", "roaming",
"startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
"startup", "date", "threading", "avatars", "identicons", "circular", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
"autoresize", "resize", "prefix_once", "autosend",
@@ -163,6 +164,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swThreading = view.findViewById(R.id.swThreading);
swAvatars = view.findViewById(R.id.swAvatars);
swIdenticons = view.findViewById(R.id.swIdenticons);
swCircular = view.findViewById(R.id.swCircular);
swNameEmail = view.findViewById(R.id.swNameEmail);
swSubjectItalic = view.findViewById(R.id.swSubjectItalic);
swFlags = view.findViewById(R.id.swFlags);
@@ -334,6 +336,13 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swCircular.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("circular", checked).apply();
}
});
swNameEmail.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -678,6 +687,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swThreading.setChecked(prefs.getBoolean("threading", true));
swAvatars.setChecked(prefs.getBoolean("avatars", true));
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
swCircular.setChecked(prefs.getBoolean("circular", false));
swNameEmail.setChecked(prefs.getBoolean("name_email", !compact));
swSubjectItalic.setChecked(prefs.getBoolean("subject_italic", true));
swFlags.setChecked(prefs.getBoolean("flags", true));