From 1cf670dad95fd6f7c03b613a571885e11c1faa8b Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Mon, 18 Apr 2022 00:35:59 +0800 Subject: [PATCH] Fix inconsistency between user interaction and database commit order when re-adding videos to the playlist --- .../fragments/detail/VideoDetailFragment.java | 17 +++++++++++++++-- .../local/playlist/LocalPlaylistFragment.java | 9 +++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 0314c2540..fe8845742 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -54,6 +54,7 @@ import androidx.appcompat.content.res.AppCompatResources; 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; @@ -89,6 +90,7 @@ import org.schabi.newpipe.fragments.list.videos.RelatedItemsFragment; 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; @@ -472,10 +474,21 @@ public final class VideoDetailFragment 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)) { diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index 28711c6fe..9a75c7dbe 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -158,6 +158,15 @@ public class LocalPlaylistFragment extends BaseLocalListFragment