Fix inconsistency between user interaction and database commit order when re-adding videos to the playlist
This commit is contained in:
parent
b50e3c07d2
commit
1cf670dad9
|
@ -54,6 +54,7 @@ import androidx.appcompat.content.res.AppCompatResources;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.PlaybackException;
|
import com.google.android.exoplayer2.PlaybackException;
|
||||||
|
@ -89,6 +90,7 @@ import org.schabi.newpipe.fragments.list.videos.RelatedItemsFragment;
|
||||||
import org.schabi.newpipe.ktx.AnimationType;
|
import org.schabi.newpipe.ktx.AnimationType;
|
||||||
import org.schabi.newpipe.local.dialog.PlaylistDialog;
|
import org.schabi.newpipe.local.dialog.PlaylistDialog;
|
||||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||||
|
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
|
||||||
import org.schabi.newpipe.player.Player;
|
import org.schabi.newpipe.player.Player;
|
||||||
import org.schabi.newpipe.player.PlayerService;
|
import org.schabi.newpipe.player.PlayerService;
|
||||||
import org.schabi.newpipe.player.PlayerType;
|
import org.schabi.newpipe.player.PlayerType;
|
||||||
|
@ -472,10 +474,21 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
binding.detailControlsBackground.setOnClickListener(v -> openBackgroundPlayer(false));
|
binding.detailControlsBackground.setOnClickListener(v -> openBackgroundPlayer(false));
|
||||||
binding.detailControlsPopup.setOnClickListener(v -> openPopupPlayer(false));
|
binding.detailControlsPopup.setOnClickListener(v -> openPopupPlayer(false));
|
||||||
binding.detailControlsPlaylistAppend.setOnClickListener(makeOnClickListener(info ->
|
binding.detailControlsPlaylistAppend.setOnClickListener(makeOnClickListener(info -> {
|
||||||
|
if (getFM() != null && currentInfo != null) {
|
||||||
|
final Fragment fragment = getParentFragmentManager().
|
||||||
|
findFragmentById(R.id.fragment_holder);
|
||||||
|
|
||||||
|
// commit previous pending changes to database
|
||||||
|
if (fragment instanceof LocalPlaylistFragment) {
|
||||||
|
((LocalPlaylistFragment) fragment).commitChanges();
|
||||||
|
}
|
||||||
|
|
||||||
disposables.add(PlaylistDialog.createCorrespondingDialog(requireContext(),
|
disposables.add(PlaylistDialog.createCorrespondingDialog(requireContext(),
|
||||||
List.of(new StreamEntity(info)),
|
List.of(new StreamEntity(info)),
|
||||||
dialog -> dialog.show(getParentFragmentManager(), TAG)))));
|
dialog -> dialog.show(getParentFragmentManager(), TAG)));
|
||||||
|
}
|
||||||
|
}));
|
||||||
binding.detailControlsDownload.setOnClickListener(v -> {
|
binding.detailControlsDownload.setOnClickListener(v -> {
|
||||||
if (PermissionHelper.checkStoragePermissions(activity,
|
if (PermissionHelper.checkStoragePermissions(activity,
|
||||||
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
||||||
|
|
|
@ -158,6 +158,15 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||||
return headerBinding;
|
return headerBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit changes immediately when the user turns to the player.
|
||||||
|
// Delete operations will be committed to ensure that the database
|
||||||
|
// is up to date when the user adds the just deleted stream by the player.
|
||||||
|
public void commitChanges() {
|
||||||
|
if (isModified != null && isModified.get()) {
|
||||||
|
saveImmediate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initListeners() {
|
protected void initListeners() {
|
||||||
super.initListeners();
|
super.initListeners();
|
||||||
|
|
Loading…
Reference in New Issue