aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-18 15:13:28 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-18 15:13:28 +0000
commit78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91 (patch)
treed3f4e240fca13cfc07f9c54cf254e9d0a29dc922 /app/src/main
parent03d8cf497db20388403f7ff294405d6ab7d108b7 (diff)
downloadinfinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar.gz
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar.bz2
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar.lz
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar.xz
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.tar.zst
infinity-for-reddit-78c8452ae4f5eaa8c58f26c8729f7d0c74c1cb91.zip
Save fetched trending searches during configuration changes in TrendingActivity.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
index 54864c5d..79d8b24e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java
@@ -59,6 +59,8 @@ import retrofit2.Retrofit;
public class TrendingActivity extends BaseActivity {
+ private static final String TRENDING_SEARCHES_STATE = "TSS";
+
@BindView(R.id.coordinator_layout_trending_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.collapsing_toolbar_layout_trending_activity)
@@ -170,7 +172,14 @@ public class TrendingActivity extends BaseActivity {
swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
swipeRefreshLayout.setOnRefreshListener(this::loadTrendingSearches);
- loadTrendingSearches();
+ if (savedInstanceState != null) {
+ trendingSearches = savedInstanceState.getParcelableArrayList(TRENDING_SEARCHES_STATE);
+ }
+ if (trendingSearches != null) {
+ adapter.setTrendingSearches(trendingSearches);
+ } else {
+ loadTrendingSearches();
+ }
}
private void loadTrendingSearches() {
@@ -247,6 +256,12 @@ public class TrendingActivity extends BaseActivity {
}
@Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putParcelableArrayList(TRENDING_SEARCHES_STATE, trendingSearches);
+ }
+
+ @Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}