diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-07-18 00:55:46 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-07-18 00:55:46 +0000 |
commit | 695076a1bdcae381db3255b296c551763d96ddcf (patch) | |
tree | 6a4f9b506d94cec9de066862959cad735c31e604 | |
parent | 6bbfa4f85ae8e3e66fa90df263be2a018e73a8f5 (diff) | |
download | infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar.gz infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar.bz2 infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar.lz infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar.xz infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.tar.zst infinity-for-reddit-695076a1bdcae381db3255b296c551763d96ddcf.zip |
Start implementing display mode for CommentFilter.
Diffstat (limited to '')
5 files changed, 58 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index ffbbb703..3891e495 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -43,7 +43,7 @@ import ml.docilealligator.infinityforreddit.user.UserData; @Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, SubscribedUserData.class, MultiReddit.class, CustomTheme.class, RecentSearchQuery.class, ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class, - CommentFilter.class, CommentFilterUsage.class}, version = 25) + CommentFilter.class, CommentFilterUsage.class}, version = 26) public abstract class RedditDataRoomDatabase extends RoomDatabase { public static RedditDataRoomDatabase create(final Context context) { @@ -54,7 +54,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17, MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21, - MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25) + MIGRATION_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25, + MIGRATION_25_26) .build(); } @@ -410,4 +411,11 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { "name_of_usage TEXT NOT NULL, PRIMARY KEY(name, usage, name_of_usage), FOREIGN KEY(name) REFERENCES comment_filter(name) ON DELETE CASCADE)"); } }; + + private static final Migration MIGRATION_25_26 = new Migration(25, 26) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE comment_filter ADD COLUMN display_mode INTEGER DEFAULT 0 NOT NULL"); + } + }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 65628bea..d2a46775 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -358,7 +358,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi Comment comment = mVisibleComments.get(position - 1); if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) { - if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) { + if ((mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) + || (comment.isFilteredOut() && !comment.hasExpandedBefore())) { return VIEW_TYPE_COMMENT_FULLY_COLLAPSED; } return VIEW_TYPE_COMMENT; @@ -376,7 +377,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi Comment comment = mVisibleComments.get(position); if (comment.getPlaceholderType() == Comment.NOT_PLACEHOLDER) { - if (mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) { + if ((mFullyCollapseComment && !comment.isExpanded() && comment.hasExpandedBefore()) + || (comment.isFilteredOut() && !comment.hasExpandedBefore())) { return VIEW_TYPE_COMMENT_FULLY_COLLAPSED; } return VIEW_TYPE_COMMENT; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java index 3d46c2f2..c838e32e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/Comment.java @@ -54,6 +54,7 @@ public class Comment implements Parcelable { private boolean saved; private boolean isExpanded; private boolean hasExpandedBefore; + private boolean isFilteredOut; private ArrayList<Comment> children; private ArrayList<String> moreChildrenIds; private int placeholderType; @@ -141,6 +142,7 @@ public class Comment implements Parcelable { scoreHidden = in.readByte() != 0; isExpanded = in.readByte() != 0; hasExpandedBefore = in.readByte() != 0; + isFilteredOut = in.readByte() != 0; children = new ArrayList<>(); in.readTypedList(children, Comment.CREATOR); moreChildrenIds = new ArrayList<>(); @@ -306,6 +308,14 @@ public class Comment implements Parcelable { return hasExpandedBefore; } + public boolean isFilteredOut() { + return isFilteredOut; + } + + public void setIsFilteredOut(boolean isFilteredOut) { + this.isExpanded = isFilteredOut; + } + public int getVoteType() { return voteType; } @@ -436,6 +446,7 @@ public class Comment implements Parcelable { parcel.writeByte((byte) (scoreHidden ? 1 : 0)); parcel.writeByte((byte) (isExpanded ? 1 : 0)); parcel.writeByte((byte) (hasExpandedBefore ? 1 : 0)); + parcel.writeByte((byte) (isFilteredOut ? 1 : 0)); parcel.writeTypedList(children); parcel.writeStringList(moreChildrenIds); parcel.writeInt(placeholderType); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java index 8a80f1a4..1593d29d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java @@ -191,8 +191,13 @@ public class ParseComment { for (int i = 0; i < actualCommentLength; i++) { JSONObject data = comments.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY); Comment singleComment = parseSingleComment(data, depth); + boolean isFilteredOut = false; if (!CommentFilter.isCommentAllowed(singleComment, commentFilter)) { - continue; + if (commentFilter.displayMode == CommentFilter.DisplayMode.REMOVE_COMMENT) { + continue; + } + + isFilteredOut = true; } if (data.get(JSONUtils.REPLIES_KEY) instanceof JSONObject) { @@ -205,6 +210,7 @@ public class ParseComment { singleComment.addChildren(children); singleComment.setMoreChildrenIds(nextMoreChildrenIds); singleComment.setChildCount(getChildCount(singleComment)); + singleComment.setIsFilteredOut(isFilteredOut); } newCommentData.add(singleComment); @@ -226,18 +232,22 @@ public class ParseComment { boolean setExpanded) { for (Comment c : comments) { visibleComments.add(c); - if (c.hasReply()) { - if (setExpanded) { + if (!c.isFilteredOut()) { + if (c.hasReply()) { + if (setExpanded) { + c.setExpanded(true); + } + expandChildren(c.getChildren(), visibleComments, setExpanded); + } else { c.setExpanded(true); } - expandChildren(c.getChildren(), visibleComments, setExpanded); - } else { - c.setExpanded(true); } if (c.hasMoreChildrenIds() && !c.getMoreChildrenIds().isEmpty()) { //Add a load more placeholder Comment placeholder = new Comment(c.getFullName(), c.getDepth() + 1, Comment.PLACEHOLDER_LOAD_MORE_COMMENTS); - visibleComments.add(placeholder); + if (!c.isFilteredOut()) { + visibleComments.add(placeholder); + } c.addChild(placeholder, c.getChildren().size()); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java index 93b65365..796fd68d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java @@ -3,11 +3,14 @@ package ml.docilealligator.infinityforreddit.commentfilter; import android.os.Parcel; import android.os.Parcelable; +import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.PrimaryKey; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.List; import ml.docilealligator.infinityforreddit.comment.Comment; @@ -17,6 +20,9 @@ public class CommentFilter implements Parcelable { @PrimaryKey @NonNull public String name = "New Filter"; + @DisplayMode + @ColumnInfo(name = "display_mode") + public int displayMode; @ColumnInfo(name = "max_vote") public int maxVote = -1; @ColumnInfo(name = "min_vote") @@ -86,16 +92,17 @@ public class CommentFilter implements Parcelable { commentFilter.name = "Merged"; for (CommentFilter c : commentFilterList) { + commentFilter.displayMode = Math.max(c.displayMode, commentFilter.displayMode); commentFilter.maxVote = Math.min(c.maxVote, commentFilter.maxVote); commentFilter.minVote = Math.max(c.minVote, commentFilter.minVote); - if (c.excludeStrings != null && !c.excludeStrings.equals("")) { + if (c.excludeStrings != null && !c.excludeStrings.isEmpty()) { stringBuilder = new StringBuilder(commentFilter.excludeStrings == null ? "" : commentFilter.excludeStrings); stringBuilder.append(",").append(c.excludeStrings); commentFilter.excludeStrings = stringBuilder.toString(); } - if (c.excludeUsers != null && !c.excludeUsers.equals("")) { + if (c.excludeUsers != null && !c.excludeUsers.isEmpty()) { stringBuilder = new StringBuilder(commentFilter.excludeUsers == null ? "" : commentFilter.excludeUsers); stringBuilder.append(",").append(c.excludeUsers); commentFilter.excludeUsers = stringBuilder.toString(); @@ -118,4 +125,11 @@ public class CommentFilter implements Parcelable { dest.writeString(excludeStrings); dest.writeString(excludeUsers); } + + @IntDef({DisplayMode.REMOVE_COMMENT, DisplayMode.COLLAPSE_COMMENT}) + @Retention(RetentionPolicy.SOURCE) + public @interface DisplayMode { + int REMOVE_COMMENT = 0; + int COLLAPSE_COMMENT = 10; + } } |