From 6f4367c45929eafcb01d6d59594c590b49f45ce4 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 12 Jul 2019 14:56:42 +0800 Subject: Fixed user's icon cannot be shown if the post is sent to user space. Start ViewUserDetailActivity when clicking user name or user icon if the post is sent to user space. --- .../CommentRecyclerViewAdapter.java | 87 +++++++++++++++------ .../infinityforreddit/PostRecyclerViewAdapter.java | 90 +++++++++++++++------- 2 files changed, 126 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java index 8cc218b5..46987335 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java @@ -39,6 +39,7 @@ import java.util.Locale; import CustomView.AspectRatioGifImageView; import SubredditDatabase.SubredditRoomDatabase; +import User.UserRoomDatabase; import butterknife.BindView; import butterknife.ButterKnife; import jp.wasabeef.glide.transformations.BlurTransformation; @@ -161,13 +162,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter { + if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) { + if(mPost.getAuthorIconUrl() == null) { + new LoadUserDataAsyncTask(UserRoomDatabase.getDatabase(mActivity).userDao(), mPost.getAuthor(), mOauthRetrofit, iconImageUrl -> { + if(mActivity != null && getItemCount() > 0) { if(!iconImageUrl.equals("")) { mGlide.load(iconImageUrl) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) @@ -180,20 +178,57 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter= 0) { + mPost.setAuthorIconUrl(iconImageUrl); + } + } + }).execute(); + } else if(!mPost.getAuthorIconUrl().equals("")) { + mGlide.load(mPost.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } } else { - mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + if(mPost.getSubredditIconUrl() == null) { + if(mLoadSubredditIconAsyncTask != null) { + mLoadSubredditIconAsyncTask.cancel(true); + } + mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask( + SubredditRoomDatabase.getDatabase(mActivity).subredditDao(), mPost.getSubredditNamePrefixed().substring(2), + iconImageUrl -> { + if(!iconImageUrl.equals("")) { + mGlide.load(iconImageUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } + + mPost.setSubredditIconUrl(iconImageUrl); + }); + + mLoadSubredditIconAsyncTask.execute(); + } else if(!mPost.getSubredditIconUrl().equals("")) { + mGlide.load(mPost.getSubredditIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } else { + mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((PostDetailViewHolder) holder).mSubredditIconGifImageView); + } } switch (mPost.getVoteType()) { @@ -659,9 +694,15 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, - mPost.getSubredditNamePrefixed().substring(2)); + Intent intent; + if(mPost.getSubredditNamePrefixed().equals("u/" + mPost.getAuthor())) { + intent = new Intent(mActivity, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mPost.getAuthor()); + } else { + intent = new Intent(mActivity, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, + mPost.getSubredditNamePrefixed().substring(2)); + } mActivity.startActivity(intent); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index bb63a905..09c87319 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -152,37 +152,71 @@ class PostRecyclerViewAdapter extends PagedListAdapter { - if(mContext != null && getItemCount() > 0) { - if(!iconImageUrl.equals("")) { - glide.load(iconImageUrl) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(glide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((DataViewHolder) holder).subredditIconGifImageView); - } else { - glide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((DataViewHolder) holder).subredditIconGifImageView); - } + if(author.equals(subredditNamePrefixed)) { + if(post.getAuthorIconUrl() == null) { + new LoadUserDataAsyncTask(userDao, post.getAuthor(), mOauthRetrofit, iconImageUrl -> { + if(mContext != null && getItemCount() > 0) { + if(!iconImageUrl.equals("")) { + glide.load(iconImageUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } else { + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } - if(holder.getAdapterPosition() >= 0) { - post.setSubredditIconUrl(iconImageUrl); - } + if(holder.getAdapterPosition() >= 0) { + post.setAuthorIconUrl(iconImageUrl); } - }).execute(); - } else if(!post.getSubredditIconUrl().equals("")) { - glide.load(post.getSubredditIconUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(glide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(((DataViewHolder) holder).subredditIconGifImageView); + } + }).execute(); + } else if(!post.getAuthorIconUrl().equals("")) { + glide.load(post.getAuthorIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } else { + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } } else { - glide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .into(((DataViewHolder) holder).subredditIconGifImageView); + if(post.getSubredditIconUrl() == null) { + new LoadSubredditIconAsyncTask(subredditDao, subredditName, + iconImageUrl -> { + if(mContext != null && getItemCount() > 0) { + if(!iconImageUrl.equals("")) { + glide.load(iconImageUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } else { + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } + + if(holder.getAdapterPosition() >= 0) { + post.setSubredditIconUrl(iconImageUrl); + } + } + }).execute(); + } else if(!post.getSubredditIconUrl().equals("")) { + glide.load(post.getSubredditIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } else { + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(((DataViewHolder) holder).subredditIconGifImageView); + } } ((DataViewHolder) holder).subredditNameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent)); -- cgit v1.2.3