aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-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);
}