diff options
Diffstat (limited to 'app')
6 files changed, 31 insertions, 17 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"; diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 972ba2af..9418ce8f 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -89,7 +89,8 @@ <View android:id="@+id/divider_search_activity" android:layout_width="match_parent" - android:layout_height="1dp" /> + android:layout_height="1dp" + android:visibility="gone" /> <TextView android:id="@+id/recent_summary_text_view_search_activity" @@ -103,7 +104,8 @@ <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view_search_activity" android:layout_width="match_parent" - android:layout_height="wrap_content" /> + android:layout_height="wrap_content" + android:visibility="gone" /> </LinearLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eac39901..4020537a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -508,6 +508,7 @@ <string name="settings_swipe_action_swipe_right_title">Swipe Right</string> <string name="settings_swipe_action_info_summary">Not applicable to post feed with more than 1 column or post detail.</string> <string name="settings_language_title">Language</string> + <string name="settings_enable_search_history">Enable Search History</string> <string name="no_link_available">Cannot get the link</string> diff --git a/app/src/main/res/xml/miscellaneous_preferences.xml b/app/src/main/res/xml/miscellaneous_preferences.xml index 95532c33..81a811fc 100644 --- a/app/src/main/res/xml/miscellaneous_preferences.xml +++ b/app/src/main/res/xml/miscellaneous_preferences.xml @@ -25,6 +25,12 @@ app:title="@string/settings_respect_subreddit_recommended_comment_sort_type_title" app:summary="@string/settings_respect_subreddit_recommended_comment_sort_type_summary" /> + <SwitchPreference + app:defaultValue="true" + app:key="enable_search_history" + app:title="@string/settings_enable_search_history" + app:summary="@string/only_for_logged_in_user" /> + <ListPreference app:defaultValue="auto" app:entries="@array/settings_language" |