diff options
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 |