diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java
index d7e6a4c7eb..8f92c0c65a 100644
--- a/app/src/main/java/eu/faircode/email/FragmentMessages.java
+++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java
@@ -2627,10 +2627,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
- if ("pro".equals(key)) {
+ if ("pro".equals(key) || "banner".equals(key)) {
boolean pro = ActivityBilling.isPro(getContext());
+ boolean banner = prefs.getBoolean("banner", true);
grpSupport.setVisibility(
- !pro && viewType == AdapterMessage.ViewType.UNIFIED
+ !pro && banner && 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 2257f1af0e..6ee64c051c 100644
--- a/app/src/main/java/eu/faircode/email/FragmentPro.java
+++ b/app/src/main/java/eu/faircode/email/FragmentPro.java
@@ -19,6 +19,9 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
@@ -29,6 +32,8 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
@@ -39,10 +44,13 @@ import androidx.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
+import java.util.Date;
+
public class FragmentPro extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private TextView tvPending;
private TextView tvActivated;
private TextView tvInfo;
+ private CheckBox cbHide;
private TextView tvList;
private Button btnPurchase;
private TextView tvPrice;
@@ -55,7 +63,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.menu_pro);
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean debug = prefs.getBoolean("debug", false);
View view = inflater.inflate(R.layout.fragment_pro, container, false);
@@ -63,6 +71,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
tvPending = view.findViewById(R.id.tvPending);
tvActivated = view.findViewById(R.id.tvActivated);
tvInfo = view.findViewById(R.id.tvInfo);
+ cbHide = view.findViewById(R.id.cbHide);
tvList = view.findViewById(R.id.tvList);
btnPurchase = view.findViewById(R.id.btnPurchase);
tvPrice = view.findViewById(R.id.tvPrice);
@@ -74,6 +83,33 @@ 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);
+
+ cbHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ prefs.edit().putBoolean("banner", !isChecked).apply();
+
+ Intent daily = new Intent(getContext(), ServiceUI.class);
+ daily.setAction("daily");
+ PendingIntent pi = PendingIntent.getService(getContext(), ServiceUI.PI_DAILY, daily, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
+ if (isChecked) {
+ long now = new Date().getTime();
+ long interval = AlarmManager.INTERVAL_DAY;
+ 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);
+ } else {
+ Log.i("Cancel banner alarm");
+ am.cancel(pi);
+ }
+ }
+ });
+
tvList.setPaintFlags(tvList.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvList.setOnClickListener(new View.OnClickListener() {
@Override
@@ -104,6 +140,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
tvPending.setVisibility(View.GONE);
tvActivated.setVisibility(View.GONE);
+ cbHide.setVisibility(View.GONE);
btnPurchase.setEnabled(false);
tvPrice.setText(null);
btnCheck.setEnabled(false);
@@ -187,9 +224,11 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
if ("pro".equals(key)) {
boolean pro = ActivityBilling.isPro(getContext());
tvActivated.setVisibility(pro ? View.VISIBLE : View.GONE);
+ cbHide.setVisibility(pro ? View.GONE : View.VISIBLE);
if (!Helper.isPlayStoreInstall())
btnPurchase.setEnabled(!pro || BuildConfig.DEBUG);
- }
+ } else if ("banner".equals(key))
+ cbHide.setChecked(!prefs.getBoolean(key, true));
}
}
diff --git a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java
index bfbd6c8d35..63d46c2cc4 100644
--- a/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java
+++ b/app/src/main/java/eu/faircode/email/ReceiverAutoStart.java
@@ -34,7 +34,7 @@ public class ReceiverAutoStart extends BroadcastReceiver {
Log.i("Received " + intent);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
- prefs.edit().remove("last_vacuum").apply();
+ prefs.edit().remove("banner").apply();
ServiceSynchronize.boot(context);
ServiceSend.boot(context);
diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java
index eaa1cd2d50..a9ac09b154 100644
--- a/app/src/main/java/eu/faircode/email/ServiceUI.java
+++ b/app/src/main/java/eu/faircode/email/ServiceUI.java
@@ -52,6 +52,7 @@ public class ServiceUI extends IntentService {
static final int PI_IGNORED = 10;
static final int PI_THREAD = 11;
static final int PI_WAKEUP = 12;
+ static final int PI_DAILY = 13;
public ServiceUI() {
this(ServiceUI.class.getName());
@@ -151,6 +152,10 @@ public class ServiceUI extends IntentService {
// https://developer.android.com/reference/android/app/AlarmManager
onWakeup(id);
break;
+
+ case "daily":
+ onDaily();
+ break;
default:
throw new IllegalArgumentException("Unknown UI action: " + parts[0]);
}
@@ -403,4 +408,9 @@ public class ServiceUI extends IntentService {
db.endTransaction();
}
}
+
+ private void onDaily() {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ prefs.edit().remove("banner").apply();
+ }
}
diff --git a/app/src/main/res/layout/fragment_pro.xml b/app/src/main/res/layout/fragment_pro.xml
index abaa02e032..124f256acc 100644
--- a/app/src/main/res/layout/fragment_pro.xml
+++ b/app/src/main/res/layout/fragment_pro.xml
@@ -42,6 +42,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvActivated" />
+
+
+ app:layout_constraintTop_toBottomOf="@id/cbHide" />