diff options
3 files changed, 86 insertions, 2 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 480adf81..6d4bb146 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -14,6 +14,8 @@ import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.account.AccountDao; import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeDao; +import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubreddit; +import ml.docilealligator.infinityforreddit.multireddit.AnonymousMultiredditSubredditDao; import ml.docilealligator.infinityforreddit.multireddit.MultiReddit; import ml.docilealligator.infinityforreddit.multireddit.MultiRedditDao; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; @@ -35,7 +37,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}, version = 20) + ReadPost.class, PostFilter.class, PostFilterUsage.class, AnonymousMultiredditSubreddit.class}, version = 21) public abstract class RedditDataRoomDatabase extends RoomDatabase { private static RedditDataRoomDatabase INSTANCE; @@ -49,7 +51,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, 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_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21) .build(); } } @@ -79,6 +81,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { public abstract PostFilterUsageDao postFilterUsageDao(); + public abstract AnonymousMultiredditSubredditDao anonymousMultiredditSubredditDao(); + private static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(SupportSQLiteDatabase database) { @@ -339,4 +343,13 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { database.execSQL("ALTER TABLE post_filter ADD COLUMN exclude_domains TEXT"); } }; + + private static final Migration MIGRATION_20_21 = new Migration(20, 21) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE anonymous_multireddit_subreddits (path TEXT NOT NULL, username TEXT NOT NULL, subreddit_name TEXT NOT NULL, " + + "PRIMARY KEY(path, username, subreddit_name), FOREIGN KEY(path) REFERENCES multi_reddits(path) ON DELETE CASCADE ON UPDATE CASCADE, " + + "FOREIGN KEY(username) REFERENCES multi_reddits(username) ON DELETE CASCADE ON UPDATE CASCADE)"); + } + }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java new file mode 100644 index 00000000..069d36f6 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubreddit.java @@ -0,0 +1,53 @@ +package ml.docilealligator.infinityforreddit.multireddit; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.ForeignKey; + +@Entity(tableName = "anonymous_multireddit_subreddits", primaryKeys = {"path", "username", "subreddit_name"}, + foreignKeys = @ForeignKey(entity = MultiReddit.class, parentColumns = {"path", "username"}, + childColumns = {"path", "username"}, onDelete = ForeignKey.CASCADE, onUpdate = ForeignKey.CASCADE)) +public class AnonymousMultiredditSubreddit { + @NonNull + @ColumnInfo(name = "path") + private String path; + @NonNull + @ColumnInfo(name = "username") + private String username = "-"; + @NonNull + @ColumnInfo(name = "subreddit_name") + private String subredditName; + + public AnonymousMultiredditSubreddit(@NonNull String path, @NonNull String subredditName) { + this.path = path; + this.subredditName = subredditName; + } + + @NonNull + public String getPath() { + return path; + } + + public void setPath(@NonNull String path) { + this.path = path; + } + + @NonNull + public String getUsername() { + return username; + } + + public void setUsername(@NonNull String username) { + this.username = username; + } + + @NonNull + public String getSubredditName() { + return subredditName; + } + + public void setSubredditName(@NonNull String subredditName) { + this.subredditName = subredditName; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubredditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubredditDao.java new file mode 100644 index 00000000..8728349c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/AnonymousMultiredditSubredditDao.java @@ -0,0 +1,18 @@ +package ml.docilealligator.infinityforreddit.multireddit; + +import androidx.lifecycle.LiveData; +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.OnConflictStrategy; +import androidx.room.Query; + +import java.util.List; + +@Dao +public interface AnonymousMultiredditSubredditDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(AnonymousMultiredditSubreddit anonymousMultiredditSubreddit); + + @Query("SELECT * FROM anonymous_multireddit_subreddits WHERE path = :path ORDER BY subreddit_name COLLATE NOCASE ASC") + LiveData<List<AnonymousMultiredditSubreddit>> getAllAnonymousMultiRedditSubreddits(String path); +} |