Add NotificationPermission entity

This commit is contained in:
Shinokuni 2020-03-11 22:36:52 +01:00
parent 2f7fd36511
commit 4762828980
5 changed files with 36 additions and 2 deletions

2
.gitignore vendored
View File

@ -125,3 +125,5 @@ Temporary Items
\.idea/ \.idea/
readropsdb/schemas/

View File

@ -13,7 +13,8 @@ android {
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {
arguments = [ arguments = [
"room.incremental": "true" "room.incremental" : "true",
"room.schemaLocation": "$projectDir/schemas".toString()
] ]
} }
} }

View File

@ -10,13 +10,15 @@ import com.readrops.readropsdb.dao.AccountDao;
import com.readrops.readropsdb.dao.FeedDao; import com.readrops.readropsdb.dao.FeedDao;
import com.readrops.readropsdb.dao.FolderDao; import com.readrops.readropsdb.dao.FolderDao;
import com.readrops.readropsdb.dao.ItemDao; 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.account.Account;
import com.readrops.readropsdb.entities.Feed; import com.readrops.readropsdb.entities.Feed;
import com.readrops.readropsdb.entities.Folder; import com.readrops.readropsdb.entities.Folder;
import com.readrops.readropsdb.entities.Item; 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}) @TypeConverters({Converters.class})
public abstract class Database extends RoomDatabase { public abstract class Database extends RoomDatabase {
@ -28,6 +30,8 @@ public abstract class Database extends RoomDatabase {
public abstract AccountDao accountDao(); public abstract AccountDao accountDao();
public abstract NotificationPermissionDao notificationPermissionDao();
private static Database database; private static Database database;
public static Database getInstance(Context context) { public static Database getInstance(Context context) {

View File

@ -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<NotificationPermission> {
@Query("Select NotificationPermission.* From NotificationPermission Inner Join Feed Where Feed.id = NotificationPermission.feedId And Feed.account_id = :accountId")
fun selectAll(accountId: Int) : List<NotificationPermission>
@Query("Update NotificationPermission set enabled = :enabled Where id = :id")
fun setEnableState(id: Int, enabled: Boolean)
}

View File

@ -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)