diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-16 02:57:12 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-10-16 02:57:12 +0000 |
commit | 45b4ecf6ac2882bcdd597e0a40f3d04c197721c3 (patch) | |
tree | decca00c3ee3841738652db03740b71e609be45a /app | |
parent | 23c353275c16ff1d92723343c6e0197f204c7349 (diff) | |
download | infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar.gz infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar.bz2 infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar.lz infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar.xz infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.tar.zst infinity-for-reddit-45b4ecf6ac2882bcdd597e0a40f3d04c197721c3.zip |
Start adding comment filter.
Diffstat (limited to 'app')
5 files changed, 120 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java new file mode 100644 index 00000000..49c60d23 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java @@ -0,0 +1,103 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.comment.Comment; + +@Entity(tableName = "comment_filter") +public class CommentFilter implements Parcelable { + @PrimaryKey + @NonNull + public String name = "New Filter"; + @ColumnInfo(name = "max_vote") + public int maxVote = -1; + @ColumnInfo(name = "min_vote") + public int minVote = -1; + @ColumnInfo(name = "exclude_strings") + public String excludeStrings; + + public CommentFilter() { + + } + + protected CommentFilter(Parcel in) { + name = in.readString(); + maxVote = in.readInt(); + minVote = in.readInt(); + excludeStrings = in.readString(); + } + + public static final Creator<CommentFilter> CREATOR = new Creator<CommentFilter>() { + @Override + public CommentFilter createFromParcel(Parcel in) { + return new CommentFilter(in); + } + + @Override + public CommentFilter[] newArray(int size) { + return new CommentFilter[size]; + } + }; + + public static boolean isCommentAllowed(Comment comment, CommentFilter commentFilter) { + if (commentFilter.maxVote > 0 && comment.getVoteType() + comment.getScore() > commentFilter.maxVote) { + return false; + } + if (commentFilter.minVote > 0 && comment.getVoteType() + comment.getScore() < commentFilter.minVote) { + return false; + } + if (commentFilter.excludeStrings != null && !commentFilter.excludeStrings.equals("")) { + String[] titles = commentFilter.excludeStrings.split(",", 0); + for (String t : titles) { + if (!t.trim().equals("") && comment.getCommentRawText().toLowerCase().contains(t.toLowerCase().trim())) { + return false; + } + } + } + + return true; + } + + public static CommentFilter mergeCommentFilter(List<CommentFilter> commentFilterList) { + if (commentFilterList.size() == 1) { + return commentFilterList.get(0); + } + CommentFilter commentFilter = new CommentFilter(); + StringBuilder stringBuilder; + commentFilter.name = "Merged"; + + for (CommentFilter c : commentFilterList) { + commentFilter.maxVote = Math.min(c.maxVote, commentFilter.maxVote); + commentFilter.minVote = Math.max(c.minVote, commentFilter.minVote); + + if (c.excludeStrings != null && !c.excludeStrings.equals("")) { + stringBuilder = new StringBuilder(commentFilter.excludeStrings == null ? "" : commentFilter.excludeStrings); + stringBuilder.append(",").append(c.excludeStrings); + commentFilter.excludeStrings = stringBuilder.toString(); + } + } + + return commentFilter; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString(name); + dest.writeInt(maxVote); + dest.writeInt(minVote); + dest.writeString(excludeStrings); + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java new file mode 100644 index 00000000..944663f1 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java @@ -0,0 +1,4 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +public interface CommentFilterDao { +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java new file mode 100644 index 00000000..a250e7b0 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java @@ -0,0 +1,4 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +public class CommentFilterUsage { +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java new file mode 100644 index 00000000..ebd1e8dd --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java @@ -0,0 +1,4 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +public class CommentFilterUsageDao { +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java new file mode 100644 index 00000000..9ee9e856 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java @@ -0,0 +1,5 @@ +package ml.docilealligator.infinityforreddit.commentfilter; + +public class CommentFilterWithUsage { + +} |