aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-22 03:20:11 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-22 03:20:11 +0000
commit5f80ada130a53d5c5b6addc16bca6b37c76734ca (patch)
tree5493fabe975cfe5cc23f25c61a074d7a909ccf9a /app/src/main/java
parent2314a9458c6914d6e4ef8abc1aa9ee2f093aaabb (diff)
downloadinfinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar.gz
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar.bz2
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar.lz
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar.xz
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.tar.zst
infinity-for-reddit-5f80ada130a53d5c5b6addc16bca6b37c76734ca.zip
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.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SearchActivityRecyclerViewAdapter.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiReddit.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/InsertRecentSearchQuery.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java30
8 files changed, 79 insertions, 20 deletions
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<Recy
if (recentSearchQueries != null && !recentSearchQueries.isEmpty() && position < recentSearchQueries.size()) {
RecentSearchQuery recentSearchQuery = recentSearchQueries.get(position);
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryTextViewItemRecentSearchQuery.setText(recentSearchQuery.getSearchQuery());
- if (recentSearchQuery.getSearchInSubredditOrUserName() != null && !recentSearchQuery.getSearchInSubredditOrUserName().isEmpty()) {
- if (recentSearchQuery.getSearchInThingType() == SelectThingReturnKey.THING_TYPE.USER) {
+ switch (recentSearchQuery.getSearchInThingType()) {
+ case SelectThingReturnKey.THING_TYPE.SUBREDDIT:
+ if (recentSearchQuery.getSearchInSubredditOrUserName() != null && !recentSearchQuery.getSearchInSubredditOrUserName().isEmpty()) {
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
+ .setTextColor(subredditTextColor);
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
+ .setText("r/" + recentSearchQuery.getSearchInSubredditOrUserName());
+ } else {
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
+ .setTextColor(secondaryTextColor);
+ ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
+ .setText(R.string.all_subreddits);
+ }
+ break;
+ case SelectThingReturnKey.THING_TYPE.USER:
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
.setTextColor(userTextColor);
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
.setText("u/" + recentSearchQuery.getSearchInSubredditOrUserName());
- } else {
+ break;
+ case SelectThingReturnKey.THING_TYPE.MULTIREDDIT:
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
- .setTextColor(subredditTextColor);
+ .setTextColor(secondaryTextColor);
((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
- .setText("r/" + recentSearchQuery.getSearchInSubredditOrUserName());
- }
- } else {
- ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
- .setTextColor(secondaryTextColor);
- ((RecentSearchQueryViewHolder) holder).binding.recentSearchQueryWhereTextViewItemRecentSearchQuery
- .setText(R.string.all_subreddits);
+ .setText(recentSearchQuery.getMultiRedditDisplayName());
}
holder.itemView.postDelayed(() -> {
((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;