Fix issue #361 - Allow to turn off remember position in settings

This commit is contained in:
Thomas 2022-10-25 11:16:26 +02:00
parent f3422871bc
commit 23ce0c4b06
3 changed files with 15 additions and 3 deletions

View file

@ -142,6 +142,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private String slug; private String slug;
private TimelinesVM.TimelineParams timelineParams; private TimelinesVM.TimelineParams timelineParams;
private boolean canBeFederated; private boolean canBeFederated;
private boolean rememberPosition;
@Override @Override
public void onResume() { public void onResume() {
@ -272,8 +273,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
binding.loader.setVisibility(View.VISIBLE); binding.loader.setVisibility(View.VISIBLE);
binding.recyclerView.setVisibility(View.GONE); binding.recyclerView.setVisibility(View.GONE);
max_id = statusReport != null ? statusReport.id : null; max_id = statusReport != null ? statusReport.id : null;
rememberPosition = sharedpreferences.getBoolean(getString(R.string.SET_REMEMBER_POSITION), true);
//Inner marker are only for pinned timelines and main timelines, they have isViewInitialized set to false //Inner marker are only for pinned timelines and main timelines, they have isViewInitialized set to false
if (max_id == null && !isViewInitialized) { if (max_id == null && !isViewInitialized && rememberPosition) {
max_id = sharedpreferences.getString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null); max_id = sharedpreferences.getString(getString(R.string.SET_INNER_MARKER) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance + slug, null);
} }
//Only fragment in main view pager should not have the view initialized //Only fragment in main view pager should not have the view initialized
@ -483,8 +486,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
} }
}); });
//For home (first tab) we fetch new messages //For first tab we fetch new messages, if we keep position
if (timelineType == Timeline.TimeLineEnum.HOME) { if (slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 && rememberPosition) {
route(DIRECTION.FETCH_NEW, true); route(DIRECTION.FETCH_NEW, true);
} }
} }

View file

@ -929,6 +929,8 @@
<string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string> <string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string>
<string name="SET_NOTIF_SILENT" translatable="false">SET_NOTIF_SILENT</string> <string name="SET_NOTIF_SILENT" translatable="false">SET_NOTIF_SILENT</string>
<string name="SET_REMEMBER_POSITION" translatable="false">SET_REMEMBER_POSITION</string>
<string name="SET_EXPAND_CW" translatable="false">SET_EXPAND_CW</string> <string name="SET_EXPAND_CW" translatable="false">SET_EXPAND_CW</string>
<string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string> <string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string>
<string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string> <string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string>
@ -1483,4 +1485,5 @@
<string name="set_display_counters">Display counters</string> <string name="set_display_counters">Display counters</string>
<string name="set_display_counters_description">Will display a bubble counter in tab timelines for new messages</string> <string name="set_display_counters_description">Will display a bubble counter in tab timelines for new messages</string>
<string name="view_the_original_message">Open the original message</string> <string name="view_the_original_message">Open the original message</string>
<string name="remember_position">Remember position in timelines</string>
</resources> </resources>

View file

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
android:defaultValue="true"
app:iconSpaceReserved="false"
app:key="@string/SET_REMEMBER_POSITION"
app:singleLineTitle="false"
app:title="@string/remember_position" />
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:defaultValue="false" android:defaultValue="false"
app:iconSpaceReserved="false" app:iconSpaceReserved="false"