npe fixes

This commit is contained in:
Yuriy Liskov
2025-04-21 10:14:59 +03:00
parent 8a9f00990b
commit 93e83b48cb
3 changed files with 14 additions and 8 deletions

View File

@ -619,6 +619,10 @@ public class PlayerUIController extends BasePlayerController {
} }
private boolean handleConfirmKey(int keyCode) { private boolean handleConfirmKey(int keyCode) {
if (getPlayer() == null) {
return false;
}
boolean controlsShown = getPlayer().isOverlayShown(); boolean controlsShown = getPlayer().isOverlayShown();
if (KeyHelpers.isConfirmKey(keyCode) && !controlsShown) { if (KeyHelpers.isConfirmKey(keyCode) && !controlsShown) {

View File

@ -56,9 +56,16 @@ public class FileUtils {
return false; return false;
} }
@Nullable
public static File getFile(Context context, String path) { public static File getFile(Context context, String path) {
File filesDir = ContextCompat.getExternalFilesDirs(context, null)[0];
if (filesDir == null) { // storage device is unavailable
return null;
}
String npath = path == null ? "" : path; String npath = path == null ? "" : path;
String absolutePath = ContextCompat.getExternalFilesDirs(context, null)[0].getPath(); String absolutePath = filesDir.getPath();
if (absolutePath.contains("/Android/data")) { if (absolutePath.contains("/Android/data")) {
int index = absolutePath.indexOf("/Android/data"); int index = absolutePath.indexOf("/Android/data");
String storage = absolutePath.substring(0, index).concat(npath.length() > 0 ? FILE_PATH_SEPARATOR : ""); String storage = absolutePath.substring(0, index).concat(npath.length() > 0 ? FILE_PATH_SEPARATOR : "");

View File

@ -1,6 +1,5 @@
package com.liskovsoft.smartyoutubetv2.tv.ui.webbrowser; package com.liskovsoft.smartyoutubetv2.tv.ui.webbrowser;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import com.liskovsoft.smartyoutubetv2.tv.R; import com.liskovsoft.smartyoutubetv2.tv.R;
import com.liskovsoft.smartyoutubetv2.tv.ui.common.LeanbackActivity; import com.liskovsoft.smartyoutubetv2.tv.ui.common.LeanbackActivity;
@ -11,11 +10,7 @@ public class WebBrowserActivity extends LeanbackActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
try { // WebBrowserFragment is not a Fragment: ClassCastException or Fragment.InstantiationException
setContentView(R.layout.fragment_webbrowser); setContentView(R.layout.fragment_webbrowser);
} catch (ClassCastException | Fragment.InstantiationException e) { // WebBrowserFragment is not a Fragment
e.printStackTrace();
finishReally();
}
} }
} }