feat: integrate sort recent searches chronologically (#300)

This commit is contained in:
eddyizm 2025-12-08 20:43:15 -08:00 committed by GitHub
commit a110faabe3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1191 additions and 6 deletions

View file

@ -30,7 +30,7 @@ import com.cappielloantonio.tempo.subsonic.models.Playlist;
@UnstableApi
@Database(
version = 12,
version = 13,
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Chronology.class, Favorite.class, SessionMediaItem.class, Playlist.class, LyricsCache.class},
autoMigrations = {@AutoMigration(from = 10, to = 11), @AutoMigration(from = 11, to = 12)}
)

View file

@ -12,9 +12,12 @@ import java.util.List;
@Dao
public interface RecentSearchDao {
@Query("SELECT * FROM recent_search ORDER BY search DESC")
@Query("SELECT search FROM recent_search ORDER BY timestamp DESC")
List<String> getRecent();
@Query("SELECT search FROM recent_search ORDER BY search DESC")
List<String> getAlpha();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insert(RecentSearch search);

View file

@ -13,5 +13,8 @@ import kotlinx.parcelize.Parcelize
data class RecentSearch(
@PrimaryKey
@ColumnInfo(name = "search")
var search: String
var search: String,
@ColumnInfo(name = "timestamp", defaultValue = "0")
var timestamp: Long
) : Parcelable

View file

@ -13,6 +13,7 @@ import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.cappielloantonio.tempo.subsonic.models.SearchResult2;
import com.cappielloantonio.tempo.subsonic.models.SearchResult3;
import com.cappielloantonio.tempo.util.Preferences;
import java.util.ArrayList;
import java.util.LinkedHashSet;
@ -186,7 +187,12 @@ public class SearchingRepository {
@Override
public void run() {
recent = recentSearchDao.getRecent();
if(Preferences.isSearchSortingChronologicallyEnabled()){
recent = recentSearchDao.getRecent();
}
else {
recent = recentSearchDao.getAlpha();
}
}
public List<String> getRecent() {

View file

@ -81,6 +81,7 @@ object Preferences {
private const val ALBUM_SORT_ORDER = "album_sort_order"
private const val DEFAULT_ALBUM_SORT_ORDER = Constants.ALBUM_ORDER_BY_NAME
private const val ARTIST_SORT_BY_ALBUM_COUNT= "artist_sort_by_album_count"
private const val SORT_SEARCH_CHRONOLOGICALLY= "sort_search_chronologically"
@JvmStatic
fun getServer(): String? {
@ -674,4 +675,9 @@ object Preferences {
else
return Constants.ARTIST_ORDER_BY_NAME
}
@JvmStatic
fun isSearchSortingChronologicallyEnabled(): Boolean {
return App.getInstance().preferences.getBoolean(SORT_SEARCH_CHRONOLOGICALLY, false)
}
}

View file

@ -48,11 +48,11 @@ public class SearchViewModel extends AndroidViewModel {
}
public void insertNewSearch(String search) {
searchingRepository.insert(new RecentSearch(search));
searchingRepository.insert(new RecentSearch(search, System.currentTimeMillis() / 1000L));
}
public void deleteRecentSearch(String search) {
searchingRepository.delete(new RecentSearch(search));
searchingRepository.delete(new RecentSearch(search, 0));
}
public LiveData<List<String>> getSearchSuggestion(String query) {