mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
feat: sort preference for playlists (#370)
This commit is contained in:
parent
75513d3bd4
commit
3cd5843c4b
5 changed files with 42 additions and 3 deletions
|
|
@ -74,6 +74,8 @@ object Preferences {
|
|||
private const val CONTINUOUS_PLAY = "continuous_play"
|
||||
private const val LAST_INSTANT_MIX = "last_instant_mix"
|
||||
private const val ALLOW_PLAYLIST_DUPLICATES = "allow_playlist_duplicates"
|
||||
private const val HOME_SORT_PLAYLISTS = "home_sort_playlists"
|
||||
private const val DEFAULT_HOME_SORT_PLAYLISTS_SORT_ORDER = Constants.PLAYLIST_ORDER_BY_RANDOM
|
||||
private const val EQUALIZER_ENABLED = "equalizer_enabled"
|
||||
private const val EQUALIZER_BAND_LEVELS = "equalizer_band_levels"
|
||||
private const val MINI_SHUFFLE_BUTTON_VISIBILITY = "mini_shuffle_button_visibility"
|
||||
|
|
@ -625,6 +627,16 @@ object Preferences {
|
|||
return App.getInstance().preferences.getBoolean(ALLOW_PLAYLIST_DUPLICATES, false)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getHomeSortPlaylists(): String {
|
||||
return App.getInstance().preferences.getString(HOME_SORT_PLAYLISTS, DEFAULT_HOME_SORT_PLAYLISTS_SORT_ORDER) ?: DEFAULT_HOME_SORT_PLAYLISTS_SORT_ORDER
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getHomeSortPlaylists(sortOrder: String) {
|
||||
App.getInstance().preferences.edit().putString(HOME_SORT_PLAYLISTS, sortOrder).apply()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun setEqualizerEnabled(enabled: Boolean) {
|
||||
App.getInstance().preferences.edit().putBoolean(EQUALIZER_ENABLED, enabled).apply()
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
|
|||
import com.cappielloantonio.tempo.subsonic.models.Child;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Playlist;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Share;
|
||||
import com.cappielloantonio.tempo.util.Constants;
|
||||
import com.cappielloantonio.tempo.util.Constants.SeedType;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
|
@ -250,12 +251,19 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
playlistRepository.getPlaylists(false, -1).observe(owner, remotes -> {
|
||||
if (remotes != null && !remotes.isEmpty()) {
|
||||
List<Playlist> playlists = new ArrayList<>(remotes);
|
||||
Collections.shuffle(playlists);
|
||||
List<Playlist> randomPlaylists = playlists.size() > 5
|
||||
String result = Preferences.getHomeSortPlaylists();
|
||||
if (Preferences.getHomeSortPlaylists().equals(Constants.PLAYLIST_ORDER_BY_RANDOM))
|
||||
{
|
||||
Collections.shuffle(playlists);
|
||||
}
|
||||
else {
|
||||
playlists.sort(Comparator.comparing(Playlist::getName));
|
||||
}
|
||||
List<Playlist> subsetPlaylists = playlists.size() > 5
|
||||
? playlists.subList(0, 5)
|
||||
: playlists;
|
||||
|
||||
pinnedPlaylists.setValue(randomPlaylists);
|
||||
pinnedPlaylists.setValue(subsetPlaylists);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue