|
|
|
@ -19,9 +19,6 @@ package eu.faircode.email;
|
|
|
|
|
Copyright 2018-2020 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;
|
|
|
|
@ -44,8 +41,6 @@ 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;
|
|
|
|
@ -90,23 +85,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
|
prefs.edit().putBoolean("banner", !isChecked).apply();
|
|
|
|
|
|
|
|
|
|
Intent banner = new Intent(getContext(), ServiceUI.class);
|
|
|
|
|
banner.setAction("banner");
|
|
|
|
|
PendingIntent pi = PendingIntent.getService(getContext(), ServiceUI.PI_BANNER, banner, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
|
|
|
|
|
AlarmManager am = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
if (isChecked) {
|
|
|
|
|
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);
|
|
|
|
|
} else {
|
|
|
|
|
Log.i("Cancel banner alarm");
|
|
|
|
|
am.cancel(pi);
|
|
|
|
|
}
|
|
|
|
|
ServiceUI.schedule(getContext(), isChecked);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|