From 5fdeeb73017ea71dda25380fd7d29b65479fdd39 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Thu, 19 Nov 2020 01:12:45 +0900 Subject: [PATCH] Add null and cast checks. Should fix https://github.com/austinhuang0131/barinsta/issues/278 --- .../DirectMessageThreadFragment.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index 8c8cf91a..087468cb 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -18,8 +18,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.widget.ArrayAdapter; -import android.widget.LinearLayout; import android.widget.Toast; import androidx.annotation.NonNull; @@ -476,9 +476,16 @@ public class DirectMessageThreadFragment extends Fragment { if (text != null) { binding.commentText.setText(""); } else { - final LinearLayout dim = (LinearLayout) binding.messageList.findViewWithTag(directItemModel).getParent(); - if (dim.findViewById(R.id.liked_container) != null) { - dim.findViewById(R.id.liked_container).setVisibility(delete ? View.GONE : View.VISIBLE); + final View viewWithTag = binding.messageList.findViewWithTag(directItemModel); + if (viewWithTag != null) { + final ViewParent dim = viewWithTag.getParent(); + if (dim instanceof View) { + final View dimView = (View) dim; + final View likedContainer = dimView.findViewById(R.id.liked_container); + if (likedContainer != null) { + likedContainer.setVisibility(delete ? View.GONE : View.VISIBLE); + } + } } directItemModel.setLiked(); }