Skip to content

Commit

Permalink
Fix inconsistency between user interaction and database commit order …
Browse files Browse the repository at this point in the history
…when re-adding videos to the playlist
  • Loading branch information
dtcxzyw authored and TobiGr committed Aug 16, 2023
1 parent db5ed48 commit 3b5a56e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;

import com.google.android.exoplayer2.PlaybackException;
Expand Down Expand Up @@ -88,6 +89,7 @@
import org.schabi.newpipe.ktx.AnimationType;
import org.schabi.newpipe.local.dialog.PlaylistDialog;
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.PlayerService;
import org.schabi.newpipe.player.PlayerType;
Expand Down Expand Up @@ -470,10 +472,21 @@ private void setOnClickListeners() {

binding.detailControlsBackground.setOnClickListener(v -> openBackgroundPlayer(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(),
List.of(new StreamEntity(info)),
dialog -> dialog.show(getParentFragmentManager(), TAG)))));
dialog -> dialog.show(getParentFragmentManager(), TAG)));
}
}));
binding.detailControlsDownload.setOnClickListener(v -> {
if (PermissionHelper.checkStoragePermissions(activity,
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ protected ViewBinding getListHeader() {
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
protected void initListeners() {
super.initListeners();
Expand Down

0 comments on commit 3b5a56e

Please sign in to comment.