Browse Source

LatestPostsFragment crash fix (when viewing profiles with no posts)

pull/70/head
Ezerous 4 years ago
parent
commit
a345545ac9
  1. 33
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsAdapter.java

33
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.PostSummary;
import gr.thmmy.mthmmy.model.TopicSummary; import gr.thmmy.mthmmy.model.TopicSummary;
import gr.thmmy.mthmmy.views.ReactiveWebView; 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 * {@link RecyclerView.Adapter} that can display a {@link TopicSummary} and makes a call to the
@ -61,22 +62,24 @@ class LatestPostsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
PostSummary topic = parsedTopicSummaries.get(position); if (holder instanceof LatestPostViewHolder){
final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder; PostSummary topic = parsedTopicSummaries.get(position);
latestPostViewHolder.postTitle.setText(topic.getSubject()); final LatestPostViewHolder latestPostViewHolder = (LatestPostViewHolder) holder;
latestPostViewHolder.postDate.setText(topic.getDateTime()); latestPostViewHolder.postTitle.setText(topic.getSubject());
latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255)); latestPostViewHolder.postDate.setText(topic.getDateTime());
latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/" latestPostViewHolder.post.setBackgroundColor(Color.argb(1, 255, 255, 255));
, topic.getPost(), "text/html", "UTF-8", null); latestPostViewHolder.post.loadDataWithBaseURL("file:///android_asset/"
, topic.getPost(), "text/html", "UTF-8", null);
latestPostViewHolder.latestPostsRow.setOnClickListener(v -> { latestPostViewHolder.latestPostsRow.setOnClickListener(v -> {
if (interactionListener != null) { if (interactionListener != null) {
// Notify the active callbacks interface (the activity, if the // Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that a post has been selected. // fragment is attached to one) that a post has been selected.
interactionListener.onLatestPostsFragmentInteraction( interactionListener.onLatestPostsFragmentInteraction(
parsedTopicSummaries.get(holder.getAdapterPosition())); parsedTopicSummaries.get(holder.getAdapterPosition()));
} }
}); });
}
} }
@Override @Override

Loading…
Cancel
Save