From 4c8dca53009cd6f8571f41f8a467117102623a4c Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Sun, 28 Nov 2021 13:42:26 +0100 Subject: [PATCH] Fixed NPE + Problems with context --- .../fragments/detail/VideoDetailFragment.java | 5 ++++- .../fragments/detail/VideoDetailPlayerCrasher.java | 14 +++++++------- 2 files changed, 11 insertions(+), 8 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 b54a04d6f..8c6e01537 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 @@ -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()) ); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java index 9ddad9855..9309a8a49 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java @@ -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; - } }