diff options
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"; |