aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-16 03:50:30 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-10-16 03:50:30 +0000
commit448f36008f481703e50b81cd2fc85fc482f185fe (patch)
tree5d6cca30e5e56189e1151e08a741392bf3b6cd53 /app/src/main
parentb4afc015cddecad8a68f9b77c8a20bcc2538092e (diff)
downloadinfinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar.gz
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar.bz2
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar.lz
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar.xz
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.tar.zst
infinity-for-reddit-448f36008f481703e50b81cd2fc85fc482f185fe.zip
Continue adding comment filter.
Diffstat (limited to 'app/src/main')
-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.java60
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java29
3 files changed, 89 insertions, 4 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java
index ea079722..e6163aa5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java
@@ -36,10 +36,10 @@ public interface CommentFilterDao {
@Query("SELECT * FROM comment_filter")
List<CommentFilter> getAllCommentFilters();
- /*@Query("SELECT * FROM comment_filter WHERE comment_filter.name IN " +
+ @Query("SELECT * FROM comment_filter WHERE comment_filter.name IN " +
"(SELECT comment_filter_usage.name FROM comment_filter_usage WHERE (usage = :usage AND name_of_usage = :nameOfUsage) " +
"OR (usage =:usage AND name_of_usage = '--'))")
- List<CommentFilter> getValidCommentFilters(int usage, String nameOfUsage);*/
+ List<CommentFilter> getValidCommentFilters(int usage, String nameOfUsage);
@Transaction
@Query("SELECT * FROM comment_filter ORDER BY name")
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java
index a250e7b0..368452ce 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsage.java
@@ -1,4 +1,62 @@
package ml.docilealligator.infinityforreddit.commentfilter;
-public class CommentFilterUsage {
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+import androidx.room.ForeignKey;
+
+@Entity(tableName = "comment_filter_usage", primaryKeys = {"name", "usage", "name_of_usage"},
+ foreignKeys = @ForeignKey(entity = CommentFilter.class, parentColumns = "name",
+ childColumns = "name", onDelete = ForeignKey.CASCADE))
+public class CommentFilterUsage implements Parcelable {
+ public static final int SUBREDDIT_TYPE = 1;
+ public static final int USER_TYPE = 2;
+
+ @NonNull
+ @ColumnInfo(name = "name")
+ public String name;
+ @ColumnInfo(name = "usage")
+ public int usage;
+ @NonNull
+ @ColumnInfo(name = "name_of_usage")
+ public String nameOfUsage;
+
+ public CommentFilterUsage(@NonNull String name, int usage, @NonNull String nameOfUsage) {
+ this.name = name;
+ this.usage = usage;
+ this.nameOfUsage = nameOfUsage;
+ }
+
+ protected CommentFilterUsage(Parcel in) {
+ name = in.readString();
+ usage = in.readInt();
+ nameOfUsage = in.readString();
+ }
+
+ public static final Creator<CommentFilterUsage> CREATOR = new Creator<CommentFilterUsage>() {
+ @Override
+ public CommentFilterUsage createFromParcel(Parcel in) {
+ return new CommentFilterUsage(in);
+ }
+
+ @Override
+ public CommentFilterUsage[] newArray(int size) {
+ return new CommentFilterUsage[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(@NonNull Parcel dest, int flags) {
+ dest.writeString(name);
+ dest.writeInt(usage);
+ dest.writeString(nameOfUsage);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java
index ebd1e8dd..0ed0aec2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterUsageDao.java
@@ -1,4 +1,31 @@
package ml.docilealligator.infinityforreddit.commentfilter;
-public class CommentFilterUsageDao {
+import androidx.lifecycle.LiveData;
+import androidx.room.Dao;
+import androidx.room.Delete;
+import androidx.room.Insert;
+import androidx.room.OnConflictStrategy;
+import androidx.room.Query;
+
+import java.util.List;
+
+@Dao
+public interface CommentFilterUsageDao {
+ @Query("SELECT * FROM comment_filter_usage WHERE name = :name")
+ LiveData<List<CommentFilterUsage>> getAllCommentFilterUsageLiveData(String name);
+
+ @Query("SELECT * FROM comment_filter_usage WHERE name = :name")
+ List<CommentFilterUsage> getAllCommentFilterUsage(String name);
+
+ @Query("SELECT * FROM comment_filter_usage")
+ List<CommentFilterUsage> getAllCommentFilterUsageForBackup();
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insert(CommentFilterUsage CommentFilterUsage);
+
+ @Insert(onConflict = OnConflictStrategy.REPLACE)
+ void insertAll(List<CommentFilterUsage> CommentFilterUsageList);
+
+ @Delete
+ void deleteCommentFilterUsage(CommentFilterUsage CommentFilterUsage);
}