diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-12-02 10:47:11 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-12-02 10:47:11 +0000 |
commit | 805017233b144101e6e1f814162508a815a4410a (patch) | |
tree | 90932e949e0820a24246d222a23b01cece0bc2a9 /app/src/main/java/ml | |
parent | 58a19c9ad1e5e358cc0babf5b4812d473706ef00 (diff) | |
download | infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar.gz infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar.bz2 infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar.lz infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar.xz infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.tar.zst infinity-for-reddit-805017233b144101e6e1f814162508a815a4410a.zip |
Add an option to disable search history.
Diffstat (limited to 'app/src/main/java/ml')
3 files changed, 20 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index b0b96ccb..03eaa6f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -226,23 +226,27 @@ public class SearchActivity extends BaseActivity { DeleteRecentSearchQuery.deleteRecentSearchQueryListener(mRedditDataRoomDatabase, recentSearchQuery, () -> {}); } }); + recyclerView.setVisibility(View.VISIBLE); recyclerView.setNestedScrollingEnabled(false); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); - mRecentSearchQueryViewModel = new ViewModelProvider(this, - new RecentSearchQueryViewModel.Factory(mRedditDataRoomDatabase, mAccountName)) - .get(RecentSearchQueryViewModel.class); - - mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> { - if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) { - divider.setVisibility(View.VISIBLE); - recentSummaryTextView.setVisibility(View.VISIBLE); - } else { - divider.setVisibility(View.GONE); - recentSummaryTextView.setVisibility(View.GONE); - } - adapter.setRecentSearchQueries(recentSearchQueries); - }); + + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true)) { + mRecentSearchQueryViewModel = new ViewModelProvider(this, + new RecentSearchQueryViewModel.Factory(mRedditDataRoomDatabase, mAccountName)) + .get(RecentSearchQueryViewModel.class); + + mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> { + if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) { + divider.setVisibility(View.VISIBLE); + recentSummaryTextView.setVisibility(View.VISIBLE); + } else { + divider.setVisibility(View.GONE); + recentSummaryTextView.setVisibility(View.GONE); + } + adapter.setRecentSearchQueries(recentSearchQueries); + }); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index c3f8fad1..1330c0ee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -251,7 +251,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect }).attach(); fixViewPager2Sensitivity(viewPager2); - if (mAccountName != null && !mInsertSearchQuerySuccess && mQuery != null) { + if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) { InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName, mQuery, () -> mInsertSearchQuerySuccess = true); } 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 f6c3d5bd..a5ba50de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -146,6 +146,7 @@ public class SharedPreferencesUtils { public static final int SWIPE_ACITON_DOWNVOTE = 1; public static final String LANGUAGE = "language"; public static final String LANGUAGE_DEFAULT_VALUE = "auto"; + public static final String ENABLE_SEARCH_HISTORY = "enable_search_history"; public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs"; public static final String MAIN_PAGE_TAB_COUNT = "_main_page_tab_count"; |