Skip to content

Commit

Permalink
fix visibility of notification preferences
Browse files Browse the repository at this point in the history
- hide notification preferences based on android version
  • Loading branch information
marunjar committed Apr 2, 2024
1 parent 9d4cb9a commit e911345
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/src/main/java/fr/neamar/kiss/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
}

0 comments on commit e911345

Please sign in to comment.