diff options
author | Sergei Kozelko <KozelkoS@yandex.ru> | 2022-11-03 01:47:10 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 01:47:10 +0000 |
commit | 78496e080f362def8265221301ab36a79947dd34 (patch) | |
tree | 6f51d700fca863cf27e25049093ac849fcf48a0e /app | |
parent | 191df66a3bae86bab0ca8cb31cef0e005900d31d (diff) | |
download | infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar.gz infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar.bz2 infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar.lz infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar.xz infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.tar.zst infinity-for-reddit-78496e080f362def8265221301ab36a79947dd34.zip |
Display comment avatar only if it is the right user (#1191)
Condition in callback for loading avatar url is almost always true[1]. So it would load avatar even if the viewholder got bound to another comment.
Ideally the solution would be to update the comment just like now, then find current position of the comment and call onItemChanged. However you cannot call onItemChanged from onBindViewHolder and that is a problem because callback can be executed synchronously.
So instead we just check that viewholder is bound to some comment and that bound comment's author matches initially requested author.
[1] The only case I know when it is false is when that comment got deleted and its author got replaced with "[deleted]" before the callback got executed
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 12 |
1 files changed, 10 insertions, 2 deletions
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 2046f5ed..34996b15 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -402,12 +402,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (comment.getAuthorIconUrl() == null) { mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> { if (authorName.equals(comment.getAuthor())) { + comment.setAuthorIconUrl(iconUrl); + } + + Comment currentComment = getCurrentComment(holder); + if (currentComment != null && authorName.equals(currentComment.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 { @@ -529,12 +533,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi if (comment.getAuthorIconUrl() == null) { mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> { if (authorName.equals(comment.getAuthor())) { + comment.setAuthorIconUrl(iconUrl); + } + + Comment currentComment = getCurrentComment(holder); + if (currentComment != null && authorName.equals(currentComment.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(((CommentFullyCollapsedViewHolder) holder).authorIconImageView); - comment.setAuthorIconUrl(iconUrl); } }); } else { |