fix: catches null value and prepares bundle appropriately adding sing… (#64)

This commit is contained in:
eddyizm 2025-08-26 21:59:33 -07:00 committed by GitHub
commit cc6cb077b4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package com.cappielloantonio.tempo.ui.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
@ -97,8 +98,12 @@ public class PlaylistChooserDialog extends DialogFragment implements ClickCallba
@Override @Override
public void onPlaylistClick(Bundle bundle) { public void onPlaylistClick(Bundle bundle) {
Playlist playlist = bundle.getParcelable(Constants.PLAYLIST_OBJECT); if (playlistChooserViewModel.getSongsToAdd() != null && !playlistChooserViewModel.getSongsToAdd().isEmpty()) {
playlistChooserViewModel.addSongsToPlaylist(playlist.getId()); Playlist playlist = bundle.getParcelable(Constants.PLAYLIST_OBJECT);
dismiss(); playlistChooserViewModel.addSongsToPlaylist(playlist.getId());
dismiss();
} else {
Toast.makeText(requireContext(), R.string.playlist_chooser_dialog_toast_add_failure, Toast.LENGTH_SHORT).show();
}
} }
} }

View file

@ -9,6 +9,7 @@ import android.transition.TransitionManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import java.util.ArrayList;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -31,6 +32,7 @@ import com.cappielloantonio.tempo.util.DownloadUtil;
import com.cappielloantonio.tempo.util.MappingUtil; import com.cappielloantonio.tempo.util.MappingUtil;
import com.cappielloantonio.tempo.util.Preferences; import com.cappielloantonio.tempo.util.Preferences;
import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel; import com.cappielloantonio.tempo.viewmodel.PlayerBottomSheetViewModel;
import com.cappielloantonio.tempo.subsonic.models.Child;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
@ -120,8 +122,10 @@ public class PlayerCoverFragment extends Fragment {
}); });
bind.innerButtonTopRight.setOnClickListener(view -> { bind.innerButtonTopRight.setOnClickListener(view -> {
ArrayList<Child> tracks = new ArrayList<>();
tracks.add(song);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putParcelable(Constants.TRACK_OBJECT, song); bundle.putParcelableArrayList(Constants.TRACKS_OBJECT, tracks);
PlaylistChooserDialog dialog = new PlaylistChooserDialog(); PlaylistChooserDialog dialog = new PlaylistChooserDialog();
dialog.setArguments(bundle); dialog.setArguments(bundle);

View file

@ -21,7 +21,7 @@ public class PlaylistChooserViewModel extends AndroidViewModel {
private final PlaylistRepository playlistRepository; private final PlaylistRepository playlistRepository;
private final MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(null); private final MutableLiveData<List<Playlist>> playlists = new MutableLiveData<>(null);
private ArrayList<Child> toAdd; private ArrayList<Child> toAdd = new ArrayList<>();
public PlaylistChooserViewModel(@NonNull Application application) { public PlaylistChooserViewModel(@NonNull Application application) {
super(application); super(application);