From ea8f2404debddee1e0b2e1dbd0078647814fed9b Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 14 Aug 2024 18:51:26 -0400 Subject: Redesign recent search queries UI. --- .../activities/SearchActivity.java | 33 +++++++++++++++++----- .../SearchActivityRecyclerViewAdapter.java | 33 +++++++++++++++------- 2 files changed, 49 insertions(+), 17 deletions(-) (limited to 'app/src/main/java/ml/docilealligator') 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 714948b8..a2826d96 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -19,6 +20,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.view.inputmethod.EditorInfoCompat; import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -196,7 +199,7 @@ public class SearchActivity extends BaseActivity { @Override public void onParseSubredditListingDataSuccess(ArrayList subredditData, String after) { subredditAutocompleteRecyclerViewAdapter.setSubreddits(subredditData); - binding.recyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); + binding.subredditAutocompleteRecyclerViewSearchActivity.setAdapter(subredditAutocompleteRecyclerViewAdapter); } @Override @@ -298,9 +301,28 @@ public class SearchActivity extends BaseActivity { executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery)); } }); - binding.recyclerViewSearchActivity.setVisibility(View.VISIBLE); - binding.recyclerViewSearchActivity.setNestedScrollingEnabled(false); - binding.recyclerViewSearchActivity.setAdapter(adapter); + binding.recentSearchQueryRecyclerViewSearchActivity.setVisibility(View.VISIBLE); + 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; + + @Override + public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + int column = ((GridLayoutManager.LayoutParams) view.getLayoutParams()).getSpanIndex(); + boolean toTheLeft = column == 0; + + if (toTheLeft) { + outRect.left = spacing; + outRect.right = halfSpacing; + } else { + outRect.left = halfSpacing; + outRect.right = spacing; + } + outRect.bottom = spacing; + } + }); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true)) { mRecentSearchQueryViewModel = new ViewModelProvider(this, @@ -309,10 +331,8 @@ public class SearchActivity extends BaseActivity { mRecentSearchQueryViewModel.getAllRecentSearchQueries().observe(this, recentSearchQueries -> { if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) { - binding.dividerSearchActivity.setVisibility(View.VISIBLE); binding.deleteAllRecentSearchesButtonSearchActivity.setVisibility(View.VISIBLE); } else { - binding.dividerSearchActivity.setVisibility(View.GONE); binding.deleteAllRecentSearchesButtonSearchActivity.setVisibility(View.GONE); } adapter.setRecentSearchQueries(recentSearchQueries); @@ -385,7 +405,6 @@ public class SearchActivity extends BaseActivity { binding.searchInTextViewSearchActivity.setTextColor(colorAccent); binding.deleteAllRecentSearchesButtonSearchActivity.setIconTint(ColorStateList.valueOf(mCustomThemeWrapper.getPrimaryIconColor())); binding.subredditNameTextViewSearchActivity.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); - binding.dividerSearchActivity.setBackgroundColor(mCustomThemeWrapper.getDividerColor()); if (typeface != null) { Utils.setFontToAllTextViews(binding.getRoot(), typeface); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java index c75479ce..9ba5dc72 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java @@ -1,6 +1,6 @@ package ml.docilealligator.infinityforreddit.adapters; -import android.graphics.drawable.Drawable; +import android.content.res.ColorStateList; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -9,19 +9,17 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.databinding.ItemRecentSearchQueryBinding; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery; -import ml.docilealligator.infinityforreddit.utils.Utils; public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { private final BaseActivity activity; private List recentSearchQueries; + private final int filledCardViewBackgroundColor; private final int primaryTextColor; - private final Drawable historyIcon; - private final Drawable deleteIcon; + private final int secondaryTextColor; private final ItemOnClickListener itemOnClickListener; public interface ItemOnClickListener { @@ -32,9 +30,9 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { + ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setSelected(true); + ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery.setSelected(true); + }, 1000); } } } @@ -58,6 +60,15 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter recentSearchQueries) { this.recentSearchQueries = recentSearchQueries; notifyDataSetChanged(); @@ -70,9 +81,10 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { + itemView.setOnLongClickListener(view -> { itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition())); + return true; }); } } -- cgit v1.2.3