diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 4d1accf26..111a98551 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -492,15 +492,15 @@ public final class Player implements PlaybackListener, Listener { switch (playerType) { case MAIN: - UIs.destroyAll(PopupPlayerUi.class); + UIs.destroyAllOfType(PopupPlayerUi.class); UIs.addAndPrepare(new MainPlayerUi(this, binding)); break; case POPUP: - UIs.destroyAll(MainPlayerUi.class); + UIs.destroyAllOfType(MainPlayerUi.class); UIs.addAndPrepare(new PopupPlayerUi(this, binding)); break; case AUDIO: - UIs.destroyAll(VideoPlayerUi.class); + UIs.destroyAllOfType(VideoPlayerUi.class); break; } } @@ -606,7 +606,7 @@ public final class Player implements PlaybackListener, Listener { databaseUpdateDisposable.clear(); progressUpdateDisposable.set(null); - UIs.destroyAll(Object.class); // destroy every UI: obviously every UI extends Object + UIs.destroyAllOfType(null); } public void setRecovery() { @@ -1995,6 +1995,10 @@ public final class Player implements PlaybackListener, Listener { triggerProgressUpdate(); } + /** + * Remove the listener, if it was set. + * @param listener listener to remove + * */ public void removeFragmentListener(final PlayerServiceEventListener listener) { if (fragmentListener == listener) { fragmentListener = null; @@ -2009,6 +2013,10 @@ public final class Player implements PlaybackListener, Listener { triggerProgressUpdate(); } + /** + * Remove the listener, if it was set. + * @param listener listener to remove + * */ void removeActivityListener(final PlayerEventListener listener) { if (activityListener == listener) { activityListener = null; diff --git a/app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.kt b/app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.kt index e258d5ac1..24a46d1ef 100644 --- a/app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.kt +++ b/app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.kt @@ -50,19 +50,19 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) { /** * Destroys all matching player UIs and removes them from the list. - * @param playerUiType the class of the player UI to destroy; - * the [Class.isInstance] method will be used, so even subclasses will be + * @param playerUiType the class of the player UI to destroy, everything if `null`. + * The [Class.isInstance] method will be used, so even subclasses will be * destroyed and removed * @param T the class type parameter * */ - fun destroyAll(playerUiType: Class) { + fun destroyAllOfType(playerUiType: Class? = null) { val toDestroy = mutableListOf() // short blocking removal from class to prevent interfering from other threads playerUis.runWithLockSync { val new = mutableListOf() for (ui in lockData) { - if (playerUiType.isInstance(ui)) { + if (playerUiType == null || playerUiType.isInstance(ui)) { toDestroy.add(ui) } else { new.add(ui) @@ -83,7 +83,7 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) { * @param T the class type parameter * @return the first player UI of the required type found in the list, or null */ - fun get(playerUiType: Class): T? = + fun get(playerUiType: Class): T? = playerUis.runWithLockSync { for (ui in lockData) { if (playerUiType.isInstance(ui)) { @@ -105,7 +105,7 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) { * [Optional] otherwise */ @Deprecated("use get", ReplaceWith("get(playerUiType)")) - fun getOpt(playerUiType: Class): Optional = + fun getOpt(playerUiType: Class): Optional = Optional.ofNullable(get(playerUiType)) /**