From e9113453a7483aea9a5253145ff3c60ebcca6655 Mon Sep 17 00:00:00 2001 From: marunjar Date: Tue, 13 Feb 2024 21:42:37 +0100 Subject: [PATCH] fix visibility of notification preferences - hide notification preferences based on android version --- .../main/java/fr/neamar/kiss/SettingsActivity.java | 10 +++++++++- .../kiss/notification/NotificationListener.java | 6 +++++- .../kiss/preference/NotificationPreference.java | 12 +++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/neamar/kiss/SettingsActivity.java b/app/src/main/java/fr/neamar/kiss/SettingsActivity.java index 9969dcce82..6d37a85bef 100644 --- a/app/src/main/java/fr/neamar/kiss/SettingsActivity.java +++ b/app/src/main/java/fr/neamar/kiss/SettingsActivity.java @@ -16,6 +16,7 @@ import android.preference.PreferenceGroup; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; +import android.provider.Settings; import android.util.Log; import android.util.Pair; import android.view.Menu; @@ -123,8 +124,10 @@ protected void onCreate(Bundle savedInstanceState) { removePreference("history-hide-section", "pref-hide-navbar"); removePreference("history-hide-section", "pref-hide-statusbar"); } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { removePreference("advanced", "enable-notifications"); + } + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { removePreference("alternate-history-inputs-section", "enable-notification-history"); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) { @@ -649,6 +652,11 @@ public void onDenied() { dh.addToFavorites(TagsProvider.generateUniqueId(tagName)); } else if ("exclude-favorites-apps".equals(key)) { KissApplication.getApplication(this).getDataHandler().reloadApps(); + } else if ("enable-notification-history".equals(key)) { + boolean enabled = sharedPreferences.getBoolean(key, false); + if (enabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { + startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)); + } } } diff --git a/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java b/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java index e8a9f4d49f..aea9b17217 100644 --- a/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java +++ b/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java @@ -210,7 +210,11 @@ public boolean isNotificationTrivial(StatusBarNotification sbn) { } } - return notification.priority <= Notification.PRIORITY_MIN || (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0 || isGroupHeader(notification); + return notification.priority <= Notification.PRIORITY_MIN || isOngoing(notification) || isGroupHeader(notification); + } + + private boolean isOngoing(Notification notification) { + return (notification.flags & Notification.FLAG_ONGOING_EVENT) != 0; } private boolean isGroupHeader(Notification notification) { diff --git a/app/src/main/java/fr/neamar/kiss/preference/NotificationPreference.java b/app/src/main/java/fr/neamar/kiss/preference/NotificationPreference.java index cf73c67613..599d7c60b0 100644 --- a/app/src/main/java/fr/neamar/kiss/preference/NotificationPreference.java +++ b/app/src/main/java/fr/neamar/kiss/preference/NotificationPreference.java @@ -1,23 +1,21 @@ package fr.neamar.kiss.preference; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; +import android.os.Build; import android.preference.DialogPreference; +import android.provider.Settings; import android.util.AttributeSet; public class NotificationPreference extends DialogPreference { - private static final String ACTION_NOTIFICATION_LISTENER_SETTINGS = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"; - public NotificationPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void onClick(DialogInterface dialog, int which) { - super.onClick(dialog, which); - if (which == DialogInterface.BUTTON_POSITIVE) { - getContext().startActivity(new Intent(ACTION_NOTIFICATION_LISTENER_SETTINGS)); + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { + getContext().startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)); } } }