mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Playlists pinned by saving the server information
This commit is contained in:
parent
a1885e96cd
commit
08c1b03d84
8 changed files with 29 additions and 10 deletions
|
|
@ -20,7 +20,7 @@ import com.cappielloantonio.play.model.Server;
|
|||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Database(
|
||||
version = 25,
|
||||
version = 26,
|
||||
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Playlist.class}
|
||||
// autoMigrations = { @AutoMigration(from = 23, to = 24) }
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import java.util.List;
|
|||
|
||||
@Dao
|
||||
public interface PlaylistDao {
|
||||
@Query("SELECT * FROM playlist")
|
||||
LiveData<List<Playlist>> getAll();
|
||||
@Query("SELECT * FROM playlist WHERE server=:serverId")
|
||||
LiveData<List<Playlist>> getAll(String serverId);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insert(Playlist playlist);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public interface QueueDao {
|
|||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
void insertAll(List<Queue> songQueueObject);
|
||||
|
||||
@Query("DELETE FROM queue WHERE queue.track_order = :position")
|
||||
@Query("DELETE FROM queue WHERE queue.track_order=:position")
|
||||
void deleteByPosition(int position);
|
||||
|
||||
@Query("DELETE FROM queue")
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ public class Playlist implements Parcelable {
|
|||
@ColumnInfo(name = "playlist_duration")
|
||||
private long duration;
|
||||
|
||||
@ColumnInfo(name = "server")
|
||||
private String server;
|
||||
|
||||
public Playlist(com.cappielloantonio.play.subsonic.models.Playlist playlist) {
|
||||
this.id = playlist.getId();
|
||||
this.name = playlist.getName();
|
||||
|
|
@ -49,12 +52,13 @@ public class Playlist implements Parcelable {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public Playlist(@NonNull String id, String name, String primary, int songCount, long duration) {
|
||||
public Playlist(@NonNull String id, String name, String primary, int songCount, long duration, String server) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.primary = primary;
|
||||
this.songCount = songCount;
|
||||
this.duration = duration;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -82,6 +86,14 @@ public class Playlist implements Parcelable {
|
|||
return duration;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
|||
|
|
@ -154,8 +154,8 @@ public class PlaylistRepository {
|
|||
});
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPinnedPlaylists() {
|
||||
return playlistDao.getAll();
|
||||
public LiveData<List<Playlist>> getPinnedPlaylists(String serverId) {
|
||||
return playlistDao.getAll(serverId);
|
||||
}
|
||||
|
||||
public void insert(Playlist playlist) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import androidx.lifecycle.LifecycleOwner;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
|
|
@ -16,6 +17,7 @@ import com.cappielloantonio.play.repository.AlbumRepository;
|
|||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -96,7 +98,7 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPinnedPlaylistList(LifecycleOwner owner, int maxNumber, boolean random) {
|
||||
playlistRepository.getPinnedPlaylists().observe(owner, playlists -> {
|
||||
playlistRepository.getPinnedPlaylists(PreferenceUtil.getInstance(App.getInstance()).getServerId()).observe(owner, playlists -> {
|
||||
if (random) Collections.shuffle(playlists);
|
||||
List<Playlist> subPlaylist = playlists.subList(0, Math.min(maxNumber, playlists.size()));
|
||||
pinnedPlaylists.postValue(subPlaylist);
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -51,7 +53,7 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
|||
|
||||
public LiveData<List<Playlist>> getPinnedPlaylistList(FragmentActivity activity) {
|
||||
pinnedPlaylistList = new MutableLiveData<>(new ArrayList<>());
|
||||
playlistRepository.getPinnedPlaylists().observe(activity, playlists -> pinnedPlaylistList.postValue(playlists));
|
||||
playlistRepository.getPinnedPlaylists(PreferenceUtil.getInstance(App.getInstance()).getServerId()).observe(activity, playlists -> pinnedPlaylistList.postValue(playlists));
|
||||
return pinnedPlaylistList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import androidx.lifecycle.AndroidViewModel;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Playlist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.PlaylistRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -48,6 +50,7 @@ public class PlaylistPageViewModel extends AndroidViewModel {
|
|||
|
||||
public void setPlaylist(Playlist playlist) {
|
||||
this.playlist = playlist;
|
||||
this.playlist.setServer(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
}
|
||||
|
||||
public void setOffline(boolean offline) {
|
||||
|
|
@ -60,7 +63,7 @@ public class PlaylistPageViewModel extends AndroidViewModel {
|
|||
|
||||
public LiveData<Boolean> isPinned(FragmentActivity activity) {
|
||||
MutableLiveData<Boolean> isPinnedLive = new MutableLiveData<>();
|
||||
playlistRepository.getPinnedPlaylists().observe(activity, playlists -> isPinnedLive.postValue(playlists.contains(playlist)));
|
||||
playlistRepository.getPinnedPlaylists(PreferenceUtil.getInstance(App.getInstance()).getServerId()).observe(activity, playlists -> isPinnedLive.postValue(playlists.contains(playlist)));
|
||||
return isPinnedLive;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue