From a22b491a30a3ced7953883f0f0dfc3b783eef281 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 26 Jun 2019 12:03:41 +0800 Subject: Fixed bugs in CommentRecyclerViewAdapter. Minor layout tweaks. --- .../CommentRecyclerViewAdapter.java | 105 +++++++++++---------- .../infinityforreddit/ViewPostDetailActivity.java | 2 - 2 files changed, 53 insertions(+), 54 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java index d987a6b7..b357e35a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java @@ -143,25 +143,24 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter { - 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 = 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("")) { @@ -378,11 +377,8 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter children = comment.getChildren(); if(children != null && children.size() > 0) { + for(int i = 0; i < children.size(); i++) { + children.get(i).setExpanded(false); + } mVisibleComments.addAll(position + 1, children); - for(int i = position + 1; i <= position + children.size(); i++) { + /*for(int i = position + 1; i <= position + children.size(); i++) { mVisibleComments.get(i).setExpanded(false); - } - notifyItemRangeInserted(position + 1, children.size()); + }*/ + notifyItemRangeInserted(position + 2, children.size()); } } } @@ -489,7 +488,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter comments) { @@ -509,12 +508,21 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter { if(mVisibleComments.get(getAdapterPosition() - 1).isExpanded()) { - collapseChildren(getAdapterPosition()); + collapseChildren(getAdapterPosition() - 1); expandButton.setImageResource(R.drawable.ic_expand_more_black_20dp); } else { - expandChildren(getAdapterPosition()); + expandChildren(getAdapterPosition() - 1); mVisibleComments.get(getAdapterPosition() - 1).setExpanded(true); expandButton.setImageResource(R.drawable.ic_expand_less_black_20dp); } @@ -782,7 +786,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter