mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
Only save post feed scrolled position for front page.
This commit is contained in:
parent
109b4be8c3
commit
80b4869c6a
@ -202,7 +202,7 @@ class AppModule {
|
||||
@Provides
|
||||
@Named("post_feed_scrolled_position_cache")
|
||||
SharedPreferences providePostFeedScrolledPositionSharedPreferences() {
|
||||
return mApplication.getSharedPreferences(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
|
||||
return mApplication.getSharedPreferences(SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -369,7 +369,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
|
||||
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
|
||||
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_POST_FEED_SCROLLED_POSITION, true);
|
||||
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, true);
|
||||
Locale locale = getResources().getConfiguration().locale;
|
||||
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
@ -717,28 +717,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
private void saveCache() {
|
||||
if (savePostFeedScrolledPosition && isShown && mAdapter != null) {
|
||||
String key;
|
||||
if (savePostFeedScrolledPosition && postType == PostDataSource.TYPE_FRONT_PAGE && mAdapter != null) {
|
||||
Post currentPost = mAdapter.getItemByPosition(maxPosition);
|
||||
if (currentPost != null) {
|
||||
String accountNameForCache = accountName == null ? SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_ANONYMOUS : accountName;
|
||||
String accountNameForCache = accountName == null ? SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS : accountName;
|
||||
String key = accountNameForCache + SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE;
|
||||
String value = currentPost.getFullName();
|
||||
switch (postType) {
|
||||
case PostDataSource.TYPE_FRONT_PAGE:
|
||||
key = accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_FRONT_PAGE_BASE;
|
||||
break;
|
||||
case PostDataSource.TYPE_SUBREDDIT:
|
||||
key = accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_SUBREDDIT_BASE + subredditName;
|
||||
break;
|
||||
case PostDataSource.TYPE_USER:
|
||||
key = accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_USER_BASE + username;
|
||||
break;
|
||||
case PostDataSource.TYPE_MULTI_REDDIT:
|
||||
key = accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_MULTI_REDDIT_BASE + multiRedditPath;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
postFeedScrolledPositionSharedPreferences.edit().putString(key, value).apply();
|
||||
}
|
||||
}
|
||||
|
@ -175,39 +175,27 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull final LoadInitialCallback<String, Post> callback) {
|
||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
boolean savePostFeedScrolledPosition = sharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_POST_FEED_SCROLLED_POSITION, true);
|
||||
String accountNameForCache = accountName == null ? SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_ANONYMOUS : accountName;
|
||||
boolean savePostFeedScrolledPosition = sharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, true);
|
||||
String accountNameForCache = accountName == null ? SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS : accountName;
|
||||
switch (postType) {
|
||||
case TYPE_FRONT_PAGE:
|
||||
if (savePostFeedScrolledPosition) {
|
||||
loadBestPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_FRONT_PAGE_BASE, null));
|
||||
loadBestPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE, null));
|
||||
} else {
|
||||
loadBestPostsInitial(callback, null);
|
||||
}
|
||||
break;
|
||||
case TYPE_SUBREDDIT:
|
||||
if (savePostFeedScrolledPosition) {
|
||||
loadSubredditPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_SUBREDDIT_BASE + subredditOrUserName, null));
|
||||
} else {
|
||||
loadSubredditPostsInitial(callback, null);
|
||||
}
|
||||
loadSubredditPostsInitial(callback, null);
|
||||
break;
|
||||
case TYPE_USER:
|
||||
if (savePostFeedScrolledPosition) {
|
||||
loadUserPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_USER_BASE + subredditOrUserName, null));
|
||||
} else {
|
||||
loadUserPostsInitial(callback, null);
|
||||
}
|
||||
loadUserPostsInitial(callback, null);
|
||||
break;
|
||||
case TYPE_SEARCH:
|
||||
loadSearchPostsInitial(callback, null);
|
||||
break;
|
||||
case TYPE_MULTI_REDDIT:
|
||||
if (savePostFeedScrolledPosition) {
|
||||
loadMultiRedditPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.POST_FEED_SCROLLED_POSITION_MULTI_REDDIT_BASE + multiRedditPath, null));
|
||||
} else {
|
||||
loadMultiRedditPostsInitial(callback, null);
|
||||
}
|
||||
loadMultiRedditPostsInitial(callback, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat {
|
||||
Preference deleteSortTypePreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE);
|
||||
Preference deletePostLaoutPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE);
|
||||
Preference deleteAllThemesPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_THEMES_IN_DATABASE);
|
||||
Preference deletePostFeedScrolledPositionsPreference = findPreference(SharedPreferencesUtils.DELETE_POST_FEED_SCROLLED_POSITIONS_IN_DATABASE);
|
||||
Preference deletePostFeedScrolledPositionsPreference = findPreference(SharedPreferencesUtils.DELETE_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE);
|
||||
Preference resetAllSettingsPreference = findPreference(SharedPreferencesUtils.RESET_ALL_SETTINGS);
|
||||
|
||||
if (deleteSubredditsPreference != null) {
|
||||
|
@ -39,7 +39,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
|
||||
setPreferencesFromResource(R.xml.main_preferences, rootKey);
|
||||
((Infinity) activity.getApplication()).getAppComponent().inject(this);
|
||||
|
||||
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_POST_FEED_SCROLLED_POSITION);
|
||||
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
|
||||
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
|
||||
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
|
||||
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
|
||||
|
@ -73,12 +73,9 @@ public class SharedPreferencesUtils {
|
||||
public static final int POST_LAYOUT_CARD = 0;
|
||||
public static final int POST_LAYOUT_COMPACT = 1;
|
||||
|
||||
public static final String POST_FEED_SCROLLED_POSITION_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_feed_scrolled_position";
|
||||
public static final String POST_FEED_SCROLLED_POSITION_FRONT_PAGE_BASE = "_front_page";
|
||||
public static final String POST_FEED_SCROLLED_POSITION_SUBREDDIT_BASE = "_subreddit_";
|
||||
public static final String POST_FEED_SCROLLED_POSITION_USER_BASE = "_user_";
|
||||
public static final String POST_FEED_SCROLLED_POSITION_MULTI_REDDIT_BASE = "_multireddit_";
|
||||
public static final String POST_FEED_SCROLLED_POSITION_ANONYMOUS = ".anonymous";
|
||||
public static final String FRONT_PAGE_SCROLLED_POSITION_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.front_page_scrolled_position";
|
||||
public static final String FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE = "_front_page";
|
||||
public static final String FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS = ".anonymous";
|
||||
|
||||
public static final String PULL_NOTIFICATION_TIME = "pull_notification_time";
|
||||
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
|
||||
@ -119,7 +116,7 @@ public class SharedPreferencesUtils {
|
||||
public static final String DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE = "delete_all_sort_type_data_in_database";
|
||||
public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE = "delete_all_post_layout_data_in_database";
|
||||
public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database";
|
||||
public static final String DELETE_POST_FEED_SCROLLED_POSITIONS_IN_DATABASE = "delete_post_feed_scrolled_positions_in_database";
|
||||
public static final String DELETE_FRONT_PAGE_SCROLLED_POSITIONS_IN_DATABASE = "delete_front_page_scrolled_positions_in_database";
|
||||
public static final String RESET_ALL_SETTINGS = "reset_all_settings";
|
||||
public static final String MAIN_PAGE_TAB_1_TITLE = "main_page_tab_1_title";
|
||||
public static final String MAIN_PAGE_TAB_2_TITLE = "main_page_tab_2_title";
|
||||
@ -140,5 +137,5 @@ public class SharedPreferencesUtils {
|
||||
public static final String START_AUTOPLAY_VISIBLE_AREA_OFFSET_LANDSCAPE = "start_autoplay_visible_area_offset_landscape";
|
||||
public static final String MUTE_NSFW_VIDEO = "mute_nsfw_video";
|
||||
public static final String VIDEO_PLAYER_IGNORE_NAV_BAR = "video_player_ignore_nav_bar";
|
||||
public static final String SAVE_POST_FEED_SCROLLED_POSITION = "save_post_feed_scrolled_position";
|
||||
public static final String SAVE_FRONT_PAGE_SCROLLED_POSITION = "save_front_page_scrolled_position";
|
||||
}
|
||||
|
@ -348,8 +348,8 @@
|
||||
<string name="settings_amoled_dark_title">Amoled Dark</string>
|
||||
<string name="settings_interface_title">Interface</string>
|
||||
<string name="settings_gestures_and_buttons_title">Gestures & Buttons</string>
|
||||
<string name="settings_save_post_feed_scrolled_position_title">Save Scrolled Position in Post Feed</string>
|
||||
<string name="settings_save_post_feed_scrolled_position_summary">Browse new posts after refreshing</string>
|
||||
<string name="settings_save_front_page_scrolled_position_title">Save Scrolled Position in HOME</string>
|
||||
<string name="settings_save_front_page_scrolled_position_summary">Browse new posts after refreshing in HOME (Front Page)</string>
|
||||
<string name="settings_open_link_in_app_title">Open Link In App</string>
|
||||
<string name="settigns_video_title">Video</string>
|
||||
<string name="settings_video_autoplay_title">Video Autoplay</string>
|
||||
@ -458,7 +458,7 @@
|
||||
<string name="settings_delete_all_sort_type_data_in_database_title">Delete All Sort Types in Database</string>
|
||||
<string name="settings_delete_all_post_layout_data_in_database_title">Delete All Post Layouts in Database</string>
|
||||
<string name="settings_delete_all_themes_in_database_title">Delete All Themes in Database</string>
|
||||
<string name="settings_delete_post_feed_scrolled_positions_in_database_title">Delete All Post Feed Scrolled Positions in Database</string>
|
||||
<string name="settings_delete_front_page_scrolled_positions_in_database_title">Delete All Front Page Scrolled Positions in Database</string>
|
||||
<string name="settings_reset_all_settings_title">Reset All Settings</string>
|
||||
<string name="settings_advanced_settings_summary">Clean the database and shared preferences</string>
|
||||
<string name="settings_tab_info">Restart the app to see the changes</string>
|
||||
|
@ -23,8 +23,8 @@
|
||||
app:title="@string/settings_delete_all_themes_in_database_title" />
|
||||
|
||||
<Preference
|
||||
app:key="delete_post_feed_scrolled_positions_in_database"
|
||||
app:title="@string/settings_delete_post_feed_scrolled_positions_in_database_title" />
|
||||
app:key="delete_front_page_scrolled_positions_in_database"
|
||||
app:title="@string/settings_delete_front_page_scrolled_positions_in_database_title" />
|
||||
|
||||
<Preference
|
||||
app:key="reset_all_settings"
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="true"
|
||||
app:key="save_post_feed_scrolled_position"
|
||||
app:title="@string/settings_save_post_feed_scrolled_position_title"
|
||||
app:summary="@string/settings_save_post_feed_scrolled_position_summary" />
|
||||
app:key="save_front_page_scrolled_position"
|
||||
app:title="@string/settings_save_front_page_scrolled_position_title"
|
||||
app:summary="@string/settings_save_front_page_scrolled_position_summary" />
|
||||
|
||||
<SwitchPreference
|
||||
app:defaultValue="false"
|
||||
|
Loading…
Reference in New Issue
Block a user