Fix issue #838 - Load and display last notifications when clicking on a push notifications

This commit is contained in:
Thomas 2023-03-25 18:03:42 +01:00
parent 917f33334c
commit 103f030f6b
5 changed files with 16 additions and 5 deletions

View File

@ -17,6 +17,7 @@ package app.fedilab.android;
import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED; import static app.fedilab.android.BaseMainActivity.status.DISCONNECTED;
import static app.fedilab.android.BaseMainActivity.status.UNKNOWN; import static app.fedilab.android.BaseMainActivity.status.UNKNOWN;
import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir; import static app.fedilab.android.mastodon.helper.CacheHelper.deleteDir;
import static app.fedilab.android.mastodon.helper.Helper.ARG_REFRESH_NOTFICATION;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE;
import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE;
@ -672,6 +673,11 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} }
viewPager.setCurrentItem(position); viewPager.setCurrentItem(position);
} }
Bundle b = new Bundle();
b.putBoolean(ARG_REFRESH_NOTFICATION, true);
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(activity).sendBroadcast(intentBC);
} }
}, 1000); }, 1000);
intent.removeExtra(Helper.INTENT_ACTION); intent.removeExtra(Helper.INTENT_ACTION);

View File

@ -194,6 +194,8 @@ public class Helper {
public static final String RECEIVE_REDRAW_BOTTOM = "RECEIVE_REDRAW_BOTTOM"; public static final String RECEIVE_REDRAW_BOTTOM = "RECEIVE_REDRAW_BOTTOM";
public static final String RECEIVE_STATUS_ACTION = "RECEIVE_STATUS_ACTION"; public static final String RECEIVE_STATUS_ACTION = "RECEIVE_STATUS_ACTION";
public static final String RECEIVE_REFRESH_NOTIFICATIONS_ACTION = "RECEIVE_REFRESH_NOTIFICATIONS_ACTION";
public static final String RECEIVE_ERROR_MESSAGE = "RECEIVE_ERROR_MESSAGE"; public static final String RECEIVE_ERROR_MESSAGE = "RECEIVE_ERROR_MESSAGE";
public static final String RECEIVE_RECREATE_ACTIVITY = "RECEIVE_RECREATE_ACTIVITY"; public static final String RECEIVE_RECREATE_ACTIVITY = "RECEIVE_RECREATE_ACTIVITY";

View File

@ -379,7 +379,7 @@ public class NotificationsHelper {
Helper.NotifType finalNotifType = notifType; Helper.NotifType finalNotifType = notifType;
String finalMessage = message; String finalMessage = message;
String finalTitle = title; String finalTitle = title;
StatusAdapter.sendAction(context, Helper.ARG_REFRESH_NOTFICATION, null, null); StatusAdapter.sendAction(context, Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION, null, null);
Runnable myRunnable = () -> Glide.with(context) Runnable myRunnable = () -> Glide.with(context)
.asBitmap() .asBitmap()
.load(finalNotificationUrl != null ? finalNotificationUrl : R.drawable.fedilab_logo_bubbles) .load(finalNotificationUrl != null ? finalNotificationUrl : R.drawable.fedilab_logo_bubbles)

View File

@ -2726,10 +2726,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
b.putSerializable(type, status); b.putSerializable(type, status);
} }
if (id != null) { if (id != null) {
b.putSerializable(type, id); b.putString(type, id);
} }
if (type == ARG_TIMELINE_REFRESH_ALL) { if (type == ARG_TIMELINE_REFRESH_ALL) {
b.putSerializable(ARG_TIMELINE_REFRESH_ALL, true); b.putBoolean(ARG_TIMELINE_REFRESH_ALL, true);
} }
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION); Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
intentBC.putExtras(b); intentBC.putExtras(b);

View File

@ -72,7 +72,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
if (b != null) { if (b != null) {
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION);
String delete_all_for_account_id = b.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID); String delete_all_for_account_id = b.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID);
if (receivedStatus != null && notificationAdapter != null) { boolean refreshNotifications = b.getBoolean(Helper.ARG_REFRESH_NOTFICATION, false);
if (refreshNotifications) {
scrollToTop();
} else if (receivedStatus != null && notificationAdapter != null) {
int position = getPosition(receivedStatus); int position = getPosition(receivedStatus);
if (position >= 0) { if (position >= 0) {
if (notificationList.get(position).status != null) { if (notificationList.get(position).status != null) {
@ -203,7 +206,7 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
aggregateNotification = false; aggregateNotification = false;
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION)); LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_refresh, new IntentFilter(Helper.ARG_REFRESH_NOTFICATION)); LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION));
return root; return root;
} }