From c8ff96f2b705c05722efe54591fa6544b11af09a Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 5 Mar 2022 18:54:18 +0100 Subject: [PATCH] Widget: refactoring --- .../main/java/eu/faircode/email/Widget.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Widget.java b/app/src/main/java/eu/faircode/email/Widget.java index 69d20d3740..7acbe95ee2 100644 --- a/app/src/main/java/eu/faircode/email/Widget.java +++ b/app/src/main/java/eu/faircode/email/Widget.java @@ -113,29 +113,18 @@ public class Widget extends AppWidgetProvider { views.setOnClickPendingIntent(R.id.background, pi); - if (background == Color.TRANSPARENT) { - if (semi) - views.setInt(R.id.background, "setBackgroundResource", R.drawable.widget_background); + // Set background + if (semi) + if (background == Color.TRANSPARENT) + views.setInt(R.id.background, "setBackgroundResource", + R.drawable.widget_background); else - views.setInt(R.id.background, "setBackgroundColor", background); - - views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground); - views.setTextColor(R.id.tvCount, colorWidgetForeground); - views.setTextColor(R.id.tvAccount, colorWidgetForeground); - } else { - float lum = (float) ColorUtils.calculateLuminance(background); - - if (semi) - background = ColorUtils.setAlphaComponent(background, 127); - + views.setInt(R.id.background, "setBackgroundColor", + ColorUtils.setAlphaComponent(background, 127)); + else views.setInt(R.id.background, "setBackgroundColor", background); - int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); - views.setInt(R.id.ivMessage, "setColorFilter", fg); - views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground); - views.setTextColor(R.id.tvAccount, fg); - } - + // Set image if (layout == 1) views.setImageViewResource(R.id.ivMessage, unseen == 0 ? R.drawable.baseline_mail_outline_widget_24 @@ -144,9 +133,25 @@ public class Widget extends AppWidgetProvider { views.setImageViewResource(R.id.ivMessage, unseen == 0 ? R.drawable.twotone_mail_outline_24 : R.drawable.baseline_mail_24); + + // Set color + if (background == Color.TRANSPARENT) { + views.setInt(R.id.ivMessage, "setColorFilter", colorWidgetForeground); + views.setTextColor(R.id.tvCount, colorWidgetForeground); + views.setTextColor(R.id.tvAccount, colorWidgetForeground); + } else { + float lum = (float) ColorUtils.calculateLuminance(background); + int fg = (lum > 0.7f ? Color.BLACK : colorWidgetForeground); + views.setInt(R.id.ivMessage, "setColorFilter", fg); + views.setTextColor(R.id.tvCount, layout == 0 ? fg : colorWidgetForeground); + views.setTextColor(R.id.tvAccount, fg); + } + + // Set count views.setTextViewText(R.id.tvCount, unseen < 100 ? nf.format(unseen) : "99+"); views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE); + // Set account name if (!TextUtils.isEmpty(name)) { views.setTextViewText(R.id.tvAccount, name); views.setViewVisibility(R.id.tvAccount, ViewStripe.VISIBLE);