diff options
-rw-r--r-- | .idea/caches/gradle_models.ser | bin | 251125 -> 251140 bytes | |||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java | 105 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java | 2 | ||||
-rw-r--r-- | app/src/main/res/layout/item_load_comments_failed_placeholder.xml | 22 | ||||
-rw-r--r-- | app/src/main/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 Binary files differindex 4b82c52a..8a1ad8c2 100644 --- a/.idea/caches/gradle_models.ser +++ b/.idea/caches/gradle_models.ser 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<RecyclerView.ViewH if(mPost.getSubredditIconUrl() == null) { if(mLoadSubredditIconAsyncTask != null) { mLoadSubredditIconAsyncTask.cancel(true); - } else { - 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 = 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<RecyclerView.ViewH } } else if(holder instanceof LoadMoreCommentViewHolder) { CommentData placeholder; - if(isInitiallyLoading || isInitiallyLoadingFailed) { - placeholder = mVisibleComments.get(holder.getAdapterPosition() - 2); - } else { - placeholder = mVisibleComments.get(holder.getAdapterPosition() - 1); - } + placeholder = mVisibleComments.get(holder.getAdapterPosition() - 1); + ((LoadMoreCommentViewHolder) holder).verticalBlock.getLayoutParams().width = placeholder.getDepth() * 16; if(placeholder.isLoadingMoreChildren()) { ((LoadMoreCommentViewHolder) holder).placeholderTextView.setText(R.string.loading); @@ -467,11 +463,14 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH comment.setExpanded(true); ArrayList<CommentData> 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<RecyclerView.ViewH } mVisibleComments.subList(position + 1, position + 1 + allChildrenSize).clear(); - notifyItemRangeRemoved(position + 1, allChildrenSize); + notifyItemRangeRemoved(position + 2, allChildrenSize); } void addComments(ArrayList<CommentData> comments) { @@ -509,12 +508,21 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } void addComment(CommentData comment) { + if(mVisibleComments.size() == 0 || isInitiallyLoadingFailed) { + notifyItemRemoved(1); + } + mVisibleComments.add(0, comment); - notifyItemInserted(0); + + if(isInitiallyLoading) { + notifyItemInserted(2); + } else { + notifyItemInserted(1); + } } void addChildComment(CommentData comment, String parentFullname, int parentPosition) { - if(parentFullname.equals(mVisibleComments.get(parentPosition).getFullName())) { + if(!parentFullname.equals(mVisibleComments.get(parentPosition).getFullName())) { for(int i = 0; i < mVisibleComments.size(); i++) { if(parentFullname.equals(mVisibleComments.get(i).getFullName())) { parentPosition = i; @@ -527,10 +535,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH mVisibleComments.get(parentPosition).setHasReply(true); if(!mVisibleComments.get(parentPosition).isExpanded()) { expandChildren(parentPosition); - notifyItemChanged(parentPosition); + notifyItemChanged(parentPosition + 1); } else { mVisibleComments.add(parentPosition + 1, comment); - notifyItemInserted(parentPosition + 1); + notifyItemInserted(parentPosition + 2); } } @@ -539,7 +547,13 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH mLoadSubredditIconAsyncTask.cancel(true); } - if(isInitiallyLoading || isInitiallyLoadingFailed) { + if(mVisibleComments.size() != 0) { + int previousSize = mVisibleComments.size(); + mVisibleComments.clear(); + notifyItemRangeRemoved(1, previousSize); + } + + if(isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) { isInitiallyLoading = true; isInitiallyLoadingFailed = false; notifyItemChanged(1); @@ -548,8 +562,6 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH isInitiallyLoadingFailed = false; notifyItemInserted(1); } - - clearComments(); } void initiallyLoadCommentsFailed() { @@ -558,14 +570,6 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH notifyItemChanged(1); } - private void clearComments() { - if(mVisibleComments.size() != 0) { - int previousSize = mVisibleComments.size(); - mVisibleComments.clear(); - notifyItemRangeRemoved(1, previousSize); - } - } - @Override public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { if (holder instanceof CommentViewHolder) { @@ -575,7 +579,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH @Override public int getItemCount() { - if(isInitiallyLoading || isInitiallyLoadingFailed) { + if(isInitiallyLoading || isInitiallyLoadingFailed || mVisibleComments.size() == 0) { return 2; } @@ -767,10 +771,10 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH expandButton.setOnClickListener(view -> { 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<RecyclerView.ViewH intent.putExtra(CommentActivity.EXTRA_COMMENT_PARENT_TEXT_KEY, mVisibleComments.get(getAdapterPosition() - 1).getCommentContent()); intent.putExtra(CommentActivity.EXTRA_PARENT_FULLNAME_KEY, mVisibleComments.get(getAdapterPosition() - 1).getFullName()); intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, true); - intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, getAdapterPosition()); + intent.putExtra(CommentActivity.EXTRA_PARENT_POSITION_KEY, getAdapterPosition() - 1); mActivity.startActivityForResult(intent, CommentActivity.WRITE_COMMENT_REQUEST_CODE); }); @@ -1038,22 +1042,19 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH } class LoadCommentsViewHolder extends RecyclerView.ViewHolder { - - public LoadCommentsViewHolder(@NonNull View itemView) { + LoadCommentsViewHolder(@NonNull View itemView) { super(itemView); } } class LoadCommentsFailedViewHolder extends RecyclerView.ViewHolder { - - public LoadCommentsFailedViewHolder(@NonNull View itemView) { + LoadCommentsFailedViewHolder(@NonNull View itemView) { super(itemView); } } class NoCommentViewHolder extends RecyclerView.ViewHolder { - - public NoCommentViewHolder(@NonNull View itemView) { + NoCommentViewHolder(@NonNull View itemView) { super(itemView); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 0eb99830..fc60b109 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -13,7 +13,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -94,7 +93,6 @@ public class ViewPostDetailActivity extends AppCompatActivity { mRecyclerView.setNestedScrollingEnabled(false); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); - mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); if(savedInstanceState == null) { orientation = getResources().getConfiguration().orientation; diff --git a/app/src/main/res/layout/item_load_comments_failed_placeholder.xml b/app/src/main/res/layout/item_load_comments_failed_placeholder.xml index 476d3d2d..25af5d14 100644 --- a/app/src/main/res/layout/item_load_comments_failed_placeholder.xml +++ b/app/src/main/res/layout/item_load_comments_failed_placeholder.xml @@ -1,8 +1,20 @@ <?xml version="1.0" encoding="utf-8"?> -<TextView xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:gravity="center" - android:padding="36dp" - android:text="@string/post_load_comments_failed" - android:drawableTop="@drawable/load_post_error_indicator"/>
\ No newline at end of file + android:layout_marginTop="36dp" + android:orientation="vertical"> + + <ImageView + android:layout_width="150dp" + android:layout_height="150dp" + android:layout_gravity="center_horizontal" + android:src="@drawable/load_post_error_indicator"/> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:text="@string/post_load_comments_failed"/> + +</LinearLayout>
\ 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 @@ <?xml version="1.0" encoding="utf-8"?> -<TextView xmlns:android="http://schemas.android.com/apk/res/android" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/no_comments_yet" - android:gravity="center" - android:padding="36dp" - android:drawableTop="@drawable/no_comment_placeholder"/>
\ No newline at end of file + android:layout_marginTop="36dp" + android:orientation="vertical"> + + <ImageView + android:layout_width="150dp" + android:layout_height="150dp" + android:layout_gravity="center_horizontal" + android:src="@drawable/no_comment_placeholder" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:text="@string/no_comments_yet" /> + +</LinearLayout>
\ No newline at end of file |