Skip to content

Commit 1cf670d

Browse files
dtcxzywTobiGr
authored andcommitted
Fix inconsistency between user interaction and database commit order when re-adding videos to the playlist
1 parent b50e3c0 commit 1cf670d

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import androidx.appcompat.widget.Toolbar;
5555
import androidx.coordinatorlayout.widget.CoordinatorLayout;
5656
import androidx.core.content.ContextCompat;
57+
import androidx.fragment.app.Fragment;
5758
import androidx.preference.PreferenceManager;
5859

5960
import com.google.android.exoplayer2.PlaybackException;
@@ -89,6 +90,7 @@
8990
import org.schabi.newpipe.ktx.AnimationType;
9091
import org.schabi.newpipe.local.dialog.PlaylistDialog;
9192
import org.schabi.newpipe.local.history.HistoryRecordManager;
93+
import org.schabi.newpipe.local.playlist.LocalPlaylistFragment;
9294
import org.schabi.newpipe.player.Player;
9395
import org.schabi.newpipe.player.PlayerService;
9496
import org.schabi.newpipe.player.PlayerType;
@@ -472,10 +474,21 @@ private void setOnClickListeners() {
472474

473475
binding.detailControlsBackground.setOnClickListener(v -> openBackgroundPlayer(false));
474476
binding.detailControlsPopup.setOnClickListener(v -> openPopupPlayer(false));
475-
binding.detailControlsPlaylistAppend.setOnClickListener(makeOnClickListener(info ->
477+
binding.detailControlsPlaylistAppend.setOnClickListener(makeOnClickListener(info -> {
478+
if (getFM() != null && currentInfo != null) {
479+
final Fragment fragment = getParentFragmentManager().
480+
findFragmentById(R.id.fragment_holder);
481+
482+
// commit previous pending changes to database
483+
if (fragment instanceof LocalPlaylistFragment) {
484+
((LocalPlaylistFragment) fragment).commitChanges();
485+
}
486+
476487
disposables.add(PlaylistDialog.createCorrespondingDialog(requireContext(),
477488
List.of(new StreamEntity(info)),
478-
dialog -> dialog.show(getParentFragmentManager(), TAG)))));
489+
dialog -> dialog.show(getParentFragmentManager(), TAG)));
490+
}
491+
}));
479492
binding.detailControlsDownload.setOnClickListener(v -> {
480493
if (PermissionHelper.checkStoragePermissions(activity,
481494
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {

app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ protected ViewBinding getListHeader() {
158158
return headerBinding;
159159
}
160160

161+
// Commit changes immediately when the user turns to the player.
162+
// Delete operations will be committed to ensure that the database
163+
// is up to date when the user adds the just deleted stream by the player.
164+
public void commitChanges() {
165+
if (isModified != null && isModified.get()) {
166+
saveImmediate();
167+
}
168+
}
169+
161170
@Override
162171
protected void initListeners() {
163172
super.initListeners();

0 commit comments

Comments
 (0)