From f68fc11403c0043f5ee37acce245d5b929000eb8 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 11 Mar 2022 15:31:01 +0100 Subject: [PATCH] Added disabled update notification channel indication --- .../faircode/email/FragmentOptionsMisc.java | 28 +++++++++++++++++++ .../main/res/layout/fragment_options_misc.xml | 13 ++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 0024e1a8fc..f7480e2523 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -20,9 +20,11 @@ package eu.faircode.email; */ import android.app.ActivityManager; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -112,6 +114,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private TextView tvSdcard; private SwitchCompat swWatchdog; private SwitchCompat swUpdates; + private ImageButton ibChannelUpdated; private SwitchCompat swCheckWeekly; private SwitchCompat swChangelog; private SwitchCompat swExperiments; @@ -270,6 +273,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc tvSdcard = view.findViewById(R.id.tvSdcard); swWatchdog = view.findViewById(R.id.swWatchdog); swUpdates = view.findViewById(R.id.swUpdates); + ibChannelUpdated = view.findViewById(R.id.ibChannelUpdated); swCheckWeekly = view.findViewById(R.id.swWeekly); swChangelog = view.findViewById(R.id.swChangelog); swExperiments = view.findViewById(R.id.swExperiments); @@ -599,6 +603,18 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + final Intent channelUpdate = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) + .putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName()) + .putExtra(Settings.EXTRA_CHANNEL_ID, "update"); + + ibChannelUpdated.setVisibility(View.GONE); + ibChannelUpdated.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + v.getContext().startActivity(channelUpdate); + } + }); + swCheckWeekly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -1447,6 +1463,18 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc super.onResume(); resumed = true; + if (!Helper.isPlayStoreInstall() && + Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); + + NotificationChannel notification = nm.getNotificationChannel("update"); + if (notification != null) { + boolean disabled = notification.getImportance() == NotificationManager.IMPORTANCE_NONE; + ibChannelUpdated.setImageLevel(disabled ? 0 : 1); + ibChannelUpdated.setVisibility(disabled ? View.VISIBLE : View.GONE); + } + } + View view = getView(); if (view != null) view.post(new Runnable() { diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 6b1763f734..61a7cb6cc1 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -368,6 +368,17 @@ app:layout_constraintTop_toBottomOf="@id/swWatchdog" app:switchPadding="12dp" /> + +