Skip to content

Commit

Permalink
Add a button to the recent search query card view to select the query.
Browse files Browse the repository at this point in the history
  • Loading branch information
Docile-Alligator committed Nov 15, 2024
1 parent c24813b commit 0a6e49e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,19 @@ private void bindView() {
if (!accountName.equals(Account.ANONYMOUS_ACCOUNT)) {
adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, new SearchActivityRecyclerViewAdapter.ItemOnClickListener() {
@Override
public void onClick(RecentSearchQuery recentSearchQuery) {
searchInSubredditOrUserName = recentSearchQuery.getSearchInSubredditOrUserName();
searchInMultiReddit = MultiReddit.getDummyMultiReddit(recentSearchQuery.getMultiRedditPath());
if (searchInMultiReddit != null && recentSearchQuery.getMultiRedditDisplayName() != null) {
searchInMultiReddit.setDisplayName(recentSearchQuery.getMultiRedditDisplayName());
public void onClick(RecentSearchQuery recentSearchQuery, boolean searchImmediately) {
if (searchImmediately) {
searchInSubredditOrUserName = recentSearchQuery.getSearchInSubredditOrUserName();
searchInMultiReddit = MultiReddit.getDummyMultiReddit(recentSearchQuery.getMultiRedditPath());
if (searchInMultiReddit != null && recentSearchQuery.getMultiRedditDisplayName() != null) {
searchInMultiReddit.setDisplayName(recentSearchQuery.getMultiRedditDisplayName());
}
searchInThingType = recentSearchQuery.getSearchInThingType();
search(recentSearchQuery.getSearchQuery());
} else {
binding.searchEditTextSearchActivity.setText(recentSearchQuery.getSearchQuery());
binding.searchEditTextSearchActivity.setSelection(recentSearchQuery.getSearchQuery().length());
}
searchInThingType = recentSearchQuery.getSearchInThingType();
search(recentSearchQuery.getSearchQuery());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private final int filledCardViewBackgroundColor;
private final int primaryTextColor;
private final int secondaryTextColor;
private final int primaryIconColor;
private final int subredditTextColor;
private final int userTextColor;
private final ItemOnClickListener itemOnClickListener;

public interface ItemOnClickListener {
void onClick(RecentSearchQuery recentSearchQuery);
void onClick(RecentSearchQuery recentSearchQuery, boolean searchImmediately);
void onDelete(RecentSearchQuery recentSearchQuery);
}

Expand All @@ -37,6 +38,7 @@ public SearchActivityRecyclerViewAdapter(BaseActivity activity, CustomThemeWrapp
this.filledCardViewBackgroundColor = customThemeWrapper.getFilledCardViewBackgroundColor();
this.primaryTextColor = customThemeWrapper.getPrimaryTextColor();
this.secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
this.primaryIconColor = customThemeWrapper.getPrimaryIconColor();
this.subredditTextColor = customThemeWrapper.getSubreddit();
this.userTextColor = customThemeWrapper.getUsername();
this.itemOnClickListener = itemOnClickListener;
Expand Down Expand Up @@ -122,16 +124,26 @@ public RecentSearchQueryViewHolder(@NonNull ItemRecentSearchQueryBinding binding
binding.recentSearchQueryTextViewItemRecentSearchQuery.setTypeface(activity.typeface);
}

binding.selectQueryImageViewItemRecentSearchQuery.setColorFilter(primaryIconColor, android.graphics.PorterDuff.Mode.SRC_IN);

itemView.setOnClickListener(view -> {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
itemOnClickListener.onClick(recentSearchQueries.get(getBindingAdapterPosition()));
itemOnClickListener.onClick(recentSearchQueries.get(getBindingAdapterPosition()), true);
}
});

itemView.setOnLongClickListener(view -> {
itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition()));
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
itemOnClickListener.onDelete(recentSearchQueries.get(getBindingAdapterPosition()));
}
return true;
});

binding.selectQueryImageViewItemRecentSearchQuery.setOnClickListener(view -> {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
itemOnClickListener.onClick(recentSearchQueries.get(getBindingAdapterPosition()), false);
}
});
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_select_query_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">

<path android:fillColor="#000000" android:pathData="M320,336v304q0,17 -11.5,28.5T280,680q-17,0 -28.5,-11.5T240,640v-400q0,-17 11.5,-28.5T280,200h400q17,0 28.5,11.5T720,240q0,17 -11.5,28.5T680,280L376,280l356,356q11,11 11,28t-11,28q-11,11 -28,11t-28,-11L320,336Z"/>

</vector>
38 changes: 29 additions & 9 deletions app/src/main/res/layout/item_recent_search_query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,59 @@
android:focusable="true"
style="?attr/materialCardViewFilledStyle">

<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/recent_search_query_text_view_item_recent_search_query"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />
android:marqueeRepeatLimit="marquee_forever"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/select_query_image_view_item_recent_search_query" />

<TextView
android:id="@+id/recent_search_query_where_text_view_item_recent_search_query"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever" />
android:marqueeRepeatLimit="marquee_forever"
app:layout_constraintTop_toBottomOf="@id/recent_search_query_text_view_item_recent_search_query"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/select_query_image_view_item_recent_search_query" />

</LinearLayout>
<ImageView
android:id="@+id/select_query_image_view_item_recent_search_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:layout_marginEnd="4dp"
android:src="@drawable/ic_select_query_24dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/actionBarItemBackground"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>

0 comments on commit 0a6e49e

Please sign in to comment.