From b41e93dac00b16d01182ac5e67b553dd714ac1b6 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 14 Aug 2024 19:02:18 -0400 Subject: Show recent search queries when there is no text in the search text view in SearchActivity. --- .../infinityforreddit/activities/SearchActivity.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') 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 a2826d96..802152c4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -193,13 +193,14 @@ public class SearchActivity extends BaseActivity { subredditAutocompleteCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { + if (response.isSuccessful() && !call.isCanceled()) { ParseSubredditData.parseSubredditListingData(executor, handler, response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() { @Override public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { + binding.recentSearchQueryRecyclerViewSearchActivity.setVisibility(View.GONE); + binding.subredditAutocompleteRecyclerViewSearchActivity.setVisibility(View.VISIBLE); subredditAutocompleteRecyclerViewAdapter.setSubreddits(subredditData); - binding.subredditAutocompleteRecyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); } @Override @@ -217,6 +218,12 @@ public class SearchActivity extends BaseActivity { }); binding.clearSearchEditViewSearchActivity.setVisibility(View.VISIBLE); } else { + if (subredditAutocompleteCall != null) { + subredditAutocompleteCall.cancel(); + } + + binding.recentSearchQueryRecyclerViewSearchActivity.setVisibility(View.VISIBLE); + binding.subredditAutocompleteRecyclerViewSearchActivity.setVisibility(View.GONE); binding.clearSearchEditViewSearchActivity.setVisibility(View.GONE); } } @@ -305,8 +312,8 @@ public class SearchActivity extends BaseActivity { binding.recentSearchQueryRecyclerViewSearchActivity.setNestedScrollingEnabled(false); binding.recentSearchQueryRecyclerViewSearchActivity.setAdapter(adapter); binding.recentSearchQueryRecyclerViewSearchActivity.addItemDecoration(new RecyclerView.ItemDecoration() { - int spacing = (int) Utils.convertDpToPixel(16, SearchActivity.this); - int halfSpacing = spacing / 2; + final int spacing = (int) Utils.convertDpToPixel(16, SearchActivity.this); + final int halfSpacing = spacing / 2; @Override public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { @@ -324,6 +331,8 @@ public class SearchActivity extends BaseActivity { } }); + binding.subredditAutocompleteRecyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true)) { mRecentSearchQueryViewModel = new ViewModelProvider(this, new RecentSearchQueryViewModel.Factory(mRedditDataRoomDatabase, accountName)) -- cgit v1.2.3