From e68f8ed4bca78214debc2ffafba7580bebdc63d0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 21 Jan 2022 19:52:31 +0800 Subject: Show author avatars in comments. --- .../activities/ViewPostDetailActivity.java | 3 ++ .../CommentsListingRecyclerViewAdapter.java | 3 ++ .../adapters/CommentsRecyclerViewAdapter.java | 31 +++++++++++++++ .../infinityforreddit/comment/Comment.java | 11 ++++++ .../fragments/ViewPostDetailFragment.java | 17 ++++++++ app/src/main/res/layout/item_comment.xml | 45 +++++++++++++++------- 6 files changed, 97 insertions(+), 13 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 3954bf2a..96d48c08 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -45,6 +45,8 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.Executor; import javax.inject.Inject; @@ -128,6 +130,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele ArrayList posts; @State Post post; + public Map authorIcons = new HashMap<>(); private FragmentManager fragmentManager; private SlidrInterface mSlidrInterface; private SectionsPagerAdapter sectionsPagerAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index 5800244d..6666d9a0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -388,6 +388,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter mVisibleComments; private Locale mLocale; + private RequestManager mGlide; private String mSingleCommentId; private boolean mIsSingleCommentThreadMode; private boolean mVoteButtonsOnTheRight; @@ -159,6 +164,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + if (authorName.equals(comment.getAuthor())) { + mGlide.load(iconUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((CommentViewHolder) holder).authorIconImageView); + comment.setAuthorIconUrl(iconUrl); + } + }); + } else { + mGlide.load(comment.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((CommentViewHolder) holder).authorIconImageView); + } + if (mShowElapsedTime) { ((CommentViewHolder) holder).commentTimeTextView.setText( Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis())); @@ -1036,6 +1061,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + activity.authorIcons.put(authorName, iconImageUrl); + loadIconListener.loadIconSuccess(authorName, iconImageUrl); + }); + } + } + @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.view_post_detail_fragment, menu); @@ -1952,4 +1965,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mPostAdapter.setCanPlayVideo(hasWindowsFocus); } } + + public interface LoadIconListener { + void loadIconSuccess(String authorName, String iconUrl); + } } diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index e64206d7..a97db526 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -24,35 +24,48 @@ android:paddingStart="16dp" android:paddingEnd="16dp"> + + + app:layout_constraintHorizontal_bias="0" + app:layout_constraintTop_toTopOf="parent" /> @@ -71,9 +84,9 @@ android:id="@+id/comment_time_text_view_item_post_comment" android:layout_width="0dp" android:layout_height="wrap_content" + android:fontFamily="?attr/font_family" android:gravity="end" android:textSize="?attr/font_default" - android:fontFamily="?attr/font_family" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -85,6 +98,13 @@ app:barrierDirection="start" app:constraint_referenced_ids="top_score_text_view_item_post_comment" /> + + -- cgit v1.2.3