diff --git a/app/src/main/java/fr/neamar/kiss/DataHandler.java b/app/src/main/java/fr/neamar/kiss/DataHandler.java
index 0dc04cdc0..eaee49027 100644
--- a/app/src/main/java/fr/neamar/kiss/DataHandler.java
+++ b/app/src/main/java/fr/neamar/kiss/DataHandler.java
@@ -46,6 +46,7 @@
import fr.neamar.kiss.pojo.Pojo;
import fr.neamar.kiss.pojo.ShortcutPojo;
import fr.neamar.kiss.searcher.Searcher;
+import fr.neamar.kiss.utils.PackageManagerUtils;
import fr.neamar.kiss.utils.ShortcutUtil;
import fr.neamar.kiss.utils.UserHandle;
@@ -957,13 +958,29 @@ public void removeFromFavorites(UserHandle user) {
}
}
+ /**
+ * Insert launching activity of package into history
+ *
+ * @param context context
+ * @param userHandle user
+ * @param packageName packageName
+ */
+ public void addPackageToHistory(Context context, UserHandle userHandle, String packageName) {
+ ComponentName componentName = PackageManagerUtils.getLaunchingComponent(context, packageName);
+ if (componentName != null) {
+ // add new package to history
+ String pojoID = userHandle.addUserSuffixToString("app://" + componentName.getPackageName() + "/" + componentName.getClassName(), '/');
+ addToHistory(pojoID);
+ }
+ }
+
/**
* Insert specified ID (probably a pojo.id) into history
*
* @param id pojo.id of item to record
*/
public void addToHistory(String id) {
- if (id.isEmpty()) {
+ if (TextUtils.isEmpty(id)) {
return;
}
diff --git a/app/src/main/java/fr/neamar/kiss/SettingsActivity.java b/app/src/main/java/fr/neamar/kiss/SettingsActivity.java
index d51b2b5f5..6d37a85be 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,9 +124,12 @@ 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) {
removePreference("icons-section", DrawableUtils.KEY_THEMED_ICONS);
}
@@ -648,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/broadcast/PackageAddedRemovedHandler.java b/app/src/main/java/fr/neamar/kiss/broadcast/PackageAddedRemovedHandler.java
index 9afe45da6..88d429469 100644
--- a/app/src/main/java/fr/neamar/kiss/broadcast/PackageAddedRemovedHandler.java
+++ b/app/src/main/java/fr/neamar/kiss/broadcast/PackageAddedRemovedHandler.java
@@ -37,15 +37,8 @@ public static void handleEvent(@NonNull Context ctx, @Nullable String action, @N
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
if (!replacing) {
for (String packageName : packageNames) {
- Intent launchIntent = ctx.getPackageManager().getLaunchIntentForPackage(packageName);
- // launchIntent can be null for some plugin app
- if (launchIntent != null) {
- // Add new package to history
- if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("enable-app-history", true)) {
- String className = launchIntent.getComponent().getClassName();
- String pojoID = user.addUserSuffixToString("app://" + packageName + "/" + className, '/');
- KissApplication.getApplication(ctx).getDataHandler().addToHistory(pojoID);
- }
+ if (PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("enable-app-history", true)) {
+ KissApplication.getApplication(ctx).getDataHandler().addPackageToHistory(ctx, user, packageName);
}
}
}
diff --git a/app/src/main/java/fr/neamar/kiss/forwarder/ExperienceTweaks.java b/app/src/main/java/fr/neamar/kiss/forwarder/ExperienceTweaks.java
index 9eb1553bb..cef26a19c 100644
--- a/app/src/main/java/fr/neamar/kiss/forwarder/ExperienceTweaks.java
+++ b/app/src/main/java/fr/neamar/kiss/forwarder/ExperienceTweaks.java
@@ -274,7 +274,7 @@ void onGlobalLayout() {
// There's no easy way to check if a soft keyboard is visible in android, but it can be safely assumed that
// if the root layout is significantly smaller than the screen, it's been resized for a keyboard. See here:
// https://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android
- if (prefs.getBoolean("history-hide", false) && prefs.getBoolean("history-onkeyboard", false) &&
+ if (isMinimalisticModeEnabled() && prefs.getBoolean("history-onkeyboard", false) &&
mainActivity.isViewingSearchResults() && TextUtils.isEmpty(mainActivity.searchEditText.getText())) {
final View activityRootView = mainActivity.findViewById(android.R.id.content);
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
@@ -382,7 +382,7 @@ private boolean isMinimalisticModeEnabled() {
}
private boolean isMinimalisticModeEnabledForFavorites() {
- return prefs.getBoolean("history-hide", false) && prefs.getBoolean("favorites-hide", false) && prefs.getBoolean("enable-favorites-bar", true);
+ return isMinimalisticModeEnabled() && prefs.getBoolean("favorites-hide", false) && prefs.getBoolean("enable-favorites-bar", true);
}
/**
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 0a46f6b1b..aea9b1721 100644
--- a/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java
+++ b/app/src/main/java/fr/neamar/kiss/notification/NotificationListener.java
@@ -5,6 +5,8 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
+import android.os.UserManager;
+import android.preference.PreferenceManager;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
@@ -16,6 +18,9 @@
import java.util.Map;
import java.util.Set;
+import fr.neamar.kiss.KissApplication;
+import fr.neamar.kiss.utils.UserHandle;
+
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
public class NotificationListener extends NotificationListenerService {
public static final String TAG = NotificationListener.class.getSimpleName();
@@ -72,7 +77,7 @@ private void refreshAllNotifications() {
editor.apply();
- Log.v(TAG, "Refreshed all notifications for " + allKeys.toString());
+ Log.v(TAG, "Refreshed all notifications for " + allKeys);
}
@Override
@@ -115,7 +120,27 @@ public void onNotificationPosted(StatusBarNotification sbn) {
editor.putStringSet(packageKey, currentNotifications);
editor.apply();
- Log.v(TAG, "Added notification for " + packageKey + ": " + currentNotifications.toString());
+ Log.v(TAG, "Added notification for " + packageKey + ": " + currentNotifications);
+
+ addNotificationToHistory(sbn);
+ }
+ }
+
+ private void addNotificationToHistory(StatusBarNotification sbn) {
+ Context context = getBaseContext();
+ if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("enable-notification-history", false)) {
+ UserHandle userHandle = getUserHandle(context, sbn);
+ KissApplication.getApplication(context).getDataHandler().addPackageToHistory(context, userHandle, sbn.getPackageName());
+ }
+ }
+
+ private UserHandle getUserHandle(Context context, StatusBarNotification sbn) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+ UserManager manager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ android.os.UserHandle user = sbn.getUser();
+ return new UserHandle(manager.getSerialNumberForUser(user), user);
+ } else {
+ return new UserHandle();
}
}
@@ -139,7 +164,7 @@ public void onNotificationRemoved(StatusBarNotification sbn) {
}
editor.apply();
- Log.v(TAG, "Removed notification for " + packageKey + ": " + currentNotifications.toString());
+ Log.v(TAG, "Removed notification for " + packageKey + ": " + currentNotifications);
}
}
@@ -185,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) {
@@ -195,4 +224,5 @@ private boolean isGroupHeader(Notification notification) {
return false;
}
}
+
}
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 cf73c6761..599d7c60b 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));
}
}
}
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index ab5f61b58..02a6a5ba1 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -72,6 +72,7 @@
App ausblenden …
Eingehende Anrufe im Verlauf anzeigen
Neu installierte Apps im Verlauf anzeigen
+ Apps mit neuen Benachrichtigungen im Verlauf anzeigen
Favoriten über der Suchleiste anzeigen
Favoritenleiste zunächst ausblenden
Favoriten im Verlauf ausblenden
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ab578478f..068821d02 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -156,6 +156,7 @@
%s was added to favorites
Show incoming calls in history
Show newly installed apps in history
+ Show apps with new notifications in history
Show favorites above search bar
Exclude favorites from apps list
Exclude favorites from history
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 2ccb87ff7..bcb1f538e 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -33,7 +33,8 @@
android:title="@string/freeze_history_name" />
+ android:title="@string/alternate_history_inputs"
+ android:key="alternate-history-inputs-section">
+