diff options
author | Alex Ning <chineseperson5@gmail.com> | 2022-01-21 11:52:31 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2022-01-21 11:52:31 +0000 |
commit | e68f8ed4bca78214debc2ffafba7580bebdc63d0 (patch) | |
tree | 4d98ee5edb27f56a62805a9f691f2ac22c6b5046 /app/src/main | |
parent | de105359f90753828836dbe6181d45558a905bc3 (diff) | |
download | infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar.gz infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar.bz2 infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar.lz infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar.xz infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.tar.zst infinity-for-reddit-e68f8ed4bca78214debc2ffafba7580bebdc63d0.zip |
Show author avatars in comments.
Diffstat (limited to 'app/src/main')
6 files changed, 97 insertions, 13 deletions
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<Post> posts; @State Post post; + public Map<String, String> 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<Comment replyButton.setVisibility(View.GONE); + ((ConstraintLayout.LayoutParams) authorTextView.getLayoutParams()).setMarginStart(0); + ((ConstraintLayout.LayoutParams) authorFlairTextView.getLayoutParams()).setMarginStart(0); + if (mVoteButtonsOnTheRight) { ConstraintSet constraintSet = new ConstraintSet(); constraintSet.clone(bottomConstraintLayout); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index a11c0266..53edff81 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -28,6 +28,9 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; +import com.bumptech.glide.request.RequestOptions; import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import java.util.ArrayList; @@ -49,6 +52,7 @@ import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; +import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; @@ -96,6 +100,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi private Post mPost; private ArrayList<Comment> 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<RecyclerVi mExecutor = executor; mRetrofit = retrofit; mOauthRetrofit = oauthRetrofit; + mGlide = Glide.with(activity); mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor(); mCommentTextColor = customThemeWrapper.getCommentColor(); int commentSpoilerBackgroundColor = mCommentTextColor | 0xFF000000; @@ -397,6 +403,25 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi currentUserDrawable, null, null, null); } + if (comment.getAuthorIconUrl() == null) { + mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> { + 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<RecyclerVi ((CommentViewHolder) holder).authorTextView.setTextColor(mUsernameColor); ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.GONE); ((CommentViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); + mGlide.clear(((CommentViewHolder) holder).authorIconImageView); ((CommentViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor); ((CommentViewHolder) holder).awardsTextView.setText(""); ((CommentViewHolder) holder).awardsTextView.setVisibility(View.GONE); @@ -1078,6 +1104,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi public class CommentViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.linear_layout_item_comment) LinearLayout linearLayout; + @BindView(R.id.author_icon_image_view_item_post_comment) + ImageView authorIconImageView; @BindView(R.id.author_text_view_item_post_comment) TextView authorTextView; @BindView(R.id.author_flair_text_view_item_post_comment) @@ -1174,6 +1202,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (mActivity.contentTypeface != null) { commentMarkdownView.setTypeface(mActivity.contentTypeface); } + + authorIconImageView.setVisibility(View.VISIBLE); + itemView.setBackgroundColor(mCommentBackgroundColor); authorTextView.setTextColor(mUsernameColor); commentTimeTextView.setTextColor(mSecondaryTextColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java index 0663cac7..f7fb0062 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java @@ -30,6 +30,7 @@ public class Comment implements Parcelable { private String author; private String authorFlair; private String authorFlairHTML; + private String authorIconUrl; private String linkAuthor; private long commentTimeMillis; private String commentMarkdown; @@ -117,6 +118,7 @@ public class Comment implements Parcelable { author = in.readString(); authorFlair = in.readString(); authorFlairHTML = in.readString(); + authorIconUrl = in.readString(); linkAuthor = in.readString(); commentTimeMillis = in.readLong(); commentMarkdown = in.readString(); @@ -169,6 +171,14 @@ public class Comment implements Parcelable { return authorFlairHTML; } + public String getAuthorIconUrl() { + return authorIconUrl; + } + + public void setAuthorIconUrl(String authorIconUrl) { + this.authorIconUrl = authorIconUrl; + } + public String getLinkAuthor() { return linkAuthor; } @@ -385,6 +395,7 @@ public class Comment implements Parcelable { parcel.writeString(author); parcel.writeString(authorFlair); parcel.writeString(authorFlairHTML); + parcel.writeString(authorIconUrl); parcel.writeString(linkAuthor); parcel.writeLong(commentTimeMillis); parcel.writeString(commentMarkdown); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index a465dc8c..d9e9f452 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -84,6 +84,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity; import ml.docilealligator.infinityforreddit.adapters.CommentsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.PostDetailRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.apis.RedditAPI; +import ml.docilealligator.infinityforreddit.asynctasks.LoadUserData; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostCommentSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.comment.Comment; @@ -842,6 +843,18 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } } + public void loadIcon(String authorName, LoadIconListener loadIconListener) { + if (activity.authorIcons.containsKey(authorName)) { + loadIconListener.loadIconSuccess(authorName, activity.authorIcons.get(authorName)); + } else { + LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, + mRetrofit, iconImageUrl -> { + 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"> + <ImageView + android:id="@+id/author_icon_image_view_item_post_comment" + android:layout_width="24dp" + android:layout_height="24dp" + android:visibility="gone" + app:layout_constraintHorizontal_bias="0" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintEnd_toStartOf="@id/barrier4" /> + <TextView android:id="@+id/author_text_view_item_post_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:drawablePadding="4dp" - android:textSize="?attr/font_default" android:fontFamily="?attr/font_family" + android:textSize="?attr/font_default" + app:layout_constrainedWidth="true" app:layout_constraintBottom_toTopOf="@id/author_flair_text_view_item_post_comment" + app:layout_constraintStart_toEndOf="@id/author_icon_image_view_item_post_comment" app:layout_constraintEnd_toStartOf="@+id/barrier" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constrainedWidth="true" - app:layout_constraintHorizontal_bias="0" /> + app:layout_constraintHorizontal_bias="0" + app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/author_flair_text_view_item_post_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:fontFamily="?attr/font_family" android:textSize="?attr/font_12" android:visibility="gone" + app:layout_constrainedWidth="true" app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/author_icon_image_view_item_post_comment" app:layout_constraintEnd_toStartOf="@+id/barrier" app:layout_constraintHorizontal_bias="0" - app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/author_text_view_item_post_comment" - app:layout_constrainedWidth="true" tools:visibility="visible" /> <TextView @@ -60,9 +73,9 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" + 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_toStartOf="@id/comment_time_text_view_item_post_comment" 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" /> + <androidx.constraintlayout.widget.Barrier + android:id="@+id/barrier4" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:barrierDirection="start" + app:constraint_referenced_ids="author_text_view_item_post_comment,author_flair_text_view_item_post_comment" /> + </androidx.constraintlayout.widget.ConstraintLayout> <TextView @@ -103,10 +123,9 @@ android:id="@+id/comment_markdown_view_item_post_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:layout_marginStart="16dp" - android:layout_marginEnd="16dp" - android:layout_marginBottom="8dp" + android:layout_margin="8dp" + android:paddingStart="8dp" + android:paddingEnd="8dp" android:textColor="?attr/primaryTextColor" android:textSize="?attr/content_font_default" android:fontFamily="?attr/content_font_family" /> |