From 658685b2c72571d93bc3120e12d36044178a8907 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 21 May 2022 17:45:23 +0200 Subject: [PATCH] comment #77 - Start for grouping similar notifications --- .../mastodon/entities/Notification.java | 3 ++ .../ui/drawer/NotificationAdapter.java | 23 +++++++++++++ .../FragmentMastodonNotification.java | 28 +++++++++++++++ .../res/layout/drawer_status_notification.xml | 34 +++++++++++++++++-- .../layout/notifications_related_accounts.xml | 18 ++++++++++ app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/layout/notifications_related_accounts.xml diff --git a/app/src/main/java/app/fedilab/android/client/mastodon/entities/Notification.java b/app/src/main/java/app/fedilab/android/client/mastodon/entities/Notification.java index 9d63b1b4e..0202a0d0f 100644 --- a/app/src/main/java/app/fedilab/android/client/mastodon/entities/Notification.java +++ b/app/src/main/java/app/fedilab/android/client/mastodon/entities/Notification.java @@ -17,6 +17,7 @@ package app.fedilab.android.client.mastodon.entities; import com.google.gson.annotations.SerializedName; import java.util.Date; +import java.util.List; public class Notification { @@ -30,4 +31,6 @@ public class Notification { public Account account; @SerializedName("status") public Status status; + + public transient List relatedNotifications; } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java index b475d1424..0937b3c10 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java @@ -40,6 +40,7 @@ import app.fedilab.android.client.entities.Timeline; import app.fedilab.android.client.mastodon.entities.Notification; import app.fedilab.android.databinding.DrawerFollowBinding; import app.fedilab.android.databinding.DrawerStatusNotificationBinding; +import app.fedilab.android.databinding.NotificationsRelatedAccountsBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.MastodonHelper; import app.fedilab.android.viewmodel.mastodon.SearchVM; @@ -165,6 +166,28 @@ public class NotificationAdapter extends RecyclerView.Adapter 0) { + holderStatus.bindingNotification.otherAccounts.removeAllViews(); + for (Notification relativeNotif : notification.relatedNotifications) { + NotificationsRelatedAccountsBinding notificationsRelatedAccountsBinding = NotificationsRelatedAccountsBinding.inflate(LayoutInflater.from(context)); + MastodonHelper.loadPPMastodon(notificationsRelatedAccountsBinding.profilePicture, relativeNotif.account); + notificationsRelatedAccountsBinding.acc.setText(relativeNotif.account.acct); + notificationsRelatedAccountsBinding.relatedAccountContainer.setOnClickListener(v -> { + Intent intent = new Intent(context, ProfileActivity.class); + Bundle b = new Bundle(); + b.putSerializable(Helper.ARG_ACCOUNT, relativeNotif.account); + intent.putExtras(b); + ActivityOptionsCompat options = ActivityOptionsCompat + .makeSceneTransitionAnimation((Activity) context, notificationsRelatedAccountsBinding.profilePicture, context.getString(R.string.activity_porfile_pp)); + // start the new activity + context.startActivity(intent, options.toBundle()); + }); + holderStatus.bindingNotification.otherAccounts.addView(notificationsRelatedAccountsBinding.getRoot()); + } + holderStatus.bindingNotification.otherAccounts.setVisibility(View.VISIBLE); + } else { + holderStatus.bindingNotification.otherAccounts.setVisibility(View.GONE); + } holderStatus.bindingNotification.status.avatar.setOnClickListener(v -> { Intent intent = new Intent(context, ProfileActivity.class); Bundle b = new Bundle(); diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index e831e52e4..b12e190ce 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -63,6 +63,7 @@ public class FragmentMastodonNotification extends Fragment { private NotificationAdapter notificationAdapter; private NotificationTypeEnum notificationType; private List excludeType; + private boolean aggregateNotification; private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override @@ -114,6 +115,7 @@ public class FragmentMastodonNotification extends Fragment { if (getArguments() != null) { notificationType = (NotificationTypeEnum) getArguments().get(Helper.ARG_NOTIFICATION_TYPE); } + aggregateNotification = false; binding.getRoot().setBackgroundColor(ThemeHelper.getBackgroundColor(requireActivity())); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); String excludedCategories = sharedpreferences.getString(getString(R.string.SET_EXCLUDED_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, null); @@ -136,6 +138,7 @@ public class FragmentMastodonNotification extends Fragment { excludeType.add("update"); excludeType.add("status"); if (notificationType == NotificationTypeEnum.ALL) { + aggregateNotification = sharedpreferences.getBoolean(getString(R.string.SET_AGGREGATE_NOTIFICATION), true); if (excludedCategories != null) { excludeType = new ArrayList<>(); String[] categoriesArray = excludedCategories.split("\\|"); @@ -172,6 +175,7 @@ public class FragmentMastodonNotification extends Fragment { binding.loader.setVisibility(View.GONE); binding.swipeContainer.setRefreshing(false); + if (notifications == null || notifications.notifications == null) { binding.noActionText.setText(R.string.no_notifications); binding.noAction.setVisibility(View.VISIBLE); @@ -181,6 +185,9 @@ public class FragmentMastodonNotification extends Fragment { binding.noAction.setVisibility(View.GONE); binding.recyclerView.setVisibility(View.VISIBLE); } + if (aggregateNotification) { + notifications.notifications = aggregateNotifications(notifications.notifications); + } if (notificationAdapter != null && this.notifications != null) { int size = this.notifications.size(); this.notifications.clear(); @@ -227,6 +234,27 @@ public class FragmentMastodonNotification extends Fragment { } + private List aggregateNotifications(List notifications) { + List notificationList = new ArrayList<>(); + int refPosition = 0; + for (int i = 0; i < notifications.size(); i++) { + if (i != refPosition) { + if (notifications.get(i).type.equals(notifications.get(refPosition).type) && (notifications.get(i).type.equals("favourite") || notifications.get(i).type.equals("reblog"))) { + if (notificationList.size() > 0) { + if (notificationList.get(notificationList.size() - 1).relatedNotifications == null) { + notificationList.get(notificationList.size() - 1).relatedNotifications = new ArrayList<>(); + } + notificationList.get(notificationList.size() - 1).relatedNotifications.add(notifications.get(i)); + } + } else { + notificationList.add(notifications.get(i)); + refPosition = i; + } + } + } + return notificationList; + } + public void scrollToTop() { binding.recyclerView.scrollToPosition(0); } diff --git a/app/src/main/res/layout/drawer_status_notification.xml b/app/src/main/res/layout/drawer_status_notification.xml index 8c1baa6ea..b298de540 100644 --- a/app/src/main/res/layout/drawer_status_notification.xml +++ b/app/src/main/res/layout/drawer_status_notification.xml @@ -14,20 +14,48 @@ You should have received a copy of the GNU General Public License along with Fedilab; if not, see --> - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/notifications_related_accounts.xml b/app/src/main/res/layout/notifications_related_accounts.xml new file mode 100644 index 000000000..762d71347 --- /dev/null +++ b/app/src/main/res/layout/notifications_related_accounts.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8beab27b7..7b45b2427 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1367,6 +1367,8 @@ SET_ENABLE_TIME_SLOT SET_CLEAR_CACHE_EXIT SET_DISPLAY_EMOJI + SET_AGGREGATE_NOTIFICATION + SET_DISPLAY_CARD SET_DISPLAY_VIDEO_PREVIEWS SET_NOTIFICATION_ACTION