From 5f80ada130a53d5c5b6addc16bca6b37c76734ca Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 21 Aug 2024 23:20:11 -0400 Subject: Save multireddit path and display name in RecentSearchQuery. App data should be removed before opening Infinity cuz RedditDataRoomDatabase's migration method is changed without bumping version. --- .../infinityforreddit/RedditDataRoomDatabase.java | 2 ++ .../activities/SearchActivity.java | 4 +++ .../activities/SearchResultActivity.java | 4 +-- .../activities/ViewMultiRedditDetailActivity.java | 6 +---- .../SearchActivityRecyclerViewAdapter.java | 30 ++++++++++++++-------- .../infinityforreddit/multireddit/MultiReddit.java | 12 +++++++++ .../recentsearchquery/InsertRecentSearchQuery.java | 11 +++++++- .../recentsearchquery/RecentSearchQuery.java | 30 +++++++++++++++++++++- 8 files changed, 79 insertions(+), 20 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 4e49676d..51db44df 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -423,6 +423,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN search_in_subreddit_or_user_name TEXT"); + database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN search_in_multireddit_path TEXT"); + database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN search_in_multireddit_display_name TEXT"); database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN search_in_thing_type INTEGER DEFAULT 0 NOT NULL"); } }; 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 d88c75ce..08ee6e68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -355,6 +355,10 @@ public class SearchActivity extends BaseActivity { @Override public void onClick(RecentSearchQuery recentSearchQuery) { searchInSubredditOrUserName = recentSearchQuery.getSearchInSubredditOrUserName(); + searchInMultiReddit = MultiReddit.getDummyMultiReddit(recentSearchQuery.getMultiRedditPath()); + if (searchInMultiReddit != null && recentSearchQuery.getMultiRedditDisplayName() != null) { + searchInMultiReddit.setDisplayName(recentSearchQuery.getMultiRedditDisplayName()); + } searchInThingType = recentSearchQuery.getSearchInThingType(); search(recentSearchQuery.getSearchQuery()); } 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 331d59ff..8db414e4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -392,8 +392,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect if (!accountName.equals(Account.ANONYMOUS_ACCOUNT) && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) { InsertRecentSearchQuery.insertRecentSearchQueryListener(executor, new Handler(getMainLooper()), - mRedditDataRoomDatabase, accountName, mQuery, mSearchInSubredditOrUserName, mSearchInThingType, - () -> mInsertSearchQuerySuccess = true); + mRedditDataRoomDatabase, accountName, mQuery, mSearchInSubredditOrUserName, mSearchInMultiReddit, + mSearchInThingType, () -> mInsertSearchQuerySuccess = true); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 20ec32b0..a71bf4da 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -733,11 +733,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT } else if (itemId == R.id.action_search_view_multi_reddit_detail_activity) { Intent intent = new Intent(this, SearchActivity.class); if (multiReddit == null) { - MultiReddit dummyMultiReddit = new MultiReddit(multiPath, - multiPath.substring(multiPath.lastIndexOf("/", multiPath.length() - 2) + 1), - multiPath, null, null, null, null, Account.ANONYMOUS_ACCOUNT, - 0, 0, true, false, false); - intent.putExtra(SearchActivity.EXTRA_SEARCH_IN_MULTIREDDIT, dummyMultiReddit); + intent.putExtra(SearchActivity.EXTRA_SEARCH_IN_MULTIREDDIT, MultiReddit.getDummyMultiReddit(multiPath)); } else { intent.putExtra(SearchActivity.EXTRA_SEARCH_IN_MULTIREDDIT, multiReddit); } 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 8008e497..f4b97116 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java @@ -54,23 +54,31 @@ public class SearchActivityRecyclerViewAdapter extends RecyclerView.Adapter { ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setSelected(true); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiReddit.java index c911f33f..cd6cc6d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiReddit.java @@ -4,6 +4,7 @@ import android.os.Parcel; import android.os.Parcelable; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; @@ -256,4 +257,15 @@ public class MultiReddit implements Parcelable { parcel.writeByte((byte) (isFavorite ? 1 : 0)); parcel.writeStringList(subreddits); } + + @Nullable + public static MultiReddit getDummyMultiReddit(@Nullable String multiPath) { + if (multiPath == null) { + return null; + } + return new MultiReddit(multiPath, + multiPath.substring(multiPath.lastIndexOf("/", multiPath.length() - 2) + 1), + multiPath, null, null, null, null, Account.ANONYMOUS_ACCOUNT, + 0, 0, true, false, false); + } } 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 130feb1e..9934cad5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.concurrent.Executor; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; public class InsertRecentSearchQuery { public interface InsertRecentSearchQueryListener { @@ -17,6 +18,7 @@ public class InsertRecentSearchQuery { String username, String recentSearchQuery, String searchInSubredditOrUserName, + MultiReddit searchInMultiReddit, int searchInThingType, InsertRecentSearchQueryListener insertRecentSearchQueryListener) { executor.execute(() -> { @@ -28,7 +30,14 @@ public class InsertRecentSearchQuery { } } - recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery, searchInSubredditOrUserName, searchInThingType)); + if (searchInMultiReddit == null) { + recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery, + searchInSubredditOrUserName, null, null, searchInThingType)); + } else { + recentSearchQueryDao.insert(new RecentSearchQuery(username, recentSearchQuery, + searchInSubredditOrUserName, searchInMultiReddit.getPath(), + searchInMultiReddit.getDisplayName(), searchInThingType)); + } handler.post(insertRecentSearchQueryListener::success); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java index c903d46a..6bc5f4ee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java @@ -22,6 +22,12 @@ public class RecentSearchQuery { @Nullable @ColumnInfo(name = "search_in_subreddit_or_user_name") private String searchInSubredditOrUserName; + @Nullable + @ColumnInfo(name = "search_in_multireddit_path") + private String multiRedditPath; + @Nullable + @ColumnInfo(name = "search_in_multireddit_display_name") + private String multiRedditDisplayName; @SelectThingReturnKey.THING_TYPE @ColumnInfo(name = "search_in_thing_type") private int searchInThingType; @@ -29,11 +35,15 @@ public class RecentSearchQuery { private long time; public RecentSearchQuery(@NonNull String username, @NonNull String searchQuery, - @Nullable String searchInSubredditOrUserName, @SelectThingReturnKey.THING_TYPE int searchInThingType) { + @Nullable String searchInSubredditOrUserName, @Nullable String multiRedditPath, + @Nullable String multiRedditDisplayName, + @SelectThingReturnKey.THING_TYPE int searchInThingType) { this.username = username; this.searchQuery = searchQuery; this.searchInSubredditOrUserName = searchInSubredditOrUserName; this.searchInThingType = searchInThingType; + this.multiRedditPath = multiRedditPath; + this.multiRedditDisplayName = multiRedditDisplayName; this.time = System.currentTimeMillis(); } @@ -64,6 +74,24 @@ public class RecentSearchQuery { this.searchInSubredditOrUserName = searchInSubredditOrUserName; } + @Nullable + public String getMultiRedditPath() { + return multiRedditPath; + } + + public void setMultiRedditPath(@Nullable String multiRedditPath) { + this.multiRedditPath = multiRedditPath; + } + + @Nullable + public String getMultiRedditDisplayName() { + return multiRedditDisplayName; + } + + public void setMultiRedditDisplayName(@Nullable String multiRedditDisplayName) { + this.multiRedditDisplayName = multiRedditDisplayName; + } + @SelectThingReturnKey.THING_TYPE public int getSearchInThingType() { return searchInThingType; -- cgit v1.2.3