diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index be21a322be..a189ee242e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3132,11 +3132,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if ("pro".equals(key) || "banner".equals(key)) { + if ("pro".equals(key) || "banner_hidden".equals(key)) { boolean pro = ActivityBilling.isPro(getContext()); - boolean banner = prefs.getBoolean("banner", true); + long banner_hidden = prefs.getLong("banner_hidden", 0); grpSupport.setVisibility( - !pro && banner && viewType == AdapterMessage.ViewType.UNIFIED + !pro && banner_hidden == 0 && viewType == AdapterMessage.ViewType.UNIFIED ? View.VISIBLE : View.GONE); } } diff --git a/app/src/main/java/eu/faircode/email/FragmentPro.java b/app/src/main/java/eu/faircode/email/FragmentPro.java index 12b28f5cb8..2b5ca506e8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentPro.java +++ b/app/src/main/java/eu/faircode/email/FragmentPro.java @@ -78,13 +78,12 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha tvInfo.setText(getString(R.string.title_pro_info) .replaceAll("^\\s+", "").replaceAll("\\s+", " ")); - boolean banner = prefs.getBoolean("banner", true); - cbHide.setChecked(!banner); + long banner_hidden = prefs.getLong("banner_hidden", 0); + cbHide.setChecked(banner_hidden > 0); cbHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - prefs.edit().putBoolean("banner", !isChecked).apply(); ServiceUI.scheduleBanner(getContext(), isChecked); } }); @@ -204,7 +203,9 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha boolean pro = ActivityBilling.isPro(getContext()); tvActivated.setVisibility(pro ? View.VISIBLE : View.GONE); cbHide.setVisibility(pro ? View.GONE : View.VISIBLE); - } else if ("banner".equals(key)) - cbHide.setChecked(!prefs.getBoolean(key, true)); + } else if ("banner_hidden".equals(key)) { + long banner_hidden = prefs.getLong("banner_hidden", 0); + cbHide.setChecked(banner_hidden > 0); + } } } diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java index 891847fa76..ac11d4ad78 100644 --- a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java +++ b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java @@ -22,9 +22,6 @@ package eu.faircode.email; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; - -import androidx.preference.PreferenceManager; public class ReceiverAutoStart extends BroadcastReceiver { @Override @@ -33,11 +30,9 @@ public class ReceiverAutoStart extends BroadcastReceiver { Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) { Log.i("Received " + intent); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().remove("banner").apply(); - ServiceSynchronize.boot(context); ServiceSend.boot(context); + ServiceUI.boot(context); WorkerCleanup.queueOnce(context); } } diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 79852a09d9..5c15dc3d3b 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -475,7 +475,7 @@ public class ServiceUI extends IntentService { private void onBanner() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().remove("banner").apply(); + prefs.edit().remove("banner_hidden").apply(); } static void sync(Context context, Long account) { @@ -506,22 +506,37 @@ public class ServiceUI extends IntentService { } } - static void scheduleBanner(Context context, boolean set) { + private static PendingIntent getBannerIntent(Context context) { Intent banner = new Intent(context, ServiceUI.class); banner.setAction("banner"); - PendingIntent pi = PendingIntent.getService(context, ServiceUI.PI_BANNER, banner, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(context, ServiceUI.PI_BANNER, banner, PendingIntent.FLAG_UPDATE_CURRENT); + } + static void scheduleBanner(Context context, boolean set) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (set) { long now = new Date().getTime(); long interval = AlarmManager.INTERVAL_DAY * 7; long due = interval - (now % interval); long trigger = now + due; Log.i("Set banner alarm at " + new Date(trigger) + " due=" + due); - am.set(AlarmManager.RTC, trigger, pi); + am.set(AlarmManager.RTC, trigger, getBannerIntent(context)); + prefs.edit().putLong("banner_hidden", trigger).apply(); } else { Log.i("Cancel banner alarm"); - am.cancel(pi); + am.cancel(getBannerIntent(context)); + prefs.edit().remove("banner_hidden").apply(); + } + } + + static void boot(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + long banner_hidden = prefs.getLong("banner_hidden", 0); + if (banner_hidden > 0) { + Log.i("Restore banner alarm at " + new Date(banner_hidden)); + AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + am.set(AlarmManager.RTC, banner_hidden, getBannerIntent(context)); } } }