mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
feat: Support skipping duplicates
This commit is contained in:
parent
1223062388
commit
e1d63a9eef
4 changed files with 32 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.cappielloantonio.tempo.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Dialog;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
|
|
@ -14,7 +15,6 @@ import com.cappielloantonio.tempo.subsonic.models.Playlist;
|
|||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaylistChooserViewModel extends AndroidViewModel {
|
||||
|
|
@ -34,8 +34,19 @@ public class PlaylistChooserViewModel extends AndroidViewModel {
|
|||
return playlists;
|
||||
}
|
||||
|
||||
public void addSongsToPlaylist(String playlistId) {
|
||||
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(Lists.transform(toAdd, Child::getId)));
|
||||
public void addSongsToPlaylist(LifecycleOwner owner, Dialog dialog, String playlistId, boolean skipDuplicates) {
|
||||
List<String> songIds = Lists.transform(toAdd, Child::getId);
|
||||
if (skipDuplicates) {
|
||||
playlistRepository.getPlaylistSongs(playlistId).observe(owner, playlistSongs -> {
|
||||
List<String> playlistSongIds = Lists.transform(playlistSongs, Child::getId);
|
||||
songIds.removeAll(playlistSongIds);
|
||||
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(songIds));
|
||||
dialog.dismiss();
|
||||
});
|
||||
} else {
|
||||
playlistRepository.addSongToPlaylist(playlistId, new ArrayList<>(songIds));
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSongsToAdd(ArrayList<Child> songs) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue