From d3bb4a285ba1665cfbb2e6b5292171e04d35145b Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 18 Jan 2023 15:42:20 +0100 Subject: [PATCH] Improve notifications --- .../java/app/fedilab/android/helper/Helper.java | 1 + .../fedilab/android/helper/NotificationsHelper.java | 2 ++ .../timeline/FragmentMastodonNotification.java | 13 +++++++++++++ .../timeline/FragmentNotificationContainer.java | 2 ++ 4 files changed, 18 insertions(+) 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 1f46300b..f8bd2dc0 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -210,6 +210,7 @@ public class Helper { public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE"; public static final String ARG_STATUS = "ARG_STATUS"; public static final String ARG_TIMELINE_REFRESH_ALL = "ARG_TIMELINE_REFRESH_ALL"; + public static final String ARG_REFRESH_NOTFICATION = "ARG_REFRESH_NOTFICATION"; public static final String ARG_STATUS_DELETED = "ARG_STATUS_DELETED"; public static final String ARG_STATUS_UPDATED = "ARG_STATUS_UPDATED"; 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 4473d48f..2df96d39 100644 --- a/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/NotificationsHelper.java @@ -17,6 +17,7 @@ package app.fedilab.android.helper; import static android.text.Html.FROM_HTML_MODE_LEGACY; import static app.fedilab.android.helper.Helper.notify_user; import static app.fedilab.android.helper.LogoHelper.getMainLogo; +import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction; import android.content.Context; import android.content.Intent; @@ -379,6 +380,7 @@ public class NotificationsHelper { Helper.NotifType finalNotifType = notifType; String finalMessage = message; String finalTitle = title; + sendAction(context, Helper.ARG_REFRESH_NOTFICATION, null, null); Runnable myRunnable = () -> Glide.with(context) .asBitmap() .load(finalNotificationUrl != null ? finalNotificationUrl : R.drawable.fedilab_logo_bubbles) 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 81797506..0404fc1d 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 @@ -64,6 +64,17 @@ public class FragmentMastodonNotification extends Fragment implements Notificati private boolean flagLoading; private List notificationList; private NotificationAdapter notificationAdapter; + private final BroadcastReceiver receive_refresh = new BroadcastReceiver() { + + @Override + public void onReceive(Context context, Intent intent) { + if (notificationType != null && notificationType == NotificationTypeEnum.ALL) { + if (notificationList != null && notificationList.size() > 0) { + route(FragmentMastodonTimeline.DIRECTION.FETCH_NEW, true); + } + } + } + }; private final BroadcastReceiver receive_action = new BroadcastReceiver() { @Override @@ -192,6 +203,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati aggregateNotification = false; LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION)); + LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_refresh, new IntentFilter(Helper.ARG_REFRESH_NOTFICATION)); return root; } @@ -655,6 +667,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati @Override public void onDestroyView() { LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action); + LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_refresh); if (isAdded()) { storeMarker(); } 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 d16fd40f..09162704 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 @@ -71,6 +71,7 @@ public class FragmentNotificationContainer extends Fragment { binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.mention))); binding.tabLayout.setTabMode(TabLayout.MODE_FIXED); binding.viewpagerNotificationContainer.setAdapter(new FedilabNotificationPageAdapter(getChildFragmentManager(), false)); + binding.viewpagerNotificationContainer.setOffscreenPageLimit(2); } else { binding.tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); binding.tabLayout.addTab(binding.tabLayout.newTab().setText(getString(R.string.all))); @@ -84,6 +85,7 @@ public class FragmentNotificationContainer extends Fragment { 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)); + binding.viewpagerNotificationContainer.setOffscreenPageLimit(10); } AtomicBoolean changes = new AtomicBoolean(false); binding.settings.setOnClickListener(v -> {