From 94ce329f49268e8b297fd59de20ea03a1e08190d Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sat, 6 Jul 2024 13:35:59 +0200 Subject: [PATCH] fix(ErrorStatusDisplayItem): disable button in onBind Fixes a NullPointerException, where the `item` was null in the constructor, ironically causing the ErrorStatusDisplayItem to crash immediately. --- .../android/ui/displayitems/ErrorStatusDisplayItem.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java index 2000ee0c2..20ca27d6e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ErrorStatusDisplayItem.java @@ -30,17 +30,19 @@ public class ErrorStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder { + private final Button openInBrowserButton; public Holder(Context context, ViewGroup parent) { super(context, R.layout.display_item_error, parent); - Button openInBrowserButton=findViewById(R.id.button_open_browser); - openInBrowserButton.setEnabled(item.status.url!=null); + openInBrowserButton=findViewById(R.id.button_open_browser); openInBrowserButton.setOnClickListener(v -> UiUtils.launchWebBrowser(v.getContext(), item.status.url)); findViewById(R.id.button_copy_error_details).setOnClickListener(this::copyErrorDetails); } @Override - public void onBind(ErrorStatusDisplayItem item) {} + public void onBind(ErrorStatusDisplayItem item) { + openInBrowserButton.setEnabled(item.status!=null && item.status.url!=null); + } private void copyErrorDetails(View v) { StringWriter stringWriter=new StringWriter();