Fixed NPE + Problems with context

pull/7142/head
litetex 2021-11-28 13:42:26 +01:00
rodzic 2f99a217c3
commit 4c8dca5300
2 zmienionych plików z 11 dodań i 8 usunięć

Wyświetl plik

@ -657,7 +657,10 @@ public final class VideoDetailFragment
binding.detailControlsPlayWithKodi.setOnClickListener(this);
if (DEBUG) {
binding.detailControlsCrashThePlayer.setOnClickListener(
v -> VideoDetailPlayerCrasher.onCrashThePlayer(this.player, getLayoutInflater())
v -> VideoDetailPlayerCrasher.onCrashThePlayer(
this.getContext(),
this.player,
getLayoutInflater())
);
}

Wyświetl plik

@ -10,6 +10,7 @@ import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import com.google.android.exoplayer2.C;
@ -85,9 +86,12 @@ public final class VideoDetailPlayerCrasher {
: R.style.DarkTheme);
}
public static void onCrashThePlayer(final Player player, final LayoutInflater layoutInflater) {
final Context context = player.getContext();
if (!isPlayerAvailable(player)) {
public static void onCrashThePlayer(
@NonNull final Context context,
@Nullable final Player player,
@NonNull final LayoutInflater layoutInflater
) {
if (player == null) {
Log.d(TAG, "Player is not available");
Toast.makeText(context, "Player is not available", Toast.LENGTH_SHORT)
.show();
@ -152,8 +156,4 @@ public final class VideoDetailPlayerCrasher {
exPlayer);
}
}
private static boolean isPlayerAvailable(final Player player) {
return player != null;
}
}