aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SearchActivityRecyclerViewAdapter.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RecentSearchQuery/DeleteRecentSearchQuery.java44
-rw-r--r--app/src/main/res/layout/item_recent_search_query.xml13
4 files changed, 80 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
index cd1989e2..69c637e9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
@@ -39,6 +39,8 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RecentSearchQuery.DeleteRecentSearchQuery;
+import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQuery;
import ml.docilealligator.infinityforreddit.RecentSearchQuery.RecentSearchQueryViewModel;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
@@ -213,7 +215,17 @@ public class SearchActivity extends BaseActivity {
private void bindView() {
if (mAccountName != null) {
- adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, this::search);
+ adapter = new SearchActivityRecyclerViewAdapter(this, mCustomThemeWrapper, new SearchActivityRecyclerViewAdapter.ItemOnClickListener() {
+ @Override
+ public void onClick(String query) {
+ search(query);
+ }
+
+ @Override
+ public void onDelete(RecentSearchQuery recentSearchQuery) {
+ DeleteRecentSearchQuery.deleteRecentSearchQueryListener(mRedditDataRoomDatabase, recentSearchQuery, () -> {});
+ }
+ });
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SearchActivityRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SearchActivityRecyclerViewAdapter.java
index 08a5fc21..75c22934 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SearchActivityRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SearchActivityRecyclerViewAdapter.java
@@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -23,16 +24,19 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private List<RecentSearchQuery> recentSearchQueries;
private int primaryTextColor;
private Drawable historyIcon;
+ private Drawable deleteIcon;
private ItemOnClickListener itemOnClickListener;
public interface ItemOnClickListener {
void onClick(String query);
+ void onDelete(RecentSearchQuery recentSearchQuery);
}
public SearchActivityRecyclerViewAdapter(Activity activity, CustomThemeWrapper customThemeWrapper,
ItemOnClickListener itemOnClickListener) {
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.itemOnClickListener = itemOnClickListener;
}
@@ -64,6 +68,8 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
class RecentSearchQueryViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.recent_search_query_text_view_item_recent_search_query)
TextView recentSearchQueryTextView;
+ @BindView(R.id.delete_image_view_item_recent_search_query)
+ ImageView deleteImageView;
public RecentSearchQueryViewHolder(@NonNull View itemView) {
super(itemView);
@@ -72,12 +78,17 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
recentSearchQueryTextView.setTextColor(primaryTextColor);
recentSearchQueryTextView.setCompoundDrawablesWithIntrinsicBounds(historyIcon, null, null, null);
+ deleteImageView.setImageDrawable(deleteIcon);
itemView.setOnClickListener(view -> {
if (recentSearchQueries != null && !recentSearchQueries.isEmpty()) {
itemOnClickListener.onClick(recentSearchQueries.get(getAdapterPosition()).getSearchQuery());
}
});
+
+ deleteImageView.setOnClickListener(view -> {
+ itemOnClickListener.onDelete(recentSearchQueries.get(getAdapterPosition()));
+ });
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RecentSearchQuery/DeleteRecentSearchQuery.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RecentSearchQuery/DeleteRecentSearchQuery.java
new file mode 100644
index 00000000..f4ada66c
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RecentSearchQuery/DeleteRecentSearchQuery.java
@@ -0,0 +1,44 @@
+package ml.docilealligator.infinityforreddit.RecentSearchQuery;
+
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class DeleteRecentSearchQuery {
+ public interface DeleteRecentSearchQueryListener {
+ void success();
+ }
+
+ public static void deleteRecentSearchQueryListener(RedditDataRoomDatabase redditDataRoomDatabase,
+ RecentSearchQuery recentSearchQuery,
+ DeleteRecentSearchQueryListener deleteRecentSearchQueryListener) {
+ new DeleteRecentSearchQueryAsyncTask(redditDataRoomDatabase, recentSearchQuery, deleteRecentSearchQueryListener).execute();
+ }
+
+ private static class DeleteRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private RecentSearchQueryDao recentSearchQueryDao;
+ private RecentSearchQuery recentSearchQuery;
+ private DeleteRecentSearchQueryListener deleteRecentSearchQueryListener;
+
+ public DeleteRecentSearchQueryAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
+ RecentSearchQuery recentSearchQuery,
+ DeleteRecentSearchQueryListener deleteRecentSearchQueryListener) {
+ this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
+ this.recentSearchQuery = recentSearchQuery;
+ this.deleteRecentSearchQueryListener = deleteRecentSearchQueryListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ recentSearchQueryDao.deleteRecentSearchQueries(recentSearchQuery);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteRecentSearchQueryListener.success();
+ }
+ }
+}
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 f014e2fe..fd851926 100644
--- a/app/src/main/res/layout/item_recent_search_query.xml
+++ b/app/src/main/res/layout/item_recent_search_query.xml
@@ -10,10 +10,21 @@
<TextView
android:id="@+id/recent_search_query_text_view_item_recent_search_query"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:drawablePadding="16dp" />
+ <ImageView
+ android:id="@+id/delete_image_view_item_recent_search_query"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground" />
+
</LinearLayout> \ No newline at end of file