aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java5
-rw-r--r--app/src/main/res/values/strings.xml4
4 files changed, 56 insertions, 6 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 37ef5cf3..a09d3b1a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.activities;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
@@ -15,6 +16,11 @@ import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -24,11 +30,13 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+import com.google.android.material.snackbar.Snackbar;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -264,7 +272,21 @@ public class SearchActivity extends BaseActivity {
.setTitle(R.string.confirm)
.setMessage(R.string.confirm_delete_all_recent_searches)
.setPositiveButton(R.string.yes, (dialogInterface, i) -> {
- executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteAllRecentSearchQueries(accountName));
+ hideKeyboard(true);
+ executor.execute(() -> {
+ List<RecentSearchQuery> deletedQueries = mRedditDataRoomDatabase.recentSearchQueryDao().getAllRecentSearchQueries(accountName);
+ mRedditDataRoomDatabase.recentSearchQueryDao().deleteAllRecentSearchQueries(accountName);
+ view.post(() -> Snackbar.make(view, R.string.deleted_all_recent_search, Snackbar.LENGTH_LONG)
+ .setAction(R.string.undo, v -> executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().insertAll(deletedQueries)))
+ .addCallback(new Snackbar.Callback() {
+ @Override
+ public void onDismissed(Snackbar transientBottomBar, int event) {
+ super.onDismissed(transientBottomBar, event);
+ hideKeyboard(false);
+ }
+ })
+ .show());
+ });
})
.setNegativeButton(R.string.no, null)
.show();
@@ -314,7 +336,20 @@ public class SearchActivity extends BaseActivity {
@Override
public void onDelete(RecentSearchQuery recentSearchQuery) {
- executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery));
+ hideKeyboard(true);
+ executor.execute(() -> {
+ mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery);
+ Snackbar.make(appBarLayout, R.string.deleted_recent_search, Snackbar.LENGTH_SHORT)
+ .setAction(R.string.undo, v -> executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().insert(recentSearchQuery)))
+ .addCallback(new Snackbar.Callback() {
+ @Override
+ public void onDismissed(Snackbar transientBottomBar, int event) {
+ super.onDismissed(transientBottomBar, event);
+ hideKeyboard(false);
+ }
+ })
+ .show();
+ });
}
});
binding.recentSearchQueryRecyclerViewSearchActivity.setVisibility(View.VISIBLE);
@@ -359,6 +394,15 @@ public class SearchActivity extends BaseActivity {
}
}
+ private void hideKeyboard(Boolean hide) {
+ View view = this.getCurrentFocus();
+ if (view != null) {
+ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (hide) imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ else imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
+ }
+ }
+
private void search(String query) {
if (query.equalsIgnoreCase("suicide") && mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, true)) {
Intent intent = new Intent(this, SuicidePreventionActivity.class);
@@ -516,4 +560,4 @@ public class SearchActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
-}
+} \ No newline at end of file
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 0761ed08..3cfdf2fb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.adapters;
import android.content.res.ColorStateList;
import android.view.LayoutInflater;
+import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
@@ -125,4 +126,4 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter<Recy
});
}
}
-}
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java
index 407b5614..c4f46621 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java
@@ -14,6 +14,9 @@ public interface RecentSearchQueryDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(RecentSearchQuery recentSearchQuery);
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insertAll(List<RecentSearchQuery> recentSearchQueries);
+
@Query("SELECT * FROM recent_search_queries WHERE username = :username ORDER BY time DESC")
LiveData<List<RecentSearchQuery>> getAllRecentSearchQueriesLiveData(String username);
@@ -25,4 +28,4 @@ public interface RecentSearchQueryDao {
@Delete
void deleteRecentSearchQueries(RecentSearchQuery recentSearchQuery);
-}
+} \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1b301887..e1f8faea 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -265,6 +265,9 @@
<string name="confirm">Confirm</string>
<string name="confirm_delete_all_recent_searches">Are you sure you want to delete all recent search queries?</string>
+ <string name="deleted_all_recent_search">Deleted all recent searches</string>
+ <string name="deleted_recent_search">Deleted recent search</string>
+ <string name="undo">Undo</string>
<string name="sort_best">Best</string>
<string name="sort_hot">Hot</string>
@@ -1406,5 +1409,4 @@
<string name="comment_filter_display_mode_remove_comments">Remove comments</string>
<string name="comment_filter_display_mode_fully_collapse_comments">Fully collapse comments</string>
-
</resources>