diff options
Diffstat (limited to 'app/src/main/java')
5 files changed, 65 insertions, 0 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); + } } |