Put notification permission in Feed instead of creating a new entity

This commit is contained in:
Shinokuni 2020-03-14 14:37:56 +01:00
parent c4848fc7c6
commit 513b455255
5 changed files with 17 additions and 33 deletions

View File

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

View File

@ -67,6 +67,10 @@ public abstract class FeedDao implements BaseDao<Feed> {
", Feed.siteUrl as feed_siteUrl, Feed.remoteId as feed_remoteId from Feed Left Join Folder on Feed.folder_id = Folder.id Where Feed.account_id = :accountId Order by Feed.name")
public abstract LiveData<List<FeedWithFolder>> getAllFeedsWithFolder(int accountId);
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("Select id, name, icon_url, notification_enabled, text_color, background_color, account_id From Feed Where account_id = :accountId")
public abstract LiveData<List<Feed>> getFeedsForNotifPermission(int accountId);
@Query("Select * From Feed Where id in (:ids)")
public abstract List<Feed> selectFromIdList(List<Long> ids);

View File

@ -1,15 +0,0 @@
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

@ -56,6 +56,9 @@ public class Feed implements Parcelable {
@ColumnInfo(name = "account_id", index = true)
private int accountId;
@ColumnInfo(name = "notification_enabled")
private boolean notificationEnabled;
@Ignore
private int unreadCount;
@ -226,6 +229,14 @@ public class Feed implements Parcelable {
this.accountId = accountId;
}
public boolean isNotificationEnabled() {
return notificationEnabled;
}
public void setNotificationEnabled(boolean notificationEnabled) {
this.notificationEnabled = notificationEnabled;
}
public String getRemoteFolderId() {
return remoteFolderId;
}

View File

@ -1,12 +0,0 @@
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)