aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAbhishek <52370265+abhishekabhi789@users.noreply.github.com>2024-08-17 03:20:16 +0000
committerGitHub <noreply@github.com>2024-08-17 03:20:16 +0000
commit482e8b3c732b543fd1dc932ddea36a1002bed08f (patch)
tree184880a4026076f5e6b1cdc1d9fe082745908696 /app/src
parent0a0d7e95b44a9c5c4926f3d566035caee3862838 (diff)
downloadinfinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar.gz
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar.bz2
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar.lz
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar.xz
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.tar.zst
infinity-for-reddit-482e8b3c732b543fd1dc932ddea36a1002bed08f.zip
Snackbar for recent search deletions (#1627)
* snackbar will be shown for recent search deletions * the view from SearchActivityRecyclerViewAdapter causes crash in android 6 sometimes, so using appBarLayout instead. --------- Co-authored-by: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>
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>