diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-08-14 23:02:18 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-08-14 23:02:18 +0000 |
commit | b41e93dac00b16d01182ac5e67b553dd714ac1b6 (patch) | |
tree | e6fcdc60be197f4b443d6784ca127f412cc8d72b /app | |
parent | ea8f2404debddee1e0b2e1dbd0078647814fed9b (diff) | |
download | infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar.gz infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar.bz2 infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar.lz infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar.xz infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.tar.zst infinity-for-reddit-b41e93dac00b16d01182ac5e67b553dd714ac1b6.zip |
Show recent search queries when there is no text in the search text view in SearchActivity.
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java | 17 |
1 files changed, 13 insertions, 4 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 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<String> call, @NonNull Response<String> 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> 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)) |