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.UNKNOWN;
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_INSTANCE;
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);
}
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);
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_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_RECREATE_ACTIVITY = "RECEIVE_RECREATE_ACTIVITY";

View file

@ -379,7 +379,7 @@ public class NotificationsHelper {
Helper.NotifType finalNotifType = notifType;
String finalMessage = message;
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)
.asBitmap()
.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);
}
if (id != null) {
b.putSerializable(type, id);
b.putString(type, id);
}
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);
intentBC.putExtras(b);

View file

@ -72,7 +72,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
if (b != null) {
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION);
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);
if (position >= 0) {
if (notificationList.get(position).status != null) {
@ -203,7 +206,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));
LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION));
return root;
}