From 6ba6c15fd97f1dfe5256c813b55a06847bb32eea Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 1 Oct 2024 09:33:15 +0200 Subject: [PATCH] Added showing stars in unified widget --- .../eu/faircode/email/ActivityWidgetUnified.java | 15 +++++++++++++++ .../email/WidgetUnifiedRemoteViewsFactory.java | 13 +++++++++++++ .../main/res/layout/activity_widget_unified.xml | 12 +++++++++++- app/src/main/res/layout/item_widget_unified.xml | 13 +++++++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index b223fc9b85..04427712d6 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -63,6 +63,7 @@ public class ActivityWidgetUnified extends ActivityBase { private CheckBox cbUnseen; private CheckBox cbShowUnseen; private CheckBox cbFlagged; + private CheckBox cbShowFlagged; private CheckBox cbDayNight; private CheckBox cbHighlight; private ViewButtonColor btnHighlight; @@ -110,6 +111,7 @@ public class ActivityWidgetUnified extends ActivityBase { boolean unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); boolean show_unseen = prefs.getBoolean("widget." + appWidgetId + ".show_unseen", true); boolean flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); + boolean show_flagged = prefs.getBoolean("widget." + appWidgetId + ".show_flagged", false); boolean daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false); boolean highlight = prefs.getBoolean("widget." + appWidgetId + ".highlight", false); int highlight_color = prefs.getInt("widget." + appWidgetId + ".highlight_color", Color.TRANSPARENT); @@ -139,6 +141,7 @@ public class ActivityWidgetUnified extends ActivityBase { cbUnseen = findViewById(R.id.cbUnseen); cbShowUnseen = findViewById(R.id.cbShowUnseen); cbFlagged = findViewById(R.id.cbFlagged); + cbShowFlagged = findViewById(R.id.cbShowFlagged); cbDayNight = findViewById(R.id.cbDayNight); cbHighlight = findViewById(R.id.cbHighlight); btnHighlight = findViewById(R.id.btnHighlight); @@ -170,6 +173,15 @@ public class ActivityWidgetUnified extends ActivityBase { } }); + cbFlagged.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + cbShowFlagged.setEnabled(!isChecked); + } + }); + + cbShowFlagged.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE); + cbDayNight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -306,6 +318,7 @@ public class ActivityWidgetUnified extends ActivityBase { editor.putBoolean("widget." + appWidgetId + ".show_unseen", cbShowUnseen.isChecked()); editor.putBoolean("widget." + appWidgetId + ".daynight", cbDayNight.isChecked()); editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); + editor.putBoolean("widget." + appWidgetId + ".show_flagged", cbShowFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".highlight", cbHighlight.isChecked()); editor.putInt("widget." + appWidgetId + ".highlight_color", btnHighlight.getColor()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); @@ -436,6 +449,8 @@ public class ActivityWidgetUnified extends ActivityBase { cbShowUnseen.setChecked(show_unseen); cbShowUnseen.setEnabled(cbUnseen.isChecked()); cbFlagged.setChecked(flagged); + cbShowFlagged.setChecked(show_flagged); + cbShowFlagged.setEnabled(!flagged); cbDayNight.setChecked(daynight); cbDayNight.setVisibility(Build.VERSION.SDK_INT < Build.VERSION_CODES.S ? View.GONE : View.VISIBLE); cbHighlight.setChecked(highlight); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java index 5bbb745127..3c4c15db8a 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnifiedRemoteViewsFactory.java @@ -59,6 +59,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot private boolean unseen; private boolean show_unseen; private boolean flagged; + private boolean show_flagged; private boolean daynight; private boolean highlight; private int highlight_color; @@ -77,6 +78,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot private int colorWidgetForeground; private int colorWidgetUnread; private int colorWidgetRead; + private int colorFlagged; private int colorSeparator; private boolean pro; private boolean hasColor; @@ -112,6 +114,7 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); show_unseen = prefs.getBoolean("widget." + appWidgetId + ".show_unseen", true); flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); + show_flagged = prefs.getBoolean("widget." + appWidgetId + ".show_flagged", false); daynight = prefs.getBoolean("widget." + appWidgetId + ".daynight", false); highlight = prefs.getBoolean("widget." + appWidgetId + ".highlight", false); highlight_color = prefs.getInt("widget." + appWidgetId + ".highlight_color", Color.TRANSPARENT); @@ -149,6 +152,8 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot } else colorWidgetUnread = colorWidgetForeground; + colorFlagged = ContextCompat.getColor(context, lum > 0.7f ? R.color.lightYellowAccent : R.color.darkYellowAccent); + pro = ActivityBilling.isPro(context); DB db = DB.getInstance(context); @@ -325,6 +330,14 @@ public class WidgetUnifiedRemoteViewsFactory implements RemoteViewsService.Remot views.setTextColor(R.id.tvNotes, message.notes_color == null ? colorWidgetRead : message.notes_color); views.setViewVisibility(R.id.tvNotes, message.notes == null ? View.GONE : View.VISIBLE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + views.setImageViewResource(R.id.ivFlagged, message.ui_flagged ? R.drawable.baseline_star_24 : R.drawable.twotone_star_border_24); + views.setColorStateList(R.id.ivFlagged, "setImageTintList", + ColorStateList.valueOf(message.ui_flagged ? colorFlagged : colorSeparator)); + views.setViewVisibility(R.id.ivFlagged, !flagged && show_flagged ? View.VISIBLE : View.GONE); + } else + views.setViewVisibility(R.id.ivFlagged, View.GONE); + views.setViewVisibility(R.id.separator, separators ? View.VISIBLE : View.GONE); views.setViewVisibility(idAccount, account < 0 && !allColors && account_name ? View.VISIBLE : View.GONE); diff --git a/app/src/main/res/layout/activity_widget_unified.xml b/app/src/main/res/layout/activity_widget_unified.xml index e267f4ed3c..fb668ccd6d 100644 --- a/app/src/main/res/layout/activity_widget_unified.xml +++ b/app/src/main/res/layout/activity_widget_unified.xml @@ -77,6 +77,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbShowUnseen" /> + + + app:layout_constraintTop_toBottomOf="@id/cbShowFlagged" /> @@ -123,6 +125,17 @@ android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textColor="?android:textColorPrimary" /> + + Unread messages only Show as unread Starred messages only + Show stars Text size Padding size Show separator lines