aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilter.java103
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterWithUsage.java5
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 {
+
+}