From 89a0b9df4239b1619a75e2f27a7e8c42844d99f6 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 29 Sep 2019 10:51:25 +0200 Subject: [PATCH] Widget improvements --- .../email/FragmentOptionsDisplay.java | 1 + .../WidgetUnifiedRemoteViewsFactory.java | 26 +++++++++++++++---- app/src/main/res/values/colors.xml | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java index 4bb243ca5b..77de1ff95a 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java @@ -237,6 +237,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("subject_italic", checked).apply(); + WidgetUnified.update(getContext()); } }); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java index 9ccbae6e96..2da54742b7 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java @@ -32,6 +32,7 @@ import android.view.View; import android.widget.RemoteViews; import android.widget.RemoteViewsService; +import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; import java.util.ArrayList; @@ -43,9 +44,12 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot private boolean threading; private boolean subject_top; + private boolean subject_italic; private long account; private boolean unseen; private boolean flagged; + private int colorWidgetForeground; + private int colorWidgetRead; private List messages = new ArrayList<>(); WidgetUnifiedRemoteViewsFactory(final Context context, Intent intent) { @@ -67,9 +71,12 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); threading = prefs.getBoolean("threading", true); subject_top = prefs.getBoolean("subject_top", false); + subject_italic = prefs.getBoolean("subject_italic", true); account = prefs.getLong("widget." + appWidgetId + ".account", -1L); unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); + colorWidgetForeground = ContextCompat.getColor(context, R.color.colorWidgetForeground); + colorWidgetRead = ContextCompat.getColor(context, R.color.colorWidgetRead); messages.clear(); @@ -119,17 +126,26 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot SpannableString ssSubject = new SpannableString(TextUtils.isEmpty(message.subject) ? "" : message.subject); SpannableString ssAccount = new SpannableString(TextUtils.isEmpty(message.accountName) ? "" : message.accountName); - if (!message.ui_seen) { - ssFrom.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssFrom.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); - ssTime.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssTime.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); - ssSubject.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); - ssAccount.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 0, ssAccount.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + if (message.ui_seen) { + if (subject_italic) + ssSubject.setSpan(new StyleSpan(Typeface.ITALIC), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + } else { + ssFrom.setSpan(new StyleSpan(Typeface.BOLD), 0, ssFrom.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + ssTime.setSpan(new StyleSpan(Typeface.BOLD), 0, ssTime.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + ssSubject.setSpan(new StyleSpan(subject_italic ? Typeface.BOLD_ITALIC : Typeface.BOLD), 0, ssSubject.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + ssAccount.setSpan(new StyleSpan(Typeface.BOLD), 0, ssAccount.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); } views.setTextViewText(idFrom, ssFrom); views.setTextViewText(idTime, ssTime); views.setTextViewText(idSubject, ssSubject); views.setTextViewText(idAccount, ssAccount); + + views.setTextColor(idFrom, message.ui_seen ? colorWidgetRead : colorWidgetForeground); + views.setTextColor(idTime, message.ui_seen ? colorWidgetRead : colorWidgetForeground); + views.setTextColor(idSubject, message.ui_seen ? colorWidgetRead : colorWidgetForeground); + views.setTextColor(idAccount, message.ui_seen ? colorWidgetRead : colorWidgetForeground); + views.setViewVisibility(idAccount, account < 0 ? View.VISIBLE : View.GONE); } catch (Throwable ex) { diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index faa76c3b91..acd01f01e0 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -22,6 +22,7 @@ #fff #7f000000 + #ddd #ccc #ccc