From b96552a5ca133c3d5e71232a0b8ba7b42c46440f Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 26 Nov 2019 22:01:34 +0800 Subject: Fix force stop when navigating top-level comments. Fix invisible retry loading more posts button in dark theme. Minor bugs fixed. --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 85 ++++++++++------------ .../Adapter/PostRecyclerViewAdapter.java | 12 ++- .../infinityforreddit/Fragment/PostFragment.java | 8 +- .../infinityforreddit/PostDataSource.java | 24 +++--- 4 files changed, 64 insertions(+), 65 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 1ba01492..bed2287c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -258,7 +258,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -824,50 +818,48 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewUserDetailActivity.class); - if (mIsSingleCommentThreadMode) { - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mVisibleComments.get(holder.getAdapterPosition() - 2).getAuthor()); - } else { - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mVisibleComments.get(holder.getAdapterPosition() - 1).getAuthor()); - } + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor()); mActivity.startActivity(intent); }); @@ -928,8 +916,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { if (((CommentViewHolder) holder).expandButton.getVisibility() == View.VISIBLE) { int commentPosition = mIsSingleCommentThreadMode ? holder.getAdapterPosition() - 2 : holder.getAdapterPosition() - 1; - if(commentPosition < mVisibleComments.size()) { + if(commentPosition >= 0 && commentPosition < mVisibleComments.size()) { if (mVisibleComments.get(commentPosition).isExpanded()) { collapseChildren(commentPosition); ((CommentViewHolder) holder).expandButton.setImageResource(R.drawable.ic_expand_more_grey_24dp); @@ -1419,20 +1406,22 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0 && position < mVisibleComments.size()) { + if (mVisibleComments.get(position).hasReply()) { + mVisibleComments.get(position).setAuthor("[deleted]"); + mVisibleComments.get(position).setCommentContent("[deleted]"); + if (mIsSingleCommentThreadMode) { + notifyItemChanged(position + 2); + } else { + notifyItemChanged(position + 1); + } } else { - notifyItemRemoved(position + 1); + mVisibleComments.remove(position); + if (mIsSingleCommentThreadMode) { + notifyItemRemoved(position + 2); + } else { + notifyItemRemoved(position + 1); + } } } } @@ -1448,7 +1437,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0; i++) { if (mVisibleComments.get(i - 2).getDepth() == 0) { return i; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 96f1ce3f..25dd2e76 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -1372,7 +1372,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter mCallback.retryLoadingMore()); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index d8a38074..76999e26 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -476,9 +476,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mPostRecyclerView.setAdapter(mAdapter); mPostViewModel = new ViewModelProvider(this, factory).get(PostViewModel.class); - mPostViewModel.getPosts().observe(this, posts -> { - mAdapter.submitList(posts); - }); + mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts)); mPostViewModel.hasPost().observe(this, hasPost -> { this.hasPost = hasPost; @@ -542,14 +540,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void refresh() { + mPostViewModel.refresh(); if (isInLazyMode) { stopLazyMode(); } - mAdapter.setNetworkState(null); + mAdapter.removeFooter(); mFetchPostInfoLinearLayout.setVisibility(View.GONE); hasPost = false; - mPostViewModel.refresh(); } private void showErrorView(int stringResId) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java index d35d5667..4a0b81c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java @@ -196,9 +196,9 @@ public class PostDataSource extends PageKeyedDataSource { public void onParsePostSuccess(Post post) { ArrayList singlePostList = new ArrayList<>(); singlePostList.add(post); + callback.onResult(singlePostList, null, null); hasPostLiveData.postValue(true); initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(singlePostList, null, null); } @Override @@ -219,16 +219,17 @@ public class PostDataSource extends PageKeyedDataSource { } if (newPosts.size() != 0) { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(true); } else if (nextPageKey != null) { loadBestPostsInitial(callback, nextPageKey); return; } else { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(false); } initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(newPosts, null, nextPageKey); } @Override @@ -275,8 +276,8 @@ public class PostDataSource extends PageKeyedDataSource { if (newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadBestPostsAfter(params, callback, lastItem); } else { - paginationNetworkStateLiveData.postValue(NetworkState.LOADED); callback.onResult(newPosts, lastItem); + paginationNetworkStateLiveData.postValue(NetworkState.LOADED); } } @@ -327,9 +328,9 @@ public class PostDataSource extends PageKeyedDataSource { public void onParsePostSuccess(Post post) { ArrayList singlePostList = new ArrayList<>(); singlePostList.add(post); + callback.onResult(singlePostList, null, null); hasPostLiveData.postValue(true); initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(singlePostList, null, null); } @Override @@ -350,16 +351,17 @@ public class PostDataSource extends PageKeyedDataSource { } if (newPosts.size() != 0) { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(true); } else if (nextPageKey != null) { loadSubredditPostsInitial(callback, nextPageKey); return; } else { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(false); } initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(newPosts, null, nextPageKey); } @Override @@ -417,8 +419,8 @@ public class PostDataSource extends PageKeyedDataSource { if (newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadSubredditPostsAfter(params, callback, lastItem); } else { - paginationNetworkStateLiveData.postValue(NetworkState.LOADED); callback.onResult(newPosts, lastItem); + paginationNetworkStateLiveData.postValue(NetworkState.LOADED); } } @@ -476,16 +478,17 @@ public class PostDataSource extends PageKeyedDataSource { } if (newPosts.size() != 0) { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(true); } else if (nextPageKey != null) { loadUserPostsInitial(callback, nextPageKey); return; } else { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(false); } initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(newPosts, null, nextPageKey); } @Override @@ -539,8 +542,8 @@ public class PostDataSource extends PageKeyedDataSource { if (newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadUserPostsAfter(params, callback, lastItem); } else { - paginationNetworkStateLiveData.postValue(NetworkState.LOADED); callback.onResult(newPosts, lastItem); + paginationNetworkStateLiveData.postValue(NetworkState.LOADED); } } @@ -620,16 +623,17 @@ public class PostDataSource extends PageKeyedDataSource { } if (newPosts.size() != 0) { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(true); } else if (nextPageKey != null) { loadSearchPostsInitial(callback, nextPageKey); return; } else { + callback.onResult(newPosts, null, nextPageKey); hasPostLiveData.postValue(false); } initialLoadStateLiveData.postValue(NetworkState.LOADED); - callback.onResult(newPosts, null, nextPageKey); } @Override @@ -703,8 +707,8 @@ public class PostDataSource extends PageKeyedDataSource { if (newPosts.size() == 0 && lastItem != null && !lastItem.equals("") && !lastItem.equals("null")) { loadSearchPostsAfter(params, callback, lastItem); } else { - paginationNetworkStateLiveData.postValue(NetworkState.LOADED); callback.onResult(newPosts, lastItem); + paginationNetworkStateLiveData.postValue(NetworkState.LOADED); } } -- cgit v1.2.3