From 2fa0d298cf371a33f9727e16c887059de9b59db2 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 11 Oct 2018 11:59:56 +0000 Subject: [PATCH] Added main enable/disable in advanced settings --- .../main/java/eu/faircode/email/FragmentOptions.java | 11 +++++++++++ .../java/eu/faircode/email/ServiceSynchronize.java | 9 ++++++++- app/src/main/res/layout/fragment_options.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 32f8bf6f..895a0de1 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -32,6 +32,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; public class FragmentOptions extends FragmentEx { + private CheckBox cbEnabled; private CheckBox cbAvatars; private CheckBox cbLight; private CheckBox cbBrowse; @@ -45,6 +46,7 @@ public class FragmentOptions extends FragmentEx { View view = inflater.inflate(R.layout.fragment_options, container, false); // Get controls + cbEnabled = view.findViewById(R.id.cbEnabled); cbAvatars = view.findViewById(R.id.cbAvatars); cbLight = view.findViewById(R.id.cbLight); cbBrowse = view.findViewById(R.id.cbBrowse); @@ -54,6 +56,15 @@ public class FragmentOptions extends FragmentEx { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + cbEnabled.setChecked(prefs.getBoolean("enabled", true)); + cbEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("enabled", checked).apply(); + ServiceSynchronize.reload(getContext(), "enabled"); + } + }); + cbAvatars.setChecked(prefs.getBoolean("avatars", true)); cbAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 6aa12453..1789fc0c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -984,7 +984,7 @@ public class ServiceSynchronize extends LifecycleService { public void onReceive(Context context, Intent intent) { // Receiver runs on main thread // Receiver has a wake lock for ~10 seconds - EntityLog.log(context, account.name + " keep alive"); + EntityLog.log(context, account.name + " keep alive wake lock=" + wl.isHeld()); state.thread.interrupt(); yieldWakelock(); } @@ -1939,6 +1939,13 @@ public class ServiceSynchronize extends LifecycleService { private void start() { EntityLog.log(ServiceSynchronize.this, "Main start"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this); + if (!prefs.getBoolean("enabled", true)) { + EntityLog.log(ServiceSynchronize.this, "Not enabled, halt"); + stopSelf(); + return; + } + state = new ServiceState(); state.thread = new Thread(new Runnable() { private List threadState = new ArrayList<>(); diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 3316dbf6..625094ab 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -11,6 +11,16 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + app:layout_constraintTop_toBottomOf="@id/cbEnabled" /> Dark theme Advanced options + Enabled Show contact photos Use notification light Browse messages on the server