diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java index f7fb285b..2c05c18b 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonConversation.java @@ -180,6 +180,22 @@ public class FragmentMastodonConversation extends Fragment implements Conversati } + private void storeMarker() { + if (mLayoutManager != null) { + int position = mLayoutManager.findFirstVisibleItemPosition(); + if (conversationList != null && conversationList.size() > position) { + try { + Conversation conversation = conversationList.get(position); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + Timeline.TimeLineEnum.CONVERSATION, conversation.id); + editor.apply(); + } catch (Exception ignored) { + } + } + } + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -283,6 +299,19 @@ public class FragmentMastodonConversation extends Fragment implements Conversati } + @Override + public void onDestroyView() { + if (isAdded()) { + storeMarker(); + } + super.onDestroyView(); + } + + @Override + public void onPause() { + storeMarker(); + super.onPause(); + } /** * Update view and pagination when scrolling down 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 c5af13b2..57efaca2 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 @@ -430,6 +430,25 @@ public class FragmentMastodonNotification extends Fragment implements Notificati } + private void storeMarker() { + if (mLayoutManager != null) { + int position = mLayoutManager.findFirstVisibleItemPosition(); + if (notificationList != null && notificationList.size() > position) { + try { + if (notificationType == NotificationTypeEnum.ALL) { + Notification notification = notificationList.get(position); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + Timeline.TimeLineEnum.NOTIFICATION, notification.id); + editor.apply(); + TimelinesVM timelinesVM = new ViewModelProvider(FragmentMastodonNotification.this).get(TimelinesVM.class); + timelinesVM.addMarker(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, notification.id); + } + } catch (Exception ignored) { + } + } + } + } /** * Update view and pagination when scrolling down @@ -535,11 +554,15 @@ public class FragmentMastodonNotification extends Fragment implements Notificati @Override public void onDestroyView() { LocalBroadcastManager.getInstance(requireActivity()).unregisterReceiver(receive_action); + if (isAdded()) { + storeMarker(); + } super.onDestroyView(); } @Override public void onPause() { + storeMarker(); super.onPause(); } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 12b6e937..a349ec10 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -596,7 +596,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private void storeMarker() { - if (timelineType == Timeline.TimeLineEnum.HOME && mLayoutManager != null) { + if (mLayoutManager != null) { int position = mLayoutManager.findFirstVisibleItemPosition(); if (timelineStatuses != null && timelineStatuses.size() > position) { try { @@ -605,8 +605,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, status.id); editor.apply(); - timelinesVM.addMarker(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null); - + if (timelineType == Timeline.TimeLineEnum.HOME) { + timelinesVM.addMarker(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null); + } } catch (Exception ignored) { } }