From 77653d298b9a0a580f6db8c4040f21e9ebd95162 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 29 Mar 2021 09:18:04 +0200 Subject: [PATCH] Apply sync on launch to widgets --- app/src/main/java/eu/faircode/email/ActivityView.java | 7 ++++++- app/src/main/java/eu/faircode/email/ActivityWidget.java | 1 + .../main/java/eu/faircode/email/ActivityWidgetSync.java | 1 + .../main/java/eu/faircode/email/ActivityWidgetUnified.java | 1 + app/src/main/java/eu/faircode/email/Widget.java | 4 ++++ app/src/main/java/eu/faircode/email/WidgetUnified.java | 2 ++ 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index efa4989319..16b908eee3 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -1011,7 +1011,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB intent.removeExtra("refresh"); setIntent(intent); - ServiceUI.sync(this, null); + int version = intent.getIntExtra("version", 0); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityView.this); + boolean sync_on_launch = prefs.getBoolean("sync_on_launch", false); + if (sync_on_launch || version < 1541) + ServiceUI.sync(this, null); } String action = intent.getAction(); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidget.java b/app/src/main/java/eu/faircode/email/ActivityWidget.java index 600ea97ba9..940f38deed 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidget.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidget.java @@ -163,6 +163,7 @@ public class ActivityWidget extends ActivityBase { editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".layout", rbNew.isChecked() ? 1 : 0); + editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE); editor.apply(); Widget.init(ActivityWidget.this, appWidgetId); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java index 6aaaad30db..ff0956d1b2 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetSync.java @@ -102,6 +102,7 @@ public class ActivityWidgetSync extends ActivityBase { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("widget." + appWidgetId + ".semi", cbSemiTransparent.isChecked()); editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); + editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE); editor.apply(); WidgetSync.init(ActivityWidgetSync.this, appWidgetId); diff --git a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java index a97506bad7..43f1308963 100644 --- a/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/ActivityWidgetUnified.java @@ -155,6 +155,7 @@ public class ActivityWidgetUnified extends ActivityBase { editor.putInt("widget." + appWidgetId + ".background", btnColor.getColor()); editor.putInt("widget." + appWidgetId + ".font", spFontSize.getSelectedItemPosition()); editor.putInt("widget." + appWidgetId + ".padding", spPadding.getSelectedItemPosition()); + editor.putInt("widget." + appWidgetId + ".version", BuildConfig.VERSION_CODE); editor.apply(); diff --git a/app/src/main/java/eu/faircode/email/Widget.java b/app/src/main/java/eu/faircode/email/Widget.java index 9b1bd9471e..ff6aacc035 100644 --- a/app/src/main/java/eu/faircode/email/Widget.java +++ b/app/src/main/java/eu/faircode/email/Widget.java @@ -60,6 +60,7 @@ public class Widget extends AppWidgetProvider { boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); int background = prefs.getInt("widget." + appWidgetId + ".background", Color.TRANSPARENT); int layout = prefs.getInt("widget." + appWidgetId + ".layout", 0); + int version = prefs.getInt("widget." + appWidgetId + ".version", 0); List folders = db.folder().getNotifyingFolders(account); if (folders == null) @@ -72,6 +73,7 @@ public class Widget extends AppWidgetProvider { view.putExtra("account", account); view.putExtra("type", folders.get(0).type); view.putExtra("refresh", true); + view.putExtra("version", version); view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); pi = PendingIntentCompat.getActivity( context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT); @@ -80,6 +82,7 @@ public class Widget extends AppWidgetProvider { Intent view = new Intent(context, ActivityView.class); view.setAction("unified"); view.putExtra("refresh", true); + view.putExtra("version", version); view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); pi = PendingIntentCompat.getActivity( context, ActivityView.REQUEST_UNIFIED, view, PendingIntent.FLAG_UPDATE_CURRENT); @@ -87,6 +90,7 @@ public class Widget extends AppWidgetProvider { Intent view = new Intent(context, ActivityView.class); view.setAction("folders:" + account); view.putExtra("refresh", true); + view.putExtra("version", version); view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); pi = PendingIntentCompat.getActivity( context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/main/java/eu/faircode/email/WidgetUnified.java b/app/src/main/java/eu/faircode/email/WidgetUnified.java index 9c7f3d3907..ef12aaa32b 100644 --- a/app/src/main/java/eu/faircode/email/WidgetUnified.java +++ b/app/src/main/java/eu/faircode/email/WidgetUnified.java @@ -48,12 +48,14 @@ public class WidgetUnified extends AppWidgetProvider { 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); + int version = prefs.getInt("widget." + appWidgetId + ".version", 0); Intent view = new Intent(context, ActivityView.class); view.setAction("folder:" + folder); view.putExtra("account", account); view.putExtra("type", type); view.putExtra("refresh", true); + view.putExtra("version", version); view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pi = PendingIntentCompat.getActivity( context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT);