diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-09-14 15:45:56 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-09-14 15:45:56 +0000 |
commit | a9098c58e60669893d4d60903d6bfa6c7cf8920b (patch) | |
tree | 44585205a48c6cf5175002835f93d4f9d3cf1d43 /app | |
parent | 2be9ea90e240f5e73ca0cbb3294bdc591c3ddb80 (diff) | |
download | infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar.gz infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar.bz2 infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar.lz infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar.xz infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.tar.zst infinity-for-reddit-a9098c58e60669893d4d60903d6bfa6c7cf8920b.zip |
Rewrite InsertRecentSearchQuery and delete recent search query function.
Diffstat (limited to 'app')
5 files changed, 17 insertions, 83 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 2e2f1b00..8cdb0920 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -49,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.DeleteRecentSearchQuery; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQuery; import ml.docilealligator.infinityforreddit.recentsearchquery.RecentSearchQueryViewModel; import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData; @@ -329,7 +328,7 @@ public class SearchActivity extends BaseActivity { @Override public void onDelete(RecentSearchQuery recentSearchQuery) { - DeleteRecentSearchQuery.deleteRecentSearchQueryListener(mRedditDataRoomDatabase, recentSearchQuery, () -> {}); + executor.execute(() -> mRedditDataRoomDatabase.recentSearchQueryDao().deleteRecentSearchQueries(recentSearchQuery)); } }); recyclerView.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index 2a9b3fe2..ac70a198 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -38,6 +38,7 @@ 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; @@ -129,6 +130,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor executor; private Call<String> subredditAutocompleteCall; private String mAccessToken; private String mAccountName; @@ -386,8 +389,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect }); if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) { - InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName, - mQuery, () -> mInsertSearchQuerySuccess = true); + InsertRecentSearchQuery.insertRecentSearchQueryListener(executor, new Handler(getMainLooper()), + mRedditDataRoomDatabase, mAccountName, mQuery, () -> mInsertSearchQuerySuccess = true); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteRecentSearchQuery.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteRecentSearchQuery.java deleted file mode 100644 index e40703c2..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/DeleteRecentSearchQuery.java +++ /dev/null @@ -1,44 +0,0 @@ -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/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java index e03a6e70..fba3ef5f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java @@ -1,8 +1,9 @@ package ml.docilealligator.infinityforreddit.recentsearchquery; -import android.os.AsyncTask; +import android.os.Handler; import java.util.List; +import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; @@ -11,28 +12,13 @@ public class InsertRecentSearchQuery { void success(); } - public static void insertRecentSearchQueryListener(RedditDataRoomDatabase redditDataRoomDatabase, String username, - String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) { - new InsertRecentSearchQueryAsyncTask(redditDataRoomDatabase, username, recentSearchQuery, insertRecentSearchQueryListener).execute(); - } - - private static class InsertRecentSearchQueryAsyncTask extends AsyncTask<Void, Void, Void> { - - private RecentSearchQueryDao recentSearchQueryDao; - private String username; - private String recentSearchQuery; - private InsertRecentSearchQueryListener insertRecentSearchQueryListener; - - public InsertRecentSearchQueryAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String username, - String recentSearchQuery, InsertRecentSearchQueryListener insertRecentSearchQueryListener) { - this.recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao(); - this.username = username; - this.recentSearchQuery = recentSearchQuery; - this.insertRecentSearchQueryListener = insertRecentSearchQueryListener; - } - - @Override - protected Void doInBackground(Void... voids) { + public static void insertRecentSearchQueryListener(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + String username, + String recentSearchQuery, + InsertRecentSearchQueryListener insertRecentSearchQueryListener) { + executor.execute(() -> { + RecentSearchQueryDao recentSearchQueryDao = redditDataRoomDatabase.recentSearchQueryDao(); List<RecentSearchQuery> recentSearchQueries = recentSearchQueryDao.getAllRecentSearchQueries(username); if (recentSearchQueries.size() >= 5) { for (int i = 4; i < recentSearchQueries.size(); i++) { @@ -41,13 +27,8 @@ public class InsertRecentSearchQuery { } recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery)); - return null; - } - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - insertRecentSearchQueryListener.success(); - } + handler.post(insertRecentSearchQueryListener::success); + }); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java index 0293ad5b..3d463845 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java @@ -114,11 +114,6 @@ public class APIUtils { public static final String REFERER_KEY = "Referer"; public static final String REVEDDIT_REFERER = "https://www.reveddit.com/"; - /*public static final String HOST_KEY = "Host"; - public static final String REDGIFS_HOST = "api.redgifs.com"; - public static final String CONTENT_TYPE_KEY = "Content-Type"; - public static final String */ - public static Map<String, String> getHttpBasicAuthHeader() { Map<String, String> params = new HashMap<>(); String credentials = String.format("%s:%s", APIUtils.CLIENT_ID, ""); |