aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteAllRecentSearchQueries.java64
2 files changed, 12 insertions, 66 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 3e786f2c..2e2f1b00 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -27,11 +27,13 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
+import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
@@ -47,7 +49,6 @@ import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
-import ml.docilealligator.infinityforreddit.recentsearchquery.DeleteAllRecentSearchQueries;
import ml.docilealligator.infinityforreddit.recentsearchquery.DeleteRecentSearchQuery;
import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery;
import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQueryViewModel;
@@ -124,6 +125,8 @@ public class SearchActivity extends BaseActivity {
SharedPreferences mNsfwAndSpoilerSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor executor;
private String mAccountName;
private String mAccessToken;
private String query;
@@ -274,7 +277,14 @@ public class SearchActivity extends BaseActivity {
});
deleteAllSearchesImageView.setOnClickListener(view -> {
- DeleteAllRecentSearchQueries.deleteAllRecentSearchQueriesListener(this,mRedditDataRoomDatabase,mAccountName, () -> {});
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.confirm)
+ .setMessage(R.string.confirm_delete_all_recent_searches)
+ .setPositiveButton(R.string.yes, (dialogInterface, i) -> {
+ executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteAllRecentSearchQueries(mAccountName));
+ })
+ .setNegativeButton(R.string.no, null)
+ .show();
});
if (savedInstanceState != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteAllRecentSearchQueries.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteAllRecentSearchQueries.java
deleted file mode 100644
index 1aeac1d3..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteAllRecentSearchQueries.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package ml.docilealligator.infinityforreddit.recentsearchquery;
-
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.os.AsyncTask;
-
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-
-public class DeleteAllRecentSearchQueries {
- public static void deleteAllRecentSearchQueriesListener(Context context, RedditDataRoomDatabase redditDataRoomDatabase, String username,
- DeleteAllRecentSearchQueriesListener deleteAllRecentSearchQueriesListener) {
- AlertDialog.Builder builder = new AlertDialog.Builder(context);
- builder.setTitle(R.string.confirm);
- builder.setMessage(R.string.confirm_delete_all_recent_searches);
- builder.setPositiveButton(context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new DeleteRecentSearchQueryAsyncTask(context, redditDataRoomDatabase, username, deleteAllRecentSearchQueriesListener).execute();
- }
- });
- builder.setNegativeButton(context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
-
- public interface DeleteAllRecentSearchQueriesListener {
- void success();
- }
-
- private static class DeleteRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> {
-
- private RecentSearchQueryDao recentSearchQueryDao;
- private String username;
- private DeleteAllRecentSearchQueriesListener deleteAllRecentSearchQueriesListener;
- private Context context;
-
- public DeleteRecentSearchQueryAsyncTask(Context context, RedditDataRoomDatabase redditDataRoomDatabase,
- String username,
- DeleteAllRecentSearchQueriesListener deleteRecentSearchQueryListener) {
- this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao();
- this.username = username;
- this.deleteAllRecentSearchQueriesListener = deleteRecentSearchQueryListener;
- this.context = context;
- }
-
- @Override
- protected Void doInBackground(Void... voids) {
- recentSearchQueryDao.deleteAllRecentSearchQueries(username);
- return null;
- }
-
- @Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- deleteAllRecentSearchQueriesListener.success();
- }
- }
-}