diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index adb279d1e3..9d5a9ea56c 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -82,6 +82,16 @@ public class ActivityWidgetUnified extends ActivityBase { appWidgetId = extras.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + long account = prefs.getLong("widget." + appWidgetId + ".account", -1L); + long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L); + boolean unseen = prefs.getBoolean("widget." + appWidgetId + ".unseen", false); + boolean flagged = prefs.getBoolean("widget." + appWidgetId + ".flagged", false); + boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); + int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); + int font = prefs.getInt("widget." + appWidgetId + ".font", 0); + int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); + getSupportActionBar().setSubtitle(R.string.title_widget_title_list); setContentView(R.layout.activity_widget_unified); @@ -151,16 +161,6 @@ public class ActivityWidgetUnified extends ActivityBase { int font = spFontSize.getSelectedItemPosition(); int padding = spPadding.getSelectedItemPosition(); - if (font == 1) // tiny - font = 4; - else if (font > 1) - font--; - - if (padding == 1) // tiny - padding = 4; - else if (padding > 1) - padding--; - editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id); editor.putLong("widget." + appWidgetId + ".folder", folder == null ? -1L : folder.id); editor.putString("widget." + appWidgetId + ".type", folder == null ? null : folder.type); @@ -168,8 +168,8 @@ public class ActivityWidgetUnified extends ActivityBase { editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked()); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); - editor.putInt("widget." + appWidgetId + ".font", font); - editor.putInt("widget." + appWidgetId + ".padding", padding); + editor.putInt("widget." + appWidgetId + ".font", tinyOut(font)); + editor.putInt("widget." + appWidgetId + ".padding", tinyOut(padding)); editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE); editor.apply(); @@ -250,7 +250,14 @@ public class ActivityWidgetUnified extends ActivityBase { adapterFolder.clear(); adapterFolder.addAll(folders); - spFolder.setSelection(0); + int select = 0; + for (int i = 0; i < folders.size(); i++) + if (folders.get(i).id.equals(folder)) { + select = i; + break; + } + + spFolder.setSelection(select); } @Override @@ -273,13 +280,21 @@ public class ActivityWidgetUnified extends ActivityBase { adapterPadding.setDropDownViewResource(R.layout.spinner_item1_dropdown); spPadding.setAdapter(adapterPadding); - btnColor.setColor(Color.TRANSPARENT); + // Initialize + cbUnseen.setChecked(unseen); + cbFlagged.setChecked(flagged); + cbSemiTransparent.setChecked(semi); + btnColor.setColor(background); + spFontSize.setSelection(tinyIn(font)); + spPadding.setSelection(tinyIn(padding)); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); setResult(RESULT_CANCELED, resultValue); + Bundle args = new Bundle(); + new SimpleTask>() { @Override protected List onExecute(Context context, Bundle args) { @@ -301,6 +316,12 @@ public class ActivityWidgetUnified extends ActivityBase { adapterAccount.addAll(accounts); + for (int i = 0; i < accounts.size(); i++) + if (accounts.get(i).id.equals(account)) { + spAccount.setSelection(i); + break; + } + grpReady.setVisibility(View.VISIBLE); pbWait.setVisibility(View.GONE); } @@ -309,6 +330,24 @@ public class ActivityWidgetUnified extends ActivityBase { protected void onException(Bundle args, Throwable ex) { Log.unexpectedError(getSupportFragmentManager(), ex); } - }.execute(this, new Bundle(), "widget:accounts"); + }.execute(this, args, "widget:accounts"); + } + + private int tinyOut(int value) { + if (value == 1) // tiny + return 4; + else if (value > 1) + return value - 1; + else + return value; + } + + private int tinyIn(int value) { + if (value == 4) + return 1; + else if (value >= 1) + return value + 1; + else + return value; } } diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index 4de668ac64..6dad0bfe89 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -50,6 +50,9 @@ public class WidgetUnified extends AppWidgetProvider { int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); int version = prefs.getInt("widget." + appWidgetId + ".version", 0); + if (version <= 1550) + semi = true; // Legacy + Intent view = new Intent(context, ActivityView.class); view.setAction("folder:" + folder); view.putExtra("account", account); @@ -96,8 +99,13 @@ public class WidgetUnified extends AppWidgetProvider { views.setPendingIntentTemplate(R.id.lv, piItem); if (background == Color.TRANSPARENT) { - if (!semi && version > 1550) + if (semi) + views.setInt(R.id.widget, "setBackgroundResource", R.drawable.widget_background); + else views.setInt(R.id.widget, "setBackgroundColor", background); + + int colorWidgetForeground = context.getResources().getColor(R.color.colorWidgetForeground); + views.setTextColor(R.id.title, colorWidgetForeground); } else { float lum = (float) ColorUtils.calculateLuminance(background); @@ -110,7 +118,11 @@ public class WidgetUnified extends AppWidgetProvider { views.setTextColor(R.id.title, Color.BLACK); } + int dp6 = Helper.dp2pixels(context, 6); + views.setViewPadding(R.id.widget, dp6, 0, dp6, 0); + appWidgetManager.updateAppWidget(appWidgetId, views); + appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv); } } diff --git a/app/src/main/res/xml/widget_unified.xml b/app/src/main/res/xml/widget_unified.xml index fd14003e1a..f4a9bcbb4d 100644 --- a/app/src/main/res/xml/widget_unified.xml +++ b/app/src/main/res/xml/widget_unified.xml @@ -7,4 +7,5 @@ android:previewImage="@drawable/widget_preview_unified" android:resizeMode="horizontal|vertical" android:updatePeriodMillis="0" - android:widgetCategory="home_screen" /> + android:widgetCategory="home_screen" + android:widgetFeatures="reconfigurable" />