Added widget contact avatars option

pull/207/head
M66B 3 years ago
parent d578ae7efd
commit bc2f7dcad3

@ -64,6 +64,7 @@ public class ActivityWidgetUnified extends ActivityBase {
private ViewButtonColor btnColor;
private Spinner spFontSize;
private Spinner spPadding;
private CheckBox cbAvatars;
private CheckBox cbRefresh;
private CheckBox cbCompose;
private Button btnSave;
@ -102,6 +103,7 @@ public class ActivityWidgetUnified extends ActivityBase {
int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
boolean refresh = prefs.getBoolean("widget." + appWidgetId + ".refresh", false);
boolean compose = prefs.getBoolean("widget." + appWidgetId + ".compose", false);
boolean avatars = prefs.getBoolean("widget." + appWidgetId + ".avatars", false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setSubtitle(R.string.title_widget_title_list);
@ -118,6 +120,7 @@ public class ActivityWidgetUnified extends ActivityBase {
btnColor = findViewById(R.id.btnColor);
spFontSize = findViewById(R.id.spFontSize);
spPadding = findViewById(R.id.spPadding);
cbAvatars = findViewById(R.id.cbAvatars);
cbRefresh = findViewById(R.id.cbRefresh);
cbCompose = findViewById(R.id.cbCompose);
btnSave = findViewById(R.id.btnSave);
@ -227,6 +230,7 @@ public class ActivityWidgetUnified extends ActivityBase {
editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor());
editor.putInt("widget." + appWidgetId + ".font", tinyOut(font));
editor.putInt("widget." + appWidgetId + ".padding", tinyOut(padding));
editor.putBoolean("widget." + appWidgetId + ".avatars", cbAvatars.isChecked());
editor.putBoolean("widget." + appWidgetId + ".refresh", cbRefresh.isChecked());
editor.putBoolean("widget." + appWidgetId + ".compose", cbCompose.isChecked());
editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE);
@ -350,6 +354,7 @@ public class ActivityWidgetUnified extends ActivityBase {
btnColor.setColor(background);
spFontSize.setSelection(tinyIn(font));
spPadding.setSelection(tinyIn(padding));
cbAvatars.setChecked(avatars);
cbRefresh.setChecked(refresh);
cbCompose.setChecked(compose);

@ -64,6 +64,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
private int background;
private int font;
private int padding;
private boolean avatars;
private boolean prefer_contact;
private boolean only_contact;
private boolean distinguish_contacts;
@ -100,6 +101,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
subject_top = prefs.getBoolean("subject_top", false);
subject_italic = prefs.getBoolean("subject_italic", true);
color_stripe = prefs.getBoolean("color_stripe", true);
account = prefs.getLong("widget." + appWidgetId + ".account", -1L);
folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L);
unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false);
@ -111,6 +113,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT);
font = prefs.getInt("widget." + appWidgetId + ".font", 0);
padding = prefs.getInt("widget." + appWidgetId + ".padding", 0);
avatars = prefs.getBoolean("widget." + appWidgetId + ".avatars", false);
prefer_contact = prefs.getBoolean("prefer_contact", false);
only_contact = prefs.getBoolean("only_contact", false);
distinguish_contacts = prefs.getBoolean("distinguish_contacts", false);
@ -214,6 +218,12 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot
views.setInt(R.id.stripe, "setBackgroundColor", colorBackground);
views.setViewVisibility(R.id.stripe, hasColor && color_stripe ? View.VISIBLE : View.GONE);
if (avatars) {
ContactInfo[] info = ContactInfo.get(context, message.account, null, message.bimi_selector, message.from);
views.setImageViewBitmap(R.id.avatar, info.length == 0 ? null : info[0].getPhotoBitmap());
}
views.setViewVisibility(R.id.avatar, avatars ? View.VISIBLE : View.GONE);
Address[] recipients = ContactInfo.fillIn(message.from, prefer_contact, only_contact);
boolean known = (distinguish_contacts && ContactInfo.getLookupUri(message.from) != null);

@ -156,6 +156,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPadding" />
<CheckBox
android:id="@+id/cbAvatars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_widget_avatars"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spPadding" />
<CheckBox
android:id="@+id/cbRefresh"
android:layout_width="wrap_content"
@ -164,7 +174,7 @@
android:checked="true"
android:text="@string/title_widget_refresh"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spPadding" />
app:layout_constraintTop_toBottomOf="@id/cbAvatars" />
<CheckBox
android:id="@+id/cbCompose"

@ -17,6 +17,17 @@
android:layout_marginEnd="3dp"
android:background="@color/grey" />
<ImageView
android:id="@+id/avatar"
android:layout_width="36dp"
android:layout_height="match_parent"
android:layout_marginEnd="3dp"
android:adjustViewBounds="true"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

@ -1935,6 +1935,7 @@
<string name="title_widget_padding">Padding size</string>
<string name="title_widget_separator_lines">Show separator lines</string>
<string name="title_widget_semi_transparent">Semi transparent background</string>
<string name="title_widget_avatars">Show contact avatars</string>
<string name="title_widget_refresh">Show refresh messages button</string>
<string name="title_widget_compose">Show compose new message button</string>
<string name="title_widget_background">Background color</string>

Loading…
Cancel
Save