diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-10-14 01:16:15 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-10-14 01:16:15 +0000 |
commit | bc9cfc8183886398f2baa1745311a5ae4970b4e5 (patch) | |
tree | e74d0d3ca25de36824ca458221d3d770e460c78b /app/src/main/java/ml | |
parent | 31d7592964e52c7220e28f0ed6dc2286c56de1c6 (diff) | |
download | infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar.gz infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar.bz2 infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar.lz infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar.xz infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.tar.zst infinity-for-reddit-bc9cfc8183886398f2baa1745311a5ae4970b4e5.zip |
Sort recent searches by search time.
Diffstat (limited to 'app/src/main/java/ml')
3 files changed, 14 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 6df86581..62ad3a81 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -351,6 +351,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { "username TEXT NOT NULL, subreddit_name TEXT NOT NULL, " + "PRIMARY KEY(path, username, subreddit_name), FOREIGN KEY(path) REFERENCES multi_reddits(path) ON DELETE CASCADE ON UPDATE CASCADE, " + "FOREIGN KEY(username) REFERENCES multi_reddits(username) ON DELETE CASCADE ON UPDATE CASCADE)"); + database.execSQL("ALTER TABLE recent_search_queries ADD COLUMN time INTEGER DEFAULT 0 NOT NULL"); } }; } 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 7cbbe77a..5075842c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQuery.java @@ -17,10 +17,13 @@ public class RecentSearchQuery { @NonNull @ColumnInfo(name = "search_query") private String searchQuery; + @ColumnInfo(name = "time") + private long time; public RecentSearchQuery(@NonNull String username, @NonNull String searchQuery) { this.username = username; this.searchQuery = searchQuery; + this.time = System.currentTimeMillis(); } @NonNull @@ -40,4 +43,12 @@ public class RecentSearchQuery { public void setSearchQuery(@NonNull String searchQuery) { this.searchQuery = searchQuery; } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } } 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 162b02f7..ae3ec0ee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/recentsearchquery/RecentSearchQueryDao.java @@ -14,10 +14,10 @@ public interface RecentSearchQueryDao { @Insert(onConflict = OnConflictStrategy.REPLACE) void insert(RecentSearchQuery recentSearchQuery); - @Query("SELECT * FROM recent_search_queries WHERE username = :username") + @Query("SELECT * FROM recent_search_queries WHERE username = :username ORDER BY time DESC") LiveData<List<RecentSearchQuery>> getAllRecentSearchQueriesLiveData(String username); - @Query("SELECT * FROM recent_search_queries WHERE username = :username") + @Query("SELECT * FROM recent_search_queries WHERE username = :username ORDER BY time DESC") List<RecentSearchQuery> getAllRecentSearchQueries(String username); @Delete |