From b4afc015cddecad8a68f9b77c8a20bcc2538092e Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:37:16 -0400 Subject: Continue adding comment filter. --- .../infinityforreddit/RedditDataRoomDatabase.java | 13 ++++++- .../commentfilter/CommentFilterDao.java | 43 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index ac76b6c9..c9eeba48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -13,6 +13,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase; import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.account.AccountDao; +import ml.docilealligator.infinityforreddit.commentfilter.CommentFilter; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDao; import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; @@ -38,7 +39,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}, version = 24) + ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class, CommentFilter.class}, version = 25) public abstract class RedditDataRoomDatabase extends RoomDatabase { public static RedditDataRoomDatabase create(final Context context) { @@ -49,7 +50,7 @@ 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_21_22, MIGRATION_22_23, MIGRATION_23_24, MIGRATION_24_25) .build(); } @@ -391,4 +392,12 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { database.execSQL("ALTER TABLE custom_themes ADD COLUMN read_post_filled_card_view_background_color INTEGER DEFAULT " + Color.parseColor("#F5F5F5") + " NOT NULL"); } }; + + private static final Migration MIGRATION_24_25 = new Migration(24, 25) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE comment_filter " + + "(name TEXT NOT NULL PRIMARY KEY, max_vote INTEGER NOT NULL, min_vote INTEGER NOT NULL, exclude_strings TEXT)"); + } + }; } 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 944663f1..ea079722 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/commentfilter/CommentFilterDao.java @@ -1,4 +1,47 @@ package ml.docilealligator.infinityforreddit.commentfilter; +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 androidx.room.Transaction; + +import java.util.List; + +@Dao public interface CommentFilterDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(CommentFilter CommentFilter); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insertAll(List CommentFilters); + + @Query("DELETE FROM comment_filter") + void deleteAllCommentFilters(); + + @Delete + void deleteCommentFilter(CommentFilter CommentFilter); + + @Query("DELETE FROM comment_filter WHERE name = :name") + void deleteCommentFilter(String name); + + @Query("SELECT * FROM comment_filter WHERE name = :name LIMIT 1") + CommentFilter getCommentFilter(String name); + + @Query("SELECT * FROM comment_filter ORDER BY name") + LiveData> getAllCommentFiltersLiveData(); + + @Query("SELECT * FROM comment_filter") + List getAllCommentFilters(); + + /*@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 getValidCommentFilters(int usage, String nameOfUsage);*/ + + @Transaction + @Query("SELECT * FROM comment_filter ORDER BY name") + public LiveData> getAllCommentFilterWithUsageLiveData(); } -- cgit v1.2.3