Fix some issues with markers

This commit is contained in:
Thomas 2022-10-05 17:26:15 +02:00
parent f11ea8fc2b
commit 919a11ec61
3 changed files with 56 additions and 3 deletions

View file

@ -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

View file

@ -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();
}

View file

@ -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) {
}
}