From f9b87f762b1b787a11db26dc802d1a99838893ea Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 24 Nov 2022 17:33:20 +0100 Subject: [PATCH] Fix issue #534 - Allow to filter notifications for admin/moderators --- .../app/fedilab/android/helper/Helper.java | 15 +++ .../android/helper/NotificationsHelper.java | 118 ++++++++++++------ .../FragmentNotificationContainer.java | 18 +++ .../FedilabNotificationPageAdapter.java | 8 +- .../ic_baseline_person_add_alt_1_24.xml | 2 +- .../res/drawable/ic_baseline_report_24.xml | 10 ++ .../layout/popup_notification_settings.xml | 16 +++ app/src/main/res/values/strings.xml | 16 ++- app/src/main/res/xml/pref_notifications.xml | 18 +++ 9 files changed, 181 insertions(+), 40 deletions(-) create mode 100644 app/src/main/res/drawable/ic_baseline_report_24.xml diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index aa73e0441..3c2ecf296 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -1528,6 +1528,18 @@ public class Helper { channelId = "channel_status"; channelTitle = context.getString(R.string.channel_notif_status); break; + case UPDATE: + channelId = "channel_update"; + channelTitle = context.getString(R.string.channel_notif_update); + break; + case SIGN_UP: + channelId = "channel_signup"; + channelTitle = context.getString(R.string.channel_notif_signup); + break; + case REPORT: + channelId = "channel_report"; + channelTitle = context.getString(R.string.channel_notif_report); + break; default: channelId = "channel_boost"; channelTitle = context.getString(R.string.channel_notif_boost); @@ -1989,6 +2001,9 @@ public class Helper { BOOST, FAV, POLL, + UPDATE, + SIGN_UP, + REPORT, STATUS, BACKUP, STORE, diff --git a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java index 57675c2a7..18a81cfbd 100644 --- a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java @@ -158,6 +158,9 @@ public class NotificationsHelper { boolean notif_poll = prefs.getBoolean(context.getString(R.string.SET_NOTIF_POLL), true); boolean notif_fav = prefs.getBoolean(context.getString(R.string.SET_NOTIF_FAVOURITE), true); boolean notif_status = prefs.getBoolean(context.getString(R.string.SET_NOTIF_STATUS), true); + boolean notif_update = prefs.getBoolean(context.getString(R.string.SET_NOTIF_UPDATE), true); + boolean notif_signup = prefs.getBoolean(context.getString(R.string.SET_NOTIF_ADMIN_SIGNUP), true); + boolean notif_report = prefs.getBoolean(context.getString(R.string.SET_NOTIF_ADMIN_REPORT), true); final String max_id = prefs.getString(context.getString(R.string.LAST_NOTIFICATION_ID) + key, null); @@ -232,18 +235,18 @@ public class NotificationsHelper { title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reblog)); else title = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reblog)); - } - if (notification.status != null) { - if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + if (notification.status != null) { + if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + } } } break; @@ -254,18 +257,18 @@ public class NotificationsHelper { title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_favourite)); else title = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_favourite)); - } - if (notification.status != null) { - if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + if (notification.status != null) { + if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + } } } break; @@ -298,21 +301,62 @@ public class NotificationsHelper { title = context.getString(R.string.notif_poll_self); else title = context.getString(R.string.notif_poll); - } - if (notification.status != null) { - if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); - else - message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + if (notification.status != null) { + if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + } } } break; + case "update": + notifType = Helper.NotifType.UPDATE; + if (notif_update) { + title = context.getString(R.string.notif_update_push); + if (notification.status != null) { + if (notification.status.spoiler_text != null && notification.status.spoiler_text.length() > 0) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.spoiler_text)).toString(); + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + message = new SpannableString(Html.fromHtml(notification.status.content, FROM_HTML_MODE_LEGACY)).toString(); + else + message = new SpannableString(Html.fromHtml(notification.status.content)).toString(); + } + } + } + break; + case "admin.sign_up": + notifType = Helper.NotifType.SIGN_UP; + if (notif_signup) { + title = context.getString(R.string.notif_sign_up); + if (notification.account.display_name != null && notification.account.display_name.length() > 0) + message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_signed_up)); + else + message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_signed_up)); + targeted_account = notification.account.id; + } + break; + case "admin.report": + notifType = Helper.NotifType.REPORT; + if (notif_report) { + title = context.getString(R.string.notif_report); + if (notification.account.display_name != null && notification.account.display_name.length() > 0) + message = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_reported)); + else + message = String.format("@%s %s", notification.account.acct, context.getString(R.string.notif_reported)); + targeted_account = notification.account.id; + } + break; default: } if (message != null) { @@ -321,7 +365,7 @@ public class NotificationsHelper { intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Helper.INTENT_ACTION, Helper.NOTIFICATION_INTENT); intent.putExtra(Helper.PREF_KEY_ID, account.user_id); - if (targeted_account != null && notifType == Helper.NotifType.FOLLLOW) + if (targeted_account != null) intent.putExtra(Helper.INTENT_TARGETED_ACCOUNT, targeted_account); intent.putExtra(Helper.PREF_INSTANCE, account.instance); notificationUrl = notification.account.avatar; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java index 354a6b50e..97e0b50f1 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentNotificationContainer.java @@ -83,6 +83,8 @@ public class FragmentNotificationContainer extends Fragment { binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_home_24)); binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24)); binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_edit_24)); + binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_person_add_alt_1_24)); + binding.tabLayout.addTab(binding.tabLayout.newTab().setIcon(R.drawable.ic_baseline_report_24)); binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), true)); } AtomicBoolean changes = new AtomicBoolean(false); @@ -98,6 +100,8 @@ public class FragmentNotificationContainer extends Fragment { ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdatesFromPeople); ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayFollows); ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayUpdates); + ThemeHelper.changeButtonColor(requireActivity(), dialogView.displaySignups); + ThemeHelper.changeButtonColor(requireActivity(), dialogView.displayReports); DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getThumbDrawable()), ThemeHelper.getSwitchCompatThumbDrawable(requireActivity())); DrawableCompat.setTintList(DrawableCompat.wrap(dialogView.displayAllCategories.getTrackDrawable()), ThemeHelper.getSwitchCompatTrackDrawable(requireActivity())); @@ -134,6 +138,8 @@ public class FragmentNotificationContainer extends Fragment { dialogView.displayUpdatesFromPeople.setChecked(true); dialogView.displayFollows.setChecked(true); dialogView.displayUpdates.setChecked(true); + dialogView.displaySignups.setChecked(true); + dialogView.displayReports.setChecked(true); String excludedCategories = sharedpreferences.getString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null); List excludedCategoriesList = new ArrayList<>(); if (excludedCategories != null) { @@ -168,6 +174,14 @@ public class FragmentNotificationContainer extends Fragment { excludedCategoriesList.add("update"); dialogView.displayUpdates.setChecked(false); break; + case "admin.sign_up": + excludedCategoriesList.add("admin.sign_up"); + dialogView.displaySignups.setChecked(false); + break; + case "admin.report": + excludedCategoriesList.add("admin.report"); + dialogView.displayReports.setChecked(false); + break; } } } @@ -188,6 +202,10 @@ public class FragmentNotificationContainer extends Fragment { notificationType = "follow"; } else if (checkedId == R.id.display_updates) { notificationType = "update"; + } else if (checkedId == R.id.display_signups) { + notificationType = "admin.sign_up"; + } else if (checkedId == R.id.display_reports) { + notificationType = "admin.report"; } if (isChecked) { excludedCategoriesList.remove(notificationType); diff --git a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabNotificationPageAdapter.java b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabNotificationPageAdapter.java index edd50f9c1..b9ec991f7 100644 --- a/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabNotificationPageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/pageadapter/FedilabNotificationPageAdapter.java @@ -86,6 +86,12 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter { case 7: bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.UPDATES); break; + case 8: + bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_SIGNUP); + break; + case 9: + bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_REPORT); + break; } } fragmentMastodonNotification.setArguments(bundle); @@ -94,6 +100,6 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter { @Override public int getCount() { - return extended ? 8 : 2; + return extended ? 10 : 2; } } \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_person_add_alt_1_24.xml b/app/src/main/res/drawable/ic_baseline_person_add_alt_1_24.xml index 111621988..33fa9bd3b 100644 --- a/app/src/main/res/drawable/ic_baseline_person_add_alt_1_24.xml +++ b/app/src/main/res/drawable/ic_baseline_person_add_alt_1_24.xml @@ -1,7 +1,7 @@ + + diff --git a/app/src/main/res/layout/popup_notification_settings.xml b/app/src/main/res/layout/popup_notification_settings.xml index 330dcdfa5..636f6fc06 100644 --- a/app/src/main/res/layout/popup_notification_settings.xml +++ b/app/src/main/res/layout/popup_notification_settings.xml @@ -109,6 +109,22 @@ android:layout_height="wrap_content" android:text="@string/notif_display_updates" app:icon="@drawable/ic_baseline_edit_24" /> + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c8cd1be25..b4f71fbf3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -320,6 +320,9 @@ Poll Ended Messages Backup New posts + New update + New sign-up + New report Media Download Select Tone Enable time slot @@ -404,6 +407,9 @@ Vote A poll you have voted in has ended A poll you published has ended + A message you shared has been edited + A user signed-up + A user sent a report Categories Move timeline Hide timeline @@ -449,7 +455,8 @@ I agree to %1$s and %2$s server rules terms of service - Sign up + Sign-up + Sign-ups This instance works with invitations. Your account will need to be manually approved by an administrator before being usable. This field cannot be empty! Passwords don\'t match! @@ -1254,6 +1261,9 @@ SET_NOTIF_FAVOURITE SET_NOTIF_POLL SET_NOTIF_STATUS + SET_NOTIF_UPDATE + SET_NOTIF_ADMIN_SIGNUP + SET_NOTIF_ADMIN_REPORT SET_FONT_SCALE SET_MAX_INDENTATION SET_FONT_SCALE_INT @@ -1904,6 +1914,7 @@ Delete timeline Submitted a report Signed up + sent a report Suggestions Not interested Blocked domains @@ -1916,4 +1927,7 @@ Delete the pinned timelines? Domains Keep notifications + Notify for updates + New sign-up (moderators) + New report (moderators) \ No newline at end of file diff --git a/app/src/main/res/xml/pref_notifications.xml b/app/src/main/res/xml/pref_notifications.xml index 9c4e7cb65..a6fe7ac3b 100644 --- a/app/src/main/res/xml/pref_notifications.xml +++ b/app/src/main/res/xml/pref_notifications.xml @@ -77,6 +77,24 @@ app:key="@string/SET_NOTIF_STATUS" app:singleLineTitle="false" app:title="@string/set_notif_status" /> + + +