aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-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
2 files changed, 49 insertions, 17 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;
});
}
}