summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2022-05-21 17:45:23 +0200
committerThomas <tschneider.ac@gmail.com>2022-05-21 17:45:23 +0200
commit658685b2c72571d93bc3120e12d36044178a8907 (patch)
treee3e273a3e3a6d196e6c9f6f608238baeb527316d /app
parentc2d3ae8e40e565af810f68f163b3aaf012368042 (diff)
comment #77 - Start for grouping similar notifications
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/app/fedilab/android/client/mastodon/entities/Notification.java3
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/NotificationAdapter.java23
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java28
-rw-r--r--app/src/main/res/layout/drawer_status_notification.xml34
-rw-r--r--app/src/main/res/layout/notifications_related_accounts.xml18
-rw-r--r--app/src/main/res/values/strings.xml2
6 files changed, 105 insertions, 3 deletions
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<Notification> 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<RecyclerView.ViewH
} else if (getItemViewType(position) == TYPE_POLL) {
title = context.getString(R.string.notif_poll);
}
+ if (notification.relatedNotifications != null && notification.relatedNotifications.size() > 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<String> 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<Notification> aggregateNotifications(List<Notification> notifications) {
+ List<Notification> 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 <http://www.gnu.org/licenses>
-->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_status_container"
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
<include
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:layout_constraintTop_toTopOf="parent"
android:id="@+id/status"
layout="@layout/drawer_status" />
+ <androidx.appcompat.widget.LinearLayoutCompat
+ android:id="@+id/other_accounts"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignBottom="@+id/status"
+ android:orientation="horizontal"
+ android:visibility="gone"
+ app:layout_constraintTop_toBottomOf="@+id/status">
+
+ <androidx.appcompat.widget.AppCompatTextView
+ android:id="@+id/type_of_concat"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+ <HorizontalScrollView
+ android:id="@+id/related_accounts"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" />
+ </androidx.appcompat.widget.LinearLayoutCompat>
+
<RelativeLayout
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
android:id="@+id/container_transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:elevation="5dp"
android:visibility="gone" />
-</FrameLayout> \ No newline at end of file
+</androidx.constraintlayout.widget.ConstraintLayout> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/related_account_container"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <androidx.appcompat.widget.AppCompatImageView
+ android:id="@+id/profile_picture"
+ android:layout_width="30dp"
+ android:layout_height="30dp" />
+
+ <androidx.appcompat.widget.AppCompatTextView
+ android:id="@+id/acc"
+ android:layout_width="0dp"
+ android:layout_height="30dp"
+ android:layout_weight="1" />
+</androidx.appcompat.widget.LinearLayoutCompat> \ 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 @@
<string name="SET_ENABLE_TIME_SLOT" translatable="false">SET_ENABLE_TIME_SLOT</string>
<string name="SET_CLEAR_CACHE_EXIT" translatable="false">SET_CLEAR_CACHE_EXIT</string>
<string name="SET_DISPLAY_EMOJI" translatable="false">SET_DISPLAY_EMOJI</string>
+ <string name="SET_AGGREGATE_NOTIFICATION" translatable="false">SET_AGGREGATE_NOTIFICATION</string>
+
<string name="SET_DISPLAY_CARD" translatable="false">SET_DISPLAY_CARD</string>
<string name="SET_DISPLAY_VIDEO_PREVIEWS" translatable="false">SET_DISPLAY_VIDEO_PREVIEWS</string>
<string name="SET_NOTIFICATION_ACTION" translatable="false">SET_NOTIFICATION_ACTION</string>