From bbaa70e396724ddc3fbd10e4f3538d50ae3d0fcf Mon Sep 17 00:00:00 2001 From: sk Date: Tue, 27 Dec 2022 21:39:41 +0100 Subject: [PATCH] add option to use uniform notif icon --- .../org/joinmastodon/android/GlobalUserPreferences.java | 3 +++ .../joinmastodon/android/PushNotificationReceiver.java | 8 ++++---- .../joinmastodon/android/fragments/SettingsFragment.java | 4 ++++ mastodon/src/main/res/values/strings_sk.xml | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 77a174218..c835d5bbe 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -28,6 +28,7 @@ public class GlobalUserPreferences{ public static boolean voteButtonForSingleChoice; public static boolean enableDeleteNotifications; public static boolean translateButtonOpenedOnly; + public static boolean uniformNotificationIcon; public static String publishButtonText; public static ThemePreference theme; public static ColorPreference color; @@ -60,6 +61,7 @@ public class GlobalUserPreferences{ voteButtonForSingleChoice=prefs.getBoolean("voteButtonForSingleChoice", true); enableDeleteNotifications=prefs.getBoolean("enableDeleteNotifications", false); translateButtonOpenedOnly=prefs.getBoolean("translateButtonOpenedOnly", false); + uniformNotificationIcon=prefs.getBoolean("uniformNotificationIcon", false); publishButtonText=prefs.getString("publishButtonText", ""); theme=ThemePreference.values()[prefs.getInt("theme", 0)]; recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>()); @@ -87,6 +89,7 @@ public class GlobalUserPreferences{ .putBoolean("disableSwipe", disableSwipe) .putBoolean("enableDeleteNotifications", enableDeleteNotifications) .putBoolean("translateButtonOpenedOnly", translateButtonOpenedOnly) + .putBoolean("uniformNotificationIcon", uniformNotificationIcon) .putString("publishButtonText", publishButtonText) .putInt("theme", theme.ordinal()) .putString("color", color.name()) diff --git a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java index 664cc5c8f..93de3b0a1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java @@ -8,9 +8,7 @@ import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.graphics.Bitmap; import android.graphics.drawable.Drawable; -import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; @@ -137,20 +135,22 @@ public class PushNotificationReceiver extends BroadcastReceiver{ builder.setContentTitle(pn.title) .setContentText(pn.body) .setStyle(new Notification.BigTextStyle().bigText(pn.body)) + .setSmallIcon(R.drawable.ic_ntf_logo) .setContentIntent(PendingIntent.getActivity(context, accountID.hashCode() & 0xFFFF, contentIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT)) .setWhen(notification==null ? System.currentTimeMillis() : notification.createdAt.toEpochMilli()) .setShowWhen(true) .setCategory(Notification.CATEGORY_SOCIAL) .setAutoCancel(true) .setColor(context.getColor(R.color.primary_700)); - switch (pn.notificationType) { + + if (!GlobalUserPreferences.uniformNotificationIcon) switch (pn.notificationType) { case FAVORITE -> builder.setSmallIcon(R.drawable.ic_fluent_star_24_filled); case REBLOG -> builder.setSmallIcon(R.drawable.ic_fluent_arrow_repeat_all_24_filled); case FOLLOW -> builder.setSmallIcon(R.drawable.ic_fluent_person_add_24_filled); case MENTION -> builder.setSmallIcon(R.drawable.ic_fluent_mention_24_filled); case POLL -> builder.setSmallIcon(R.drawable.ic_fluent_poll_24_filled); - default -> builder.setSmallIcon(R.drawable.ic_ntf_logo); } + if(avatar!=null){ builder.setLargeIcon(UiUtils.getBitmapFromDrawable(avatar)); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java index f590de406..fa1a442a7 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java @@ -152,6 +152,10 @@ public class SettingsFragment extends MastodonToolbarFragment{ .show(); }); })); + items.add(new SwitchItem(R.string.sk_settings_uniform_icon_for_notifications, R.drawable.ic_ntf_logo, GlobalUserPreferences.uniformNotificationIcon, i->{ + GlobalUserPreferences.uniformNotificationIcon =i.checked; + GlobalUserPreferences.save(); + })); items.add(new HeaderItem(R.string.settings_behavior)); items.add(new SwitchItem(R.string.sk_settings_show_federated_timeline, R.drawable.ic_fluent_earth_24_regular, GlobalUserPreferences.showFederatedTimeline, i->{ diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 34b089a9f..c061e97fd 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -101,4 +101,5 @@ Reblogged as %s Already reblogged Reply with other account + Uniform icon for all notifications \ No newline at end of file