mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-06-26 15:13:00 +00:00
PlayerUIList: restrict superclasses a little
This commit is contained in:
parent
a8da9946d1
commit
731efc2124
@ -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;
|
||||
|
@ -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 </T>
|
||||
* */
|
||||
fun <T> destroyAll(playerUiType: Class<T?>) {
|
||||
fun <T : PlayerUi> destroyAllOfType(playerUiType: Class<T>? = null) {
|
||||
val toDestroy = mutableListOf<PlayerUi>()
|
||||
|
||||
// short blocking removal from class to prevent interfering from other threads
|
||||
playerUis.runWithLockSync {
|
||||
val new = mutableListOf<PlayerUi>()
|
||||
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
|
||||
</T> */
|
||||
fun <T> get(playerUiType: Class<T>): T? =
|
||||
fun <T : PlayerUi> get(playerUiType: Class<T>): T? =
|
||||
playerUis.runWithLockSync {
|
||||
for (ui in lockData) {
|
||||
if (playerUiType.isInstance(ui)) {
|
||||
@ -105,7 +105,7 @@ class PlayerUiList(vararg initialPlayerUis: PlayerUi) {
|
||||
* [Optional] otherwise
|
||||
</T> */
|
||||
@Deprecated("use get", ReplaceWith("get(playerUiType)"))
|
||||
fun <T> getOpt(playerUiType: Class<T>): Optional<T & Any> =
|
||||
fun <T : PlayerUi> getOpt(playerUiType: Class<T>): Optional<T> =
|
||||
Optional.ofNullable(get(playerUiType))
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user