aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-07-31 09:20:54 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-07-31 09:20:54 +0000
commit80b4869c6a17bb305b5a5c843e53a8f71e14b7d4 (patch)
treee5665c12b5de750ff620797a0577245f2f6a6ee0 /app/src/main
parent109b4be8c3002df503f86ac94d57f1a1be005cec (diff)
downloadinfinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar.gz
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar.bz2
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar.lz
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar.xz
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.tar.zst
infinity-for-reddit-80b4869c6a17bb305b5a5c843e53a8f71e14b7d4.zip
Only save post feed scrolled position for front page.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java13
-rw-r--r--app/src/main/res/values/strings.xml6
-rw-r--r--app/src/main/res/xml/advanced_preferences.xml4
-rw-r--r--app/src/main/res/xml/main_preferences.xml6
9 files changed, 26 insertions, 57 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 9b930855..d5e7dfad 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -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
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index 6a574860..9e795f5c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -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();
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java
index 5ef80d0c..2b18ef2a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/PostDataSource.java
@@ -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;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
index 43779da2..4548a344 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
@@ -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) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
index 65384fbd..3a11855a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
@@ -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);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index 50294522..b3ce6be5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -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";
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0dbcce20..244e6739 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -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 &amp; 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>
diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml
index 224433ba..d890159f 100644
--- a/app/src/main/res/xml/advanced_preferences.xml
+++ b/app/src/main/res/xml/advanced_preferences.xml
@@ -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"
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 3b1b129f..dc8900d3 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -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"