Fix NullPointerException in PostFilter.mergePostFilter. Minor bugs fixed in CommentsListingFragment.

This commit is contained in:
Alex Ning 2021-02-05 12:27:58 +08:00
parent 370e02c311
commit efd8d1c080
2 changed files with 98 additions and 87 deletions

View File

@ -254,6 +254,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
private void bindView(Resources resources) { private void bindView(Resources resources) {
if (mActivity != null && !mActivity.isFinishing() && !mActivity.isDestroyed()) {
mLinearLayoutManager = new LinearLayoutManager(mActivity); mLinearLayoutManager = new LinearLayoutManager(mActivity);
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager); mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
@ -329,6 +330,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh()); mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh());
} }
}
public void changeSortType(SortType sortType) { public void changeSortType(SortType sortType) {
mCommentViewModel.changeSortType(sortType); mCommentViewModel.changeSortType(sortType);

View File

@ -212,10 +212,10 @@ public class PostFilter implements Parcelable {
} }
public static PostFilter mergePostFilter(List<PostFilter> postFilterList) { public static PostFilter mergePostFilter(List<PostFilter> postFilterList) {
PostFilter postFilter = new PostFilter();
if (postFilterList.size() == 1) { if (postFilterList.size() == 1) {
return postFilterList.get(0); return postFilterList.get(0);
} }
PostFilter postFilter = new PostFilter();
StringBuilder stringBuilder; StringBuilder stringBuilder;
postFilter.name = "Merged"; postFilter.name = "Merged";
for (PostFilter p : postFilterList) { for (PostFilter p : postFilterList) {
@ -229,30 +229,39 @@ public class PostFilter implements Parcelable {
postFilter.onlyNSFW = p.onlyNSFW ? p.onlyNSFW : postFilter.onlyNSFW; postFilter.onlyNSFW = p.onlyNSFW ? p.onlyNSFW : postFilter.onlyNSFW;
postFilter.onlySpoiler = p.onlySpoiler ? p.onlySpoiler : postFilter.onlySpoiler; postFilter.onlySpoiler = p.onlySpoiler ? p.onlySpoiler : postFilter.onlySpoiler;
postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex.equals("") ? postFilter.postTitleExcludesRegex : p.postTitleExcludesRegex; if (p.postTitleExcludesRegex != null && !p.postTitleExcludesRegex.equals("")) {
stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings); postFilter.postTitleExcludesRegex = p.postTitleExcludesRegex;
}
if (p.postTitleExcludesStrings != null && !p.postTitleExcludesStrings.equals("")) {
stringBuilder = new StringBuilder(postFilter.postTitleExcludesStrings == null ? "" : postFilter.postTitleExcludesStrings);
stringBuilder.append(",").append(p.postTitleExcludesStrings); stringBuilder.append(",").append(p.postTitleExcludesStrings);
postFilter.postTitleExcludesStrings = stringBuilder.toString(); postFilter.postTitleExcludesStrings = stringBuilder.toString();
}
postFilter.excludeSubreddits = p.excludeSubreddits.equals("") ? postFilter.excludeSubreddits : p.postTitleExcludesRegex; if (p.excludeSubreddits != null && !p.excludeSubreddits.equals("")) {
stringBuilder = new StringBuilder(postFilter.excludeSubreddits); stringBuilder = new StringBuilder(postFilter.excludeSubreddits == null ? "" : postFilter.excludeSubreddits);
stringBuilder.append(",").append(p.excludeSubreddits); stringBuilder.append(",").append(p.excludeSubreddits);
postFilter.excludeSubreddits = stringBuilder.toString(); postFilter.excludeSubreddits = stringBuilder.toString();
}
postFilter.excludeUsers = p.excludeUsers.equals("") ? postFilter.excludeUsers : p.postTitleExcludesRegex; if (p.excludeUsers != null && !p.excludeUsers.equals("")) {
stringBuilder = new StringBuilder(postFilter.excludeUsers); stringBuilder = new StringBuilder(postFilter.excludeUsers == null ? "" : postFilter.excludeUsers);
stringBuilder.append(",").append(p.excludeUsers); stringBuilder.append(",").append(p.excludeUsers);
postFilter.excludeUsers = stringBuilder.toString(); postFilter.excludeUsers = stringBuilder.toString();
}
postFilter.containFlairs = p.containFlairs.equals("") ? postFilter.containFlairs : p.postTitleExcludesRegex; if (p.containFlairs != null && !p.containFlairs.equals("")) {
stringBuilder = new StringBuilder(postFilter.containFlairs); stringBuilder = new StringBuilder(postFilter.containFlairs == null ? "" : postFilter.containFlairs);
stringBuilder.append(",").append(p.containFlairs); stringBuilder.append(",").append(p.containFlairs);
postFilter.containFlairs = stringBuilder.toString(); postFilter.containFlairs = stringBuilder.toString();
}
postFilter.excludeFlairs = p.excludeFlairs.equals("") ? postFilter.excludeFlairs : p.postTitleExcludesRegex; if (p.excludeFlairs != null && !p.excludeFlairs.equals("")) {
stringBuilder = new StringBuilder(postFilter.excludeFlairs); stringBuilder = new StringBuilder(postFilter.excludeFlairs == null ? "" : postFilter.excludeFlairs);
stringBuilder.append(",").append(p.excludeFlairs); stringBuilder.append(",").append(p.excludeFlairs);
postFilter.excludeFlairs = stringBuilder.toString(); postFilter.excludeFlairs = stringBuilder.toString();
}
postFilter.containTextType = p.containTextType || postFilter.containTextType; postFilter.containTextType = p.containTextType || postFilter.containTextType;
postFilter.containLinkType = p.containLinkType || postFilter.containLinkType; postFilter.containLinkType = p.containLinkType || postFilter.containLinkType;