aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-14 22:51:26 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-14 22:51:26 +0000
commitea8f2404debddee1e0b2e1dbd0078647814fed9b (patch)
treef3c8816968a0eb880ede1cf22a56c6d81b149f14 /app
parent1c821fbab41a21ec3d40f78436a78cc596692b28 (diff)
downloadinfinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar.gz
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar.bz2
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar.lz
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar.xz
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.tar.zst
infinity-for-reddit-ea8f2404debddee1e0b2e1dbd0078647814fed9b.zip
Redesign recent search queries UI.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java33
-rw-r--r--app/src/main/res/layout/activity_search.xml12
-rw-r--r--app/src/main/res/layout/item_recent_search_query.xml58
4 files changed, 90 insertions, 46 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 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> 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<RecyclerView.ViewHolder> {
private final BaseActivity activity;
private List<RecentSearchQuery> 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<Recy
public SearchActivityRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapper customThemeWrapper,
ItemOnClickListener itemOnClickListener) {
this.activity = activity;
+ this.filledCardViewBackgroundColor = customThemeWrapper.getFilledCardViewBackgroundColor();
this.primaryTextColor = customThemeWrapper.getPrimaryTextColor();
- this.historyIcon = Utils.getTintedDrawable(activity, R.drawable.ic_history_24dp, customThemeWrapper.getPrimaryIconColor());
- this.deleteIcon = Utils.getTintedDrawable(activity, R.drawable.ic_delete_24dp, customThemeWrapper.getPrimaryIconColor());
+ this.secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
this.itemOnClickListener = itemOnClickListener;
}
@@ -49,6 +47,10 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (holder instanceof RecentSearchQueryViewHolder) {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) {
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setText(recentSearchQueries.get(position).getSearchQuery());
+ holder.itemView.postDelayed(() -> {
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setSelected(true);
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery.setSelected(true);
+ }, 1000);
}
}
}
@@ -58,6 +60,15 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
return recentSearchQueries == null ? 0 : recentSearchQueries.size();
}
+ @Override
+ public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
+ super.onViewRecycled(holder);
+ if (holder instanceof RecentSearchQueryViewHolder) {
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setSelected(false);
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery.setSelected(false);
+ }
+ }
+
public void setRecentSearchQueries(List<RecentSearchQuery> recentSearchQueries) {
this.recentSearchQueries = recentSearchQueries;
notifyDataSetChanged();
@@ -70,9 +81,10 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
super(binding.getRoot());
this.binding = binding;
+ itemView.setBackgroundTintList(ColorStateList.valueOf(filledCardViewBackgroundColor));
+
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTextColor(primaryTextColor);
- binding.recentSearchQueryTextViewItemRecentSearchQuery.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
- binding.deleteButtonItemRecentSearchQuery.setIcon(deleteIcon);
+ binding.recentSearchQueryWhereTextViewItemRecentSearchQuery.setTextColor(secondaryTextColor);
if (activity.typeface != null) {
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTypeface(activity.typeface);
@@ -84,8 +96,9 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
});
- binding.deleteButtonItemRecentSearchQuery.setOnClickListener(view -> {
+ itemView.setOnLongClickListener(view -> {
itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition()));
+ return true;
});
}
}
diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml
index 3427f7d3..ef6bee96 100644
--- a/app/src/main/res/layout/activity_search.xml
+++ b/app/src/main/res/layout/activity_search.xml
@@ -122,14 +122,16 @@
</RelativeLayout>
- <View
- android:id="@+id/divider_search_activity"
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/recent_search_query_recycler_view_search_activity"
android:layout_width="match_parent"
- android:layout_height="1dp"
- android:visibility="gone" />
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ app:spanCount="2"
+ app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" />
<androidx.recyclerview.widget.RecyclerView
- android:id="@+id/recycler_view_search_activity"
+ android:id="@+id/subreddit_autocomplete_recycler_view_search_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
diff --git a/app/src/main/res/layout/item_recent_search_query.xml b/app/src/main/res/layout/item_recent_search_query.xml
index e23e7378..dc732c03 100644
--- a/app/src/main/res/layout/item_recent_search_query.xml
+++ b/app/src/main/res/layout/item_recent_search_query.xml
@@ -1,33 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- xmlns:app="http://schemas.android.com/apk/res-auto"
+ app:cardCornerRadius="12dp"
android:clickable="true"
android:focusable="true"
- android:background="?attr/selectableItemBackground">
+ style="?attr/materialCardViewFilledStyle">
- <TextView
- android:id="@+id/recent_search_query_text_view_item_recent_search_query"
- android:layout_width="0dp"
+ <LinearLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_weight="1"
- android:layout_gravity="center_vertical"
- android:gravity="center_vertical"
- android:fontFamily="?attr/font_family"
- android:textSize="?attr/font_default"
- android:padding="16dp"
- android:drawablePadding="16dp" />
+ android:orientation="vertical">
- <com.google.android.material.button.MaterialButton
- android:id="@+id/delete_button_item_recent_search_query"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:padding="16dp"
- app:strokeWidth="0dp"
- app:iconSize="24dp"
- app:iconTint="@null"
- style="?attr/materialIconButtonOutlinedStyle" />
+ <TextView
+ android:id="@+id/recent_search_query_text_view_item_recent_search_query"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:fontFamily="?attr/font_family"
+ android:textSize="?attr/font_default"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:marqueeRepeatLimit="marquee_forever" />
+
+ <TextView
+ android:id="@+id/recent_search_query_where_text_view_item_recent_search_query"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:layout_marginStart="16dp"
+ android:layout_marginEnd="16dp"
+ android:fontFamily="?attr/font_family"
+ android:textSize="?attr/font_default"
+ android:singleLine="true"
+ android:ellipsize="marquee"
+ android:marqueeRepeatLimit="marquee_forever"
+ android:visibility="gone" />
+
+ </LinearLayout>
-</LinearLayout> \ No newline at end of file
+</com.google.android.material.card.MaterialCardView>