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. --- .idea/caches/gradle_models.ser | Bin 251125 -> 251140 bytes .../CommentRecyclerViewAdapter.java | 105 +++++++++++---------- .../infinityforreddit/ViewPostDetailActivity.java | 2 - .../item_load_comments_failed_placeholder.xml | 22 ++++- .../res/layout/item_no_comment_placeholder.xml | 22 ++++- 5 files changed, 87 insertions(+), 64 deletions(-) diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 4b82c52a..8a1ad8c2 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ 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 - \ No newline at end of file + android:layout_marginTop="36dp" + android:orientation="vertical"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_no_comment_placeholder.xml b/app/src/main/res/layout/item_no_comment_placeholder.xml index becf93d4..707243c6 100644 --- a/app/src/main/res/layout/item_no_comment_placeholder.xml +++ b/app/src/main/res/layout/item_no_comment_placeholder.xml @@ -1,8 +1,20 @@ - \ No newline at end of file + android:layout_marginTop="36dp" + android:orientation="vertical"> + + + + + + \ No newline at end of file -- cgit v1.2.3