Skip to content

Commit

Permalink
add notification to history
Browse files Browse the repository at this point in the history
add notification to history
  • Loading branch information
marunjar committed Apr 2, 2024
1 parent 3bf4300 commit 9d4cb9a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 16 deletions.
19 changes: 18 additions & 1 deletion app/src/main/java/fr/neamar/kiss/DataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/fr/neamar/kiss/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
removePreference("advanced", "enable-notifications");
removePreference("alternate-history-inputs-section", "enable-notification-history");
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
removePreference("icons-section", DrawableUtils.KEY_THEMED_ICONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

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

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -195,4 +220,5 @@ private boolean isGroupHeader(Notification notification) {
return false;
}
}

}
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="menu_exclude">App ausblenden …</string>
<string name="enable_phone">Eingehende Anrufe im Verlauf anzeigen</string>
<string name="enable_app">Neu installierte Apps im Verlauf anzeigen</string>
<string name="enable_notification_history">Apps mit neuen Benachrichtigungen im Verlauf anzeigen</string>
<string name="enable_favorites_bar">Favoriten über der Suchleiste anzeigen</string>
<string name="favorites_hide">Favoritenleiste zunächst ausblenden</string>
<string name="exclude_favorites_history">Favoriten im Verlauf ausblenden</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<string name="toast_favorites_added">%s was added to favorites</string>
<string name="enable_phone">Show incoming calls in history</string>
<string name="enable_app">Show newly installed apps in history</string>
<string name="enable_notification_history">Show apps with new notifications in history</string>
<string name="enable_favorites_bar">Show favorites above search bar</string>
<string name="exclude_favorites_apps">Exclude favorites from apps list</string>
<string name="exclude_favorites_history">Exclude favorites from history</string>
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
android:title="@string/freeze_history_name" />
<PreferenceCategory
android:order="50"
android:title="@string/alternate_history_inputs">
android:title="@string/alternate_history_inputs"
android:key="alternate-history-inputs-section">
<fr.neamar.kiss.preference.SwitchPreference
android:defaultValue="false"
android:key="enable-phone-history"
Expand All @@ -42,6 +43,10 @@
android:defaultValue="true"
android:key="enable-app-history"
android:title="@string/enable_app" />
<fr.neamar.kiss.preference.SwitchPreference
android:defaultValue="false"
android:key="enable-notification-history"
android:title="@string/enable_notification_history" />
</PreferenceCategory>
<PreferenceCategory
android:key="exclude_apps_category"
Expand Down

0 comments on commit 9d4cb9a

Please sign in to comment.