mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 23:43:07 +00:00
Refactoring
This commit is contained in:
parent
29e6fb7076
commit
fceefc1b4b
2 changed files with 20 additions and 22 deletions
|
@ -19,9 +19,6 @@ package eu.faircode.email;
|
||||||
Copyright 2018-2020 by Marcel Bokhorst (M66B)
|
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.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
@ -44,8 +41,6 @@ import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class FragmentPro extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class FragmentPro extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private TextView tvPending;
|
private TextView tvPending;
|
||||||
private TextView tvActivated;
|
private TextView tvActivated;
|
||||||
|
@ -90,23 +85,7 @@ public class FragmentPro extends FragmentBase implements SharedPreferences.OnSha
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
prefs.edit().putBoolean("banner", !isChecked).apply();
|
prefs.edit().putBoolean("banner", !isChecked).apply();
|
||||||
|
ServiceUI.schedule(getContext(), isChecked);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -505,4 +505,23 @@ public class ServiceUI extends IntentService {
|
||||||
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, piSync);
|
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, piSync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void scheduleBanner(Context context, boolean set) {
|
||||||
|
Intent banner = new Intent(context, ServiceUI.class);
|
||||||
|
banner.setAction("banner");
|
||||||
|
PendingIntent pi = PendingIntent.getService(context, ServiceUI.PI_BANNER, banner, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
||||||
|
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);
|
||||||
|
} else {
|
||||||
|
Log.i("Cancel banner alarm");
|
||||||
|
am.cancel(pi);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue