mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Order pinned playlists in playlist catalogue
This commit is contained in:
parent
e29b96d905
commit
e2f1212e58
4 changed files with 59 additions and 6 deletions
|
|
@ -20,7 +20,7 @@ import com.cappielloantonio.play.model.Server;
|
|||
|
||||
@SuppressLint("RestrictedApi")
|
||||
@Database(
|
||||
version = 24,
|
||||
version = 25,
|
||||
entities = {Queue.class, Server.class, RecentSearch.class, Download.class, Playlist.class}
|
||||
// autoMigrations = { @AutoMigration(from = 23, to = 24) }
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,16 +22,16 @@ public class Playlist implements Parcelable {
|
|||
@ColumnInfo(name = "playlist_name")
|
||||
private String name;
|
||||
|
||||
@Ignore
|
||||
@ColumnInfo(name = "primary")
|
||||
private String primary;
|
||||
|
||||
@Ignore
|
||||
private String blurHash;
|
||||
|
||||
@Ignore
|
||||
@ColumnInfo(name = "song_count")
|
||||
private int songCount;
|
||||
|
||||
@Ignore
|
||||
@ColumnInfo(name = "playlist_duration")
|
||||
private long duration;
|
||||
|
||||
public Playlist(com.cappielloantonio.play.subsonic.models.Playlist playlist) {
|
||||
|
|
@ -43,11 +43,20 @@ public class Playlist implements Parcelable {
|
|||
this.duration = playlist.getDuration();
|
||||
}
|
||||
|
||||
public Playlist(@NonNull String id, String name) {
|
||||
@Ignore
|
||||
public Playlist(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Playlist(@NonNull String id, String name, String primary, int songCount, long duration) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.primary = primary;
|
||||
this.songCount = songCount;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getId() {
|
||||
return id;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ import com.cappielloantonio.play.model.Playlist;
|
|||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.PlaylistCatalogueViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistCatalogueFragment extends Fragment {
|
||||
private static final String TAG = "GenreCatalogueFragment";
|
||||
|
||||
|
|
@ -107,7 +111,32 @@ public class PlaylistCatalogueFragment extends Fragment {
|
|||
|
||||
playlistCatalogueAdapter = new PlaylistCatalogueAdapter(activity, requireContext(), playlistCatalogueViewModel.getType().equals(Playlist.DOWNLOADED));
|
||||
bind.playlistCatalogueRecyclerView.setAdapter(playlistCatalogueAdapter);
|
||||
playlistCatalogueViewModel.getPlaylistList(requireActivity()).observe(requireActivity(), playlist -> playlistCatalogueAdapter.setItems(playlist));
|
||||
playlistCatalogueViewModel.getPlaylistList(requireActivity()).observe(requireActivity(), playlists -> {
|
||||
playlistCatalogueViewModel.getPinnedPlaylistList(requireActivity()).observe(requireActivity(), pinnedPlaylists -> {
|
||||
List<Playlist> sortedList = new ArrayList<>();
|
||||
List<Playlist> unsortedList = new ArrayList<>(playlists);
|
||||
|
||||
List<Playlist> pinnedPlaylistsVerified = new ArrayList<>();
|
||||
List<Playlist> pinnedPlaylistsNotFound = new ArrayList<>();
|
||||
|
||||
if(unsortedList.size() > 0) {
|
||||
for(Playlist pinnedPlaylist: pinnedPlaylists) {
|
||||
if(playlists.contains(pinnedPlaylist)) {
|
||||
pinnedPlaylistsVerified.add(pinnedPlaylist);
|
||||
} else {
|
||||
pinnedPlaylistsNotFound.add(pinnedPlaylist);
|
||||
}
|
||||
}
|
||||
|
||||
unsortedList.removeAll(pinnedPlaylistsVerified);
|
||||
sortedList.addAll(pinnedPlaylistsVerified);
|
||||
sortedList.addAll(unsortedList);
|
||||
}
|
||||
|
||||
playlistCatalogueAdapter.setItems(sortedList);
|
||||
playlistCatalogueViewModel.unpinPlaylist(pinnedPlaylistsNotFound);
|
||||
});
|
||||
});
|
||||
|
||||
bind.playlistCatalogueRecyclerView.setOnTouchListener((v, event) -> {
|
||||
hideKeyboard(v);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
|||
private String type;
|
||||
|
||||
private MutableLiveData<List<Playlist>> playlistList;
|
||||
private MutableLiveData<List<Playlist>> pinnedPlaylistList;
|
||||
|
||||
public PlaylistCatalogueViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -48,6 +49,20 @@ public class PlaylistCatalogueViewModel extends AndroidViewModel {
|
|||
return playlistList;
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPinnedPlaylistList(FragmentActivity activity) {
|
||||
pinnedPlaylistList = new MutableLiveData<>(new ArrayList<>());
|
||||
playlistRepository.getPinnedPlaylists().observe(activity, playlists -> pinnedPlaylistList.postValue(playlists));
|
||||
return pinnedPlaylistList;
|
||||
}
|
||||
|
||||
public void unpinPlaylist(List<Playlist> playlists) {
|
||||
if(type.equals(Playlist.ALL)) {
|
||||
for(Playlist playlist: playlists) {
|
||||
playlistRepository.delete(playlist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue