From d2cb26e325cf376eb3a06527e184c1ce03b651e1 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 14 Sep 2018 13:31:00 +0000 Subject: [PATCH] Added settings for notification light --- .../main/java/eu/faircode/email/FragmentOptions.java | 12 ++++++++++++ .../main/java/eu/faircode/email/FragmentSetup.java | 1 + .../java/eu/faircode/email/ServiceSynchronize.java | 11 ++++++++++- app/src/main/res/layout/fragment_options.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 35 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 61a64dfd..05514e27 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -35,6 +35,7 @@ import androidx.annotation.Nullable; public class FragmentOptions extends FragmentEx { private CheckBox cbCompressImap; private CheckBox cbAvatars; + private CheckBox cbLight; private CheckBox cbDebug; @Override @@ -47,6 +48,7 @@ public class FragmentOptions extends FragmentEx { // Get controls cbCompressImap = view.findViewById(R.id.cbCompressImap); cbAvatars = view.findViewById(R.id.cbAvatars); + cbLight = view.findViewById(R.id.cbLight); cbDebug = view.findViewById(R.id.cbDebug); // Wire controls @@ -77,6 +79,14 @@ public class FragmentOptions extends FragmentEx { } }); + cbLight.setChecked(prefs.getBoolean("light", false)); + cbLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("light", checked).apply(); + } + }); + cbDebug.setChecked(prefs.getBoolean("debug", false)); cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @@ -85,6 +95,8 @@ public class FragmentOptions extends FragmentEx { } }); + cbLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE); + return view; } } diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 0b1494a0..ba0f73e8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -102,6 +102,7 @@ public class FragmentSetup extends FragmentEx { static final List EXPORT_SETTINGS = Arrays.asList( "compress", "avatars", + "light", "theme" ); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f683d4fd..bb04bde1 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -26,6 +26,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.SharedPreferences; import android.media.RingtoneManager; import android.net.ConnectivityManager; import android.net.Network; @@ -270,6 +271,8 @@ public class ServiceSynchronize extends LifecycleService { } private Notification.Builder getNotificationUnseen(List messages) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + // Build pending intent Intent intent = new Intent(this, ActivityView.class); intent.setAction("unseen"); @@ -301,7 +304,13 @@ public class ServiceSynchronize extends LifecycleService { .setVisibility(Notification.VISIBILITY_PUBLIC) .setDeleteIntent(pid); - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pro", false)) { + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O && + prefs.getBoolean("light", true)) { + builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS); + builder.setLights(0xff00ff00, 1000, 1000); + } + + if (prefs.getBoolean("pro", false)) { DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); StringBuilder sb = new StringBuilder(); for (EntityMessage message : messages) { diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index ad884c77..8f4ce340 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -31,6 +31,16 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/cbCompressImap" /> + + + app:layout_constraintTop_toBottomOf="@id/cbLight" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f68378b0..ca2fceb5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -78,6 +78,7 @@ Advanced options Compress IMAP data Show contact photos + Use notification light Debug Select …