Delete UnreadItemsIds and StarredItem tables

This commit is contained in:
Shinokuni 2021-04-26 13:56:10 +02:00
parent 90468faefc
commit 750bf10902
8 changed files with 12 additions and 288 deletions

View File

@ -119,7 +119,7 @@ public class ItemActivity extends AppCompatActivity {
}));
viewModel = ViewModelCompat.getViewModel(this, ItemViewModel.class);
viewModel.getItemById(itemId, starredItem).observe(this, itemWithFeed1 -> {
viewModel.getItemById(itemId).observe(this, itemWithFeed1 -> {
if (!uiBinded) {
bindUI(itemWithFeed1);
uiBinded = true;

View File

@ -31,13 +31,9 @@ public class ItemViewModel extends ViewModel {
this.database = database;
}
public LiveData<ItemWithFeed> getItemById(int id, boolean starredItem) {
if (starredItem) {
return database.starredItemDao().getStarredItemById(id);
} else {
public LiveData<ItemWithFeed> getItemById(int id) {
return database.itemDao().getItemById(id);
}
}
public Completable setStarState(Item item) {
return KoinJavaComponent.get(ARepository.class).setItemStarState(item);

View File

@ -71,11 +71,15 @@ public class MainViewModel extends ViewModel {
DataSource.Factory<Integer, ItemWithFeed> items;
/*
if (queryFilters.getFilterType() == FilterType.STARS_FILTER && currentAccount.getAccountType().getAccountConfig().useStarredItems()) {
items = database.starredItemDao().selectAll(ItemsQueryBuilder.buildStarredItemsQuery(queryFilters));
} else {
items = database.itemDao().selectAll(ItemsQueryBuilder.buildItemsQuery(queryFilters));
}
*/
items = database.itemDao().selectAll(ItemsQueryBuilder.buildItemsQuery(queryFilters));
lastFetch = new LivePagedListBuilder<>(new RoomFactoryWrapper<>(items),
new PagedList.Config.Builder()

View File

@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "ebbfc42b6562b2363ec0e3005d107d5e",
"identityHash": "276d6f5e56615e86b3634302b7565e95",
"entities": [
{
"tableName": "Feed",
@ -421,67 +421,6 @@
"indices": [],
"foreignKeys": []
},
{
"tableName": "UnreadItemsIds",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `remote_id` TEXT NOT NULL, `account_id` INTEGER NOT NULL, FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "remoteId",
"columnName": "remote_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "accountId",
"columnName": "account_id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_UnreadItemsIds_remote_id",
"unique": false,
"columnNames": [
"remote_id"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_UnreadItemsIds_remote_id` ON `${TABLE_NAME}` (`remote_id`)"
},
{
"name": "index_UnreadItemsIds_account_id",
"unique": false,
"columnNames": [
"account_id"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_UnreadItemsIds_account_id` ON `${TABLE_NAME}` (`account_id`)"
}
],
"foreignKeys": [
{
"table": "Account",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"account_id"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "ReadStarStateChange",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `read_change` INTEGER NOT NULL, `star_change` INTEGER NOT NULL, `account_id` INTEGER NOT NULL, PRIMARY KEY(`id`))",
@ -520,145 +459,6 @@
"indices": [],
"foreignKeys": []
},
{
"tableName": "StarredItem",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `title` TEXT, `description` TEXT, `clean_description` TEXT, `link` TEXT, `image_link` TEXT, `author` TEXT, `pub_date` INTEGER, `content` TEXT, `feed_id` INTEGER NOT NULL, `guid` TEXT, `read_time` REAL NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `read_it_later` INTEGER NOT NULL, `remoteId` TEXT, FOREIGN KEY(`feed_id`) REFERENCES `Feed`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "cleanDescription",
"columnName": "clean_description",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "link",
"columnName": "link",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "imageLink",
"columnName": "image_link",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "author",
"columnName": "author",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "pubDate",
"columnName": "pub_date",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "feedId",
"columnName": "feed_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "guid",
"columnName": "guid",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "readTime",
"columnName": "read_time",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "read",
"columnName": "read",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "starred",
"columnName": "starred",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "readItLater",
"columnName": "read_it_later",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "remoteId",
"columnName": "remoteId",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_StarredItem_feed_id",
"unique": false,
"columnNames": [
"feed_id"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_StarredItem_feed_id` ON `${TABLE_NAME}` (`feed_id`)"
},
{
"name": "index_StarredItem_guid",
"unique": false,
"columnNames": [
"guid"
],
"createSql": "CREATE INDEX IF NOT EXISTS `index_StarredItem_guid` ON `${TABLE_NAME}` (`guid`)"
}
],
"foreignKeys": [
{
"table": "Feed",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"feed_id"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "ItemStateId",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `read` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `remote_id` TEXT NOT NULL, `account_id` INTEGER NOT NULL)",
@ -707,7 +507,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ebbfc42b6562b2363ec0e3005d107d5e')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '276d6f5e56615e86b3634302b7565e95')"
]
}
}

View File

@ -8,8 +8,8 @@ import com.readrops.db.entities.*
import com.readrops.db.entities.account.Account
import dev.matrix.roomigrant.GenerateRoomMigrations
@Database(entities = [Feed::class, Item::class, Folder::class, Account::class, UnreadItemsIds::class,
ReadStarStateChange::class, StarredItem::class, ItemStateId::class], version = 3)
@Database(entities = [Feed::class, Item::class, Folder::class, Account::class,
ReadStarStateChange::class, ItemStateId::class], version = 3)
@TypeConverters(Converters::class)
@GenerateRoomMigrations
abstract class Database : RoomDatabase() {
@ -22,6 +22,4 @@ abstract class Database : RoomDatabase() {
abstract fun accountDao(): AccountDao
abstract fun itemsIdsDao(): ItemsIdsDao
abstract fun starredItemDao(): StarredItemDao
}

View File

@ -1,31 +0,0 @@
package com.readrops.db.dao
import androidx.lifecycle.LiveData
import androidx.paging.DataSource
import androidx.room.Dao
import androidx.room.Query
import androidx.room.RawQuery
import androidx.room.RoomWarnings
import androidx.sqlite.db.SupportSQLiteQuery
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.entities.StarredItem
import com.readrops.db.entities.UnreadItemsIds
import com.readrops.db.pojo.ItemWithFeed
@Dao
interface StarredItemDao : BaseDao<StarredItem> {
@Query("Delete From StarredItem Where feed_id In (Select feed_id From Feed Where account_id = :accountId)")
fun deleteStarredItems(accountId: Int)
@RawQuery(observedEntities = [StarredItem::class, Folder::class, Feed::class, UnreadItemsIds::class])
fun selectAll(query: SupportSQLiteQuery?): DataSource.Factory<Int, ItemWithFeed>
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("Select StarredItem.id, title, StarredItem.description, content, link, pub_date, image_link, author, read, text_color, " +
"background_color, read_time, starred, Feed.name, Feed.id as feedId, siteUrl, Folder.id as folder_id, " +
"Folder.name as folder_name from StarredItem Inner Join Feed On StarredItem.feed_id = Feed.id Left Join Folder on Folder.id = Feed.folder_id Where StarredItem.id = :id")
fun getStarredItemById(id: Int): LiveData<ItemWithFeed>
}

View File

@ -2,17 +2,7 @@ package com.readrops.db.entities
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import com.readrops.db.entities.account.Account
@Entity(foreignKeys = [ForeignKey(entity = Account::class, parentColumns = ["id"],
childColumns = ["account_id"], onDelete = ForeignKey.CASCADE)])
data class UnreadItemsIds(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
@ColumnInfo(name = "remote_id", index = true) val remoteId: String,
@ColumnInfo(name = "account_id", index = true) val accountId: Int,
)
@Entity
data class ReadStarStateChange(

View File

@ -1,33 +0,0 @@
package com.readrops.db.entities
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Ignore
@Entity(foreignKeys = [ForeignKey(entity = Feed::class, parentColumns = ["id"], childColumns = ["feed_id"],
onDelete = ForeignKey.CASCADE)], inheritSuperIndices = true)
class StarredItem() : Item() {
// TODO really hacky, should be replaced by something better
@Ignore
constructor(item: Item) : this() {
id = item.id
title = item.title
description = item.description
cleanDescription = item.cleanDescription
link = item.link
imageLink = item.imageLink
author = item.author
pubDate = item.pubDate
content = item.content
feedId = item.feedId
guid = item.guid
readTime = item.readTime
isRead = item.isRead
isStarred = true // important here for the items query compatibility
isReadItLater = item.isReadItLater
remoteId = item.remoteId
feedRemoteId = item.feedRemoteId
}
}