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

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

@ -13,5 +13,8 @@ import kotlinx.parcelize.Parcelize
data class RecentSearch( data class RecentSearch(
@PrimaryKey @PrimaryKey
@ColumnInfo(name = "search") @ColumnInfo(name = "search")
var search: String var search: String,
@ColumnInfo(name = "timestamp", defaultValue = "0")
var timestamp: Long
) : Parcelable ) : 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.Child;
import com.cappielloantonio.tempo.subsonic.models.SearchResult2; import com.cappielloantonio.tempo.subsonic.models.SearchResult2;
import com.cappielloantonio.tempo.subsonic.models.SearchResult3; import com.cappielloantonio.tempo.subsonic.models.SearchResult3;
import com.cappielloantonio.tempo.util.Preferences;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -186,8 +187,13 @@ public class SearchingRepository {
@Override @Override
public void run() { public void run() {
if(Preferences.isSearchSortingChronologicallyEnabled()){
recent = recentSearchDao.getRecent(); recent = recentSearchDao.getRecent();
} }
else {
recent = recentSearchDao.getAlpha();
}
}
public List<String> getRecent() { public List<String> getRecent() {
return recent; return recent;

View file

@ -81,6 +81,7 @@ object Preferences {
private const val ALBUM_SORT_ORDER = "album_sort_order" private const val ALBUM_SORT_ORDER = "album_sort_order"
private const val DEFAULT_ALBUM_SORT_ORDER = Constants.ALBUM_ORDER_BY_NAME 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 ARTIST_SORT_BY_ALBUM_COUNT= "artist_sort_by_album_count"
private const val SORT_SEARCH_CHRONOLOGICALLY= "sort_search_chronologically"
@JvmStatic @JvmStatic
fun getServer(): String? { fun getServer(): String? {
@ -674,4 +675,9 @@ object Preferences {
else else
return Constants.ARTIST_ORDER_BY_NAME 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) { public void insertNewSearch(String search) {
searchingRepository.insert(new RecentSearch(search)); searchingRepository.insert(new RecentSearch(search, System.currentTimeMillis() / 1000L));
} }
public void deleteRecentSearch(String search) { public void deleteRecentSearch(String search) {
searchingRepository.delete(new RecentSearch(search)); searchingRepository.delete(new RecentSearch(search, 0));
} }
public LiveData<List<String>> getSearchSuggestion(String query) { public LiveData<List<String>> getSearchSuggestion(String query) {

View file

@ -543,4 +543,7 @@
<string name="folder_play_collecting">Collecting songs from folder…</string> <string name="folder_play_collecting">Collecting songs from folder…</string>
<string name="folder_play_playing">Playing %d songs</string> <string name="folder_play_playing">Playing %d songs</string>
<string name="folder_play_no_songs">No songs found in folder</string> <string name="folder_play_no_songs">No songs found in folder</string>
<string name="search_sort_title">Sort recent searches chronologically</string>
<string name="search_sort_summary">If enabled, sort searches chronologically. Sort by name if disabled.</string>
</resources> </resources>

View file

@ -122,6 +122,12 @@
android:summary="@string/settings_artist_sort_by_album_count_summary" android:summary="@string/settings_artist_sort_by_album_count_summary"
android:key="artist_sort_by_album_count" /> android:key="artist_sort_by_album_count" />
<SwitchPreference
android:title="@string/search_sort_title"
android:defaultValue="false"
android:summary="@string/search_sort_summary"
android:key="sort_search_chronologically" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/settings_title_playlist"> <PreferenceCategory app:title="@string/settings_title_playlist">