diff --git a/.gitignore b/.gitignore index 9200a734..bd589800 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,5 @@ Temporary Items \.idea/ + +readropsdb/schemas/ diff --git a/readropsdb/build.gradle b/readropsdb/build.gradle index e9374c0c..ef3c9854 100644 --- a/readropsdb/build.gradle +++ b/readropsdb/build.gradle @@ -13,7 +13,8 @@ android { javaCompileOptions { annotationProcessorOptions { arguments = [ - "room.incremental": "true" + "room.incremental" : "true", + "room.schemaLocation": "$projectDir/schemas".toString() ] } } diff --git a/readropsdb/src/main/java/com/readrops/readropsdb/Database.java b/readropsdb/src/main/java/com/readrops/readropsdb/Database.java index 32df2ece..180c4dc9 100644 --- a/readropsdb/src/main/java/com/readrops/readropsdb/Database.java +++ b/readropsdb/src/main/java/com/readrops/readropsdb/Database.java @@ -10,13 +10,15 @@ import com.readrops.readropsdb.dao.AccountDao; import com.readrops.readropsdb.dao.FeedDao; import com.readrops.readropsdb.dao.FolderDao; import com.readrops.readropsdb.dao.ItemDao; +import com.readrops.readropsdb.dao.NotificationPermissionDao; +import com.readrops.readropsdb.entities.NotificationPermission; import com.readrops.readropsdb.entities.account.Account; import com.readrops.readropsdb.entities.Feed; import com.readrops.readropsdb.entities.Folder; import com.readrops.readropsdb.entities.Item; -@androidx.room.Database(entities = {Feed.class, Item.class, Folder.class, Account.class}, version = 1, exportSchema = false) +@androidx.room.Database(entities = {Feed.class, Item.class, Folder.class, Account.class, NotificationPermission.class}, version = 2) @TypeConverters({Converters.class}) public abstract class Database extends RoomDatabase { @@ -28,6 +30,8 @@ public abstract class Database extends RoomDatabase { public abstract AccountDao accountDao(); + public abstract NotificationPermissionDao notificationPermissionDao(); + private static Database database; public static Database getInstance(Context context) { diff --git a/readropsdb/src/main/java/com/readrops/readropsdb/dao/NotificationPermissionDao.kt b/readropsdb/src/main/java/com/readrops/readropsdb/dao/NotificationPermissionDao.kt new file mode 100644 index 00000000..f799954f --- /dev/null +++ b/readropsdb/src/main/java/com/readrops/readropsdb/dao/NotificationPermissionDao.kt @@ -0,0 +1,15 @@ +package com.readrops.readropsdb.dao + +import androidx.room.Dao +import androidx.room.Query +import com.readrops.readropsdb.entities.NotificationPermission + +@Dao +interface NotificationPermissionDao : BaseDao { + + @Query("Select NotificationPermission.* From NotificationPermission Inner Join Feed Where Feed.id = NotificationPermission.feedId And Feed.account_id = :accountId") + fun selectAll(accountId: Int) : List + + @Query("Update NotificationPermission set enabled = :enabled Where id = :id") + fun setEnableState(id: Int, enabled: Boolean) +} \ No newline at end of file diff --git a/readropsdb/src/main/java/com/readrops/readropsdb/entities/NotificationPermission.kt b/readropsdb/src/main/java/com/readrops/readropsdb/entities/NotificationPermission.kt new file mode 100644 index 00000000..2f14659c --- /dev/null +++ b/readropsdb/src/main/java/com/readrops/readropsdb/entities/NotificationPermission.kt @@ -0,0 +1,12 @@ +package com.readrops.readropsdb.entities + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity(foreignKeys = [ForeignKey(entity = Feed::class, parentColumns = ["id"], + childColumns = ["feedId"], onDelete = ForeignKey.CASCADE)]) +data class NotificationPermission(@PrimaryKey(autoGenerate = true) val id: Int, + @ColumnInfo(index = true) val feedId: Int, + val enabled: Boolean) \ No newline at end of file