From a345545ac9ce59bad29a6f8595884a968313c258 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 7 Sep 2020 18:59:13 +0300 Subject: [PATCH] LatestPostsFragment crash fix (when viewing profiles with no posts) --- .../latestPosts/LatestPostsAdapter.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java index e42e4095..3e82c5df 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java @@ -19,6 +19,7 @@ import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.model.PostSummary; import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.views.ReactiveWebView; +import timber.log.Timber; /** * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the @@ -61,22 +62,24 @@ class LatestPostsAdapter extends RecyclerView.Adapter { @SuppressLint("ClickableViewAccessibility") @Override public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) { - PostSummary topic = parsedTopicSummaries.get(position); - final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder; - latestPostViewHolder.postTitle.setText(topic.getSubject()); - latestPostViewHolder.postDate.setText(topic.getDateTime()); - latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); - latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" - , topic.getPost(), "text/html", "UTF-8", null); + if (holder instanceof LatestPostViewHolder){ + PostSummary topic = parsedTopicSummaries.get(position); + final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder; + latestPostViewHolder.postTitle.setText(topic.getSubject()); + latestPostViewHolder.postDate.setText(topic.getDateTime()); + latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); + latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" + , topic.getPost(), "text/html", "UTF-8", null); - latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { - if (interactionListener != null) { - // Notify the active callbacks interface (the activity, if the - // fragment is attached to one) that a post has been selected. - interactionListener.onLatestPostsFragmentInteraction( - parsedTopicSummaries.get(holder.getAdapterPosition())); - } - }); + latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { + if (interactionListener != null) { + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that a post has been selected. + interactionListener.onLatestPostsFragmentInteraction( + parsedTopicSummaries.get(holder.getAdapterPosition())); + } + }); + } } @Override