From 3af122066655082a4027f30229f5acc90ea0cd09 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sun, 4 Aug 2024 18:04:55 +0200 Subject: [PATCH] Rework Feed table columns --- .../java/com/readrops/app/item/ItemScreen.kt | 12 ++--- .../app/repositories/LocalRSSRepository.kt | 2 +- .../com/readrops/app/sync/SyncAnalyzer.kt | 2 +- .../com/readrops/app/timelime/TimelineItem.kt | 1 - .../app/timelime/TimelineItemParts.kt | 10 ++-- .../com/readrops/app/util/CrashActivity.kt | 11 +++- db/schemas/com.readrops.db.Database/4.json | 20 +++---- .../java/com/readrops/db/MigrationsTest.kt | 2 +- db/src/main/java/com/readrops/db/Database.kt | 11 ++++ .../main/java/com/readrops/db/dao/FeedDao.kt | 10 ++-- .../java/com/readrops/db/entities/Feed.kt | 54 ++++++++++++------- .../java/com/readrops/db/pojo/ItemWithFeed.kt | 15 +++--- .../db/queries/FoldersAndFeedsQueryBuilder.kt | 2 +- .../db/queries/ItemSelectionQueryBuilder.kt | 24 +++++++-- .../readrops/db/queries/ItemsQueryBuilder.kt | 3 +- 15 files changed, 109 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/com/readrops/app/item/ItemScreen.kt b/app/src/main/java/com/readrops/app/item/ItemScreen.kt index 2a2d2ac5..d5a33fe8 100644 --- a/app/src/main/java/com/readrops/app/item/ItemScreen.kt +++ b/app/src/main/java/com/readrops/app/item/ItemScreen.kt @@ -130,8 +130,8 @@ class ItemScreen( val itemWithFeed = state.itemWithFeed!! val item = itemWithFeed.item - val accentColor = if (itemWithFeed.bgColor != 0) { - Color(itemWithFeed.bgColor) + val accentColor = if (itemWithFeed.color != 0) { + Color(itemWithFeed.color) } else { primaryColor } @@ -203,8 +203,8 @@ class ItemScreen( if (item.imageLink != null) { BackgroundTitle(itemWithFeed = itemWithFeed) } else { - val tintColor = if (itemWithFeed.bgColor != 0) { - Color(itemWithFeed.bgColor) + val tintColor = if (itemWithFeed.color != 0) { + Color(itemWithFeed.color) } else { MaterialTheme.colorScheme.onBackground } @@ -249,8 +249,8 @@ fun BackgroundTitle( itemWithFeed: ItemWithFeed, ) { val onScrimColor = Color.White.copy(alpha = 0.85f) - val accentColor = if (itemWithFeed.bgColor != 0) { - Color(itemWithFeed.bgColor) + val accentColor = if (itemWithFeed.color != 0) { + Color(itemWithFeed.color) } else { onScrimColor } diff --git a/app/src/main/java/com/readrops/app/repositories/LocalRSSRepository.kt b/app/src/main/java/com/readrops/app/repositories/LocalRSSRepository.kt index 5088e179..032de40f 100644 --- a/app/src/main/java/com/readrops/app/repositories/LocalRSSRepository.kt +++ b/app/src/main/java/com/readrops/app/repositories/LocalRSSRepository.kt @@ -124,7 +124,7 @@ class LocalRSSRepository( try { iconUrl = HtmlParser.getFaviconLink(siteUrl!!, get()).also { feedUrl -> - feedUrl?.let { backgroundColor = FeedColors.getFeedColor(it) } + feedUrl?.let { color = FeedColors.getFeedColor(it) } } } catch (e: Exception) { Log.d("LocalRSSRepository", "insertFeed: ${e.message}") diff --git a/app/src/main/java/com/readrops/app/sync/SyncAnalyzer.kt b/app/src/main/java/com/readrops/app/sync/SyncAnalyzer.kt index 961023dc..d7749ed3 100644 --- a/app/src/main/java/com/readrops/app/sync/SyncAnalyzer.kt +++ b/app/src/main/java/com/readrops/app/sync/SyncAnalyzer.kt @@ -119,7 +119,7 @@ class SyncAnalyzer( text = text, largeIcon = icon, item = item, - color = feed.backgroundColor, + color = feed.color, accountId = account.id ) } diff --git a/app/src/main/java/com/readrops/app/timelime/TimelineItem.kt b/app/src/main/java/com/readrops/app/timelime/TimelineItem.kt index 7d90f4f8..eb8a88e7 100644 --- a/app/src/main/java/com/readrops/app/timelime/TimelineItem.kt +++ b/app/src/main/java/com/readrops/app/timelime/TimelineItem.kt @@ -67,7 +67,6 @@ private val itemWithFeed = ItemWithFeed( ), feedName = "feed name", color = 0, - bgColor = 0, feedId = 0, feedIconUrl = "", websiteUrl = "", diff --git a/app/src/main/java/com/readrops/app/timelime/TimelineItemParts.kt b/app/src/main/java/com/readrops/app/timelime/TimelineItemParts.kt index 56ec2190..2f47adfe 100644 --- a/app/src/main/java/com/readrops/app/timelime/TimelineItemParts.kt +++ b/app/src/main/java/com/readrops/app/timelime/TimelineItemParts.kt @@ -62,7 +62,7 @@ fun RegularTimelineItem( TimelineItemHeader( feedName = itemWithFeed.feedName, feedIconUrl = itemWithFeed.feedIconUrl, - feedColor = itemWithFeed.bgColor, + feedColor = itemWithFeed.color, folderName = itemWithFeed.folder?.name, date = itemWithFeed.item.pubDate!!, duration = itemWithFeed.item.readTime, @@ -80,7 +80,7 @@ fun RegularTimelineItem( TimelineItemBadge( date = itemWithFeed.item.pubDate!!, duration = itemWithFeed.item.readTime, - color = itemWithFeed.bgColor + color = itemWithFeed.color ) } } @@ -111,7 +111,7 @@ fun CompactTimelineItem( TimelineItemHeader( feedName = itemWithFeed.feedName, feedIconUrl = itemWithFeed.feedIconUrl, - feedColor = itemWithFeed.bgColor, + feedColor = itemWithFeed.color, folderName = itemWithFeed.folder?.name, onFavorite = onFavorite, onShare = onShare, @@ -162,7 +162,7 @@ fun LargeTimelineItem( TimelineItemHeader( feedName = itemWithFeed.feedName, feedIconUrl = itemWithFeed.feedIconUrl, - feedColor = itemWithFeed.bgColor, + feedColor = itemWithFeed.color, folderName = itemWithFeed.folder?.name, date = itemWithFeed.item.pubDate!!, duration = itemWithFeed.item.readTime, @@ -176,7 +176,7 @@ fun LargeTimelineItem( TimelineItemBadge( date = itemWithFeed.item.pubDate!!, duration = itemWithFeed.item.readTime, - color = itemWithFeed.bgColor + color = itemWithFeed.color ) ShortSpacer() diff --git a/app/src/main/java/com/readrops/app/util/CrashActivity.kt b/app/src/main/java/com/readrops/app/util/CrashActivity.kt index 65bb8c2d..e81f3d68 100644 --- a/app/src/main/java/com/readrops/app/util/CrashActivity.kt +++ b/app/src/main/java/com/readrops/app/util/CrashActivity.kt @@ -3,6 +3,7 @@ package com.readrops.app.util import android.content.Context import android.graphics.Color import android.os.Bundle +import android.util.Log import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.SystemBarStyle @@ -54,9 +55,17 @@ class CrashActivity : ComponentActivity() { val throwable = intent.getSerializableExtra(THROWABLE_KEY) as Throwable? + val stackTrace = try { + throwable?.stackTraceToString() + + } catch (e: Exception) { + Log.e("CrashActivity", "Unable to get crash exception") + null + } + setContent { ReadropsTheme { - CrashScreen(throwable?.stackTraceToString().orEmpty()) + CrashScreen(stackTrace.orEmpty()) } } } diff --git a/db/schemas/com.readrops.db.Database/4.json b/db/schemas/com.readrops.db.Database/4.json index 316c3f20..5d579ecb 100644 --- a/db/schemas/com.readrops.db.Database/4.json +++ b/db/schemas/com.readrops.db.Database/4.json @@ -2,11 +2,11 @@ "formatVersion": 1, "database": { "version": 4, - "identityHash": "6a1403979efe044075bf2f30a47a9e08", + "identityHash": "1cd84a05829477201803f5f27275fe29", "entities": [ { "tableName": "Feed", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `description` TEXT, `url` TEXT, `siteUrl` TEXT, `lastUpdated` TEXT, `text_color` INTEGER NOT NULL, `background_color` INTEGER NOT NULL, `icon_url` TEXT, `etag` TEXT, `last_modified` TEXT, `folder_id` INTEGER, `remoteId` TEXT, `account_id` INTEGER NOT NULL, `notification_enabled` INTEGER NOT NULL DEFAULT 1, FOREIGN KEY(`folder_id`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL , FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `description` TEXT, `url` TEXT, `siteUrl` TEXT, `last_updated` TEXT, `color` INTEGER NOT NULL, `icon_url` TEXT, `etag` TEXT, `last_modified` TEXT, `folder_id` INTEGER, `remote_id` TEXT, `account_id` INTEGER NOT NULL, `notification_enabled` INTEGER NOT NULL DEFAULT 1, FOREIGN KEY(`folder_id`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL , FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", "fields": [ { "fieldPath": "id", @@ -40,19 +40,13 @@ }, { "fieldPath": "lastUpdated", - "columnName": "lastUpdated", + "columnName": "last_updated", "affinity": "TEXT", "notNull": false }, { - "fieldPath": "textColor", - "columnName": "text_color", - "affinity": "INTEGER", - "notNull": true - }, - { - "fieldPath": "backgroundColor", - "columnName": "background_color", + "fieldPath": "color", + "columnName": "color", "affinity": "INTEGER", "notNull": true }, @@ -82,7 +76,7 @@ }, { "fieldPath": "remoteId", - "columnName": "remoteId", + "columnName": "remote_id", "affinity": "TEXT", "notNull": false }, @@ -526,7 +520,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, '6a1403979efe044075bf2f30a47a9e08')" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1cd84a05829477201803f5f27275fe29')" ] } } \ No newline at end of file diff --git a/db/src/androidTest/java/com/readrops/db/MigrationsTest.kt b/db/src/androidTest/java/com/readrops/db/MigrationsTest.kt index 77305c92..f165f641 100644 --- a/db/src/androidTest/java/com/readrops/db/MigrationsTest.kt +++ b/db/src/androidTest/java/com/readrops/db/MigrationsTest.kt @@ -3,7 +3,7 @@ package com.readrops.db import androidx.room.testing.MigrationTestHelper import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import junit.framework.Assert.assertEquals +import junit.framework.TestCase.assertEquals import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith diff --git a/db/src/main/java/com/readrops/db/Database.kt b/db/src/main/java/com/readrops/db/Database.kt index 847346a2..426a984e 100644 --- a/db/src/main/java/com/readrops/db/Database.kt +++ b/db/src/main/java/com/readrops/db/Database.kt @@ -83,6 +83,17 @@ object MigrationFrom3To4 : Migration(3, 4) { db.execSQL("DROP TABLE IF EXISTS `Item`") db.execSQL("ALTER TABLE `_new_Item` RENAME TO `Item`") db.execSQL("CREATE INDEX IF NOT EXISTS `index_Item_feed_id` ON `Item` (`feed_id`)") + + // remove text_color + // rename background_color to color + // rename remoteId to remote_id + // rename lastUpdated to last_updated + db.execSQL("CREATE TABLE IF NOT EXISTS `_new_Feed` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `description` TEXT, `url` TEXT, `siteUrl` TEXT, `last_updated` TEXT, `color` INTEGER NOT NULL, `icon_url` TEXT, `etag` TEXT, `last_modified` TEXT, `folder_id` INTEGER, `remote_id` TEXT, `account_id` INTEGER NOT NULL, `notification_enabled` INTEGER NOT NULL DEFAULT 1, FOREIGN KEY(`folder_id`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL , FOREIGN KEY(`account_id`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )") + db.execSQL("INSERT INTO `_new_Feed` (`id`, `name`, `description`, `url`, `siteUrl`, `last_updated`, `color`, `icon_url`, `etag`, `last_modified`, `folder_id`, `remote_id`, `account_id`, `notification_enabled`) SELECT `id`, `name`, `description`, `url`, `siteUrl`, `lastUpdated`, `background_color`, `icon_url`, `etag`, `last_modified`, `folder_id`, `remoteId`, `account_id`, `notification_enabled` FROM `Feed`") + db.execSQL("DROP TABLE IF EXISTS `Feed`") + db.execSQL("ALTER TABLE `_new_Feed` RENAME TO `Feed`") + db.execSQL("CREATE INDEX IF NOT EXISTS `index_Feed_folder_id` ON `Feed` (`folder_id`)") + db.execSQL("CREATE INDEX IF NOT EXISTS `index_Feed_account_id` ON `Feed` (`account_id`)") } } diff --git a/db/src/main/java/com/readrops/db/dao/FeedDao.kt b/db/src/main/java/com/readrops/db/dao/FeedDao.kt index 462ea265..8f713736 100644 --- a/db/src/main/java/com/readrops/db/dao/FeedDao.kt +++ b/db/src/main/java/com/readrops/db/dao/FeedDao.kt @@ -39,22 +39,22 @@ abstract class FeedDao : BaseDao { @Query("Select count(*) from Feed Where account_id = :accountId") abstract suspend fun selectFeedCount(accountId: Int): Int - @Query("Select remoteId From Feed Where account_id = :accountId") + @Query("Select remote_id From Feed Where account_id = :accountId") abstract suspend fun selectFeedRemoteIds(accountId: Int): MutableList @Query("Select id From Folder Where remoteId = :remoteId And account_id = :accountId") abstract suspend fun selectRemoteFolderLocalId(remoteId: String, accountId: Int): Int - @Query("Select id From Feed Where remoteId = :remoteId And account_id = :accountId") + @Query("Select id From Feed Where remote_id = :remoteId And account_id = :accountId") abstract suspend fun selectRemoteFeedLocalId(remoteId: String, accountId: Int): Int - @Query("Update Feed set name = :name, folder_id = :folderId Where remoteId = :remoteFeedId And account_id = :accountId") + @Query("Update Feed set name = :name, folder_id = :folderId Where remote_id = :remoteFeedId And account_id = :accountId") abstract fun updateFeedNameAndFolder(remoteFeedId: String, accountId: Int, name: String, folderId: Int?) - @Query("Delete from Feed Where remoteId in (:ids) And account_id = :accountId") + @Query("Delete from Feed Where remote_id in (:ids) And account_id = :accountId") abstract fun deleteByIds(ids: List, accountId: Int) - @Query("Update Feed set background_color = :color Where id = :feedId") + @Query("Update Feed set color = :color Where id = :feedId") abstract fun updateFeedColor(feedId: Int, color: Int) @Query("""Select Feed.*, Folder.name as folder_name From Feed Left Join Folder On Feed.folder_id = Folder.id diff --git a/db/src/main/java/com/readrops/db/entities/Feed.kt b/db/src/main/java/com/readrops/db/entities/Feed.kt index 7ac359cb..2962e53d 100644 --- a/db/src/main/java/com/readrops/db/entities/Feed.kt +++ b/db/src/main/java/com/readrops/db/entities/Feed.kt @@ -8,25 +8,39 @@ import androidx.room.Ignore import androidx.room.PrimaryKey import com.readrops.db.entities.account.Account -@Entity(foreignKeys = [ForeignKey(entity = Folder::class, parentColumns = ["id"], childColumns = ["folder_id"], - onDelete = ForeignKey.SET_NULL), ForeignKey(entity = Account::class, parentColumns = ["id"], - childColumns = ["account_id"], onDelete = ForeignKey.CASCADE)]) +@Entity( + foreignKeys = [ + ForeignKey( + entity = Folder::class, + parentColumns = ["id"], + childColumns = ["folder_id"], + onDelete = ForeignKey.SET_NULL + ), ForeignKey( + entity = Account::class, + parentColumns = ["id"], + childColumns = ["account_id"], + onDelete = ForeignKey.CASCADE + ) + ] +) data class Feed( - @PrimaryKey(autoGenerate = true) var id: Int = 0, - var name: String? = null, - var description: String? = null, - var url: String? = null, - var siteUrl: String? = null, - var lastUpdated: String? = null, - @ColumnInfo(name = "text_color") @ColorInt var textColor: Int = 0, - @ColumnInfo(name = "background_color") @ColorInt var backgroundColor: Int = 0, - @ColumnInfo(name = "icon_url") var iconUrl: String? = null, - var etag: String? = null, - @ColumnInfo(name = "last_modified") var lastModified: String? = null, - @ColumnInfo(name = "folder_id", index = true) var folderId: Int? = null, - var remoteId: String? = null, - @ColumnInfo(name = "account_id", index = true) var accountId: Int = 0, - @ColumnInfo(name = "notification_enabled", defaultValue = "1") var isNotificationEnabled: Boolean = true, - @Ignore var unreadCount: Int = 0, - @Ignore var remoteFolderId: String? = null, + @PrimaryKey(autoGenerate = true) var id: Int = 0, + var name: String? = null, + var description: String? = null, + var url: String? = null, + var siteUrl: String? = null, + @ColumnInfo("last_updated") var lastUpdated: String? = null, + @ColorInt var color: Int = 0, + @ColumnInfo(name = "icon_url") var iconUrl: String? = null, + var etag: String? = null, + @ColumnInfo(name = "last_modified") var lastModified: String? = null, + @ColumnInfo(name = "folder_id", index = true) var folderId: Int? = null, + @ColumnInfo("remote_id") var remoteId: String? = null, + @ColumnInfo(name = "account_id", index = true) var accountId: Int = 0, + @ColumnInfo( + name = "notification_enabled", + defaultValue = "1" + ) var isNotificationEnabled: Boolean = true, + @Ignore var unreadCount: Int = 0, + @Ignore var remoteFolderId: String? = null, ) \ No newline at end of file diff --git a/db/src/main/java/com/readrops/db/pojo/ItemWithFeed.kt b/db/src/main/java/com/readrops/db/pojo/ItemWithFeed.kt index 56e19eef..abaf479b 100644 --- a/db/src/main/java/com/readrops/db/pojo/ItemWithFeed.kt +++ b/db/src/main/java/com/readrops/db/pojo/ItemWithFeed.kt @@ -7,12 +7,11 @@ import com.readrops.db.entities.Folder import com.readrops.db.entities.Item data class ItemWithFeed( - @Embedded val item: Item, - @ColumnInfo(name = "name") val feedName: String, - @ColumnInfo(name = "feedId") val feedId: Int, - @ColumnInfo(name = "text_color") @ColorInt val color: Int, - @ColumnInfo(name = "background_color") @ColorInt val bgColor: Int, - @ColumnInfo(name = "icon_url") val feedIconUrl: String?, - @ColumnInfo(name = "siteUrl") val websiteUrl: String?, - @Embedded(prefix = "folder_") val folder: Folder?, + @Embedded val item: Item, + @ColumnInfo(name = "name") val feedName: String, + @ColumnInfo(name = "feedId") val feedId: Int, + @ColumnInfo(name = "color") @ColorInt val color: Int, + @ColumnInfo(name = "icon_url") val feedIconUrl: String?, + @ColumnInfo(name = "siteUrl") val websiteUrl: String?, + @Embedded(prefix = "folder_") val folder: Folder? ) \ No newline at end of file diff --git a/db/src/main/java/com/readrops/db/queries/FoldersAndFeedsQueryBuilder.kt b/db/src/main/java/com/readrops/db/queries/FoldersAndFeedsQueryBuilder.kt index 53d63e20..d5a65f82 100644 --- a/db/src/main/java/com/readrops/db/queries/FoldersAndFeedsQueryBuilder.kt +++ b/db/src/main/java/com/readrops/db/queries/FoldersAndFeedsQueryBuilder.kt @@ -13,7 +13,7 @@ object FoldersAndFeedsQueryBuilder { "Feed.url As feedUrl", "Feed.siteUrl As feedSiteUrl", "Feed.description as feedDescription", - "Feed.remoteId as feedRemoteId", + "Feed.remote_id as feedRemoteId", "Folder.id As folderId", "Folder.name As folderName", "Feed.account_id as accountId", diff --git a/db/src/main/java/com/readrops/db/queries/ItemSelectionQueryBuilder.kt b/db/src/main/java/com/readrops/db/queries/ItemSelectionQueryBuilder.kt index f8ef2e57..bdb47c56 100644 --- a/db/src/main/java/com/readrops/db/queries/ItemSelectionQueryBuilder.kt +++ b/db/src/main/java/com/readrops/db/queries/ItemSelectionQueryBuilder.kt @@ -6,10 +6,24 @@ import androidx.sqlite.db.SupportSQLiteQueryBuilder object ItemSelectionQueryBuilder { private val COLUMNS = arrayOf( - "Item.id", "Item.remoteId", "title", "Item.description", "content", - "link", "pub_date", "image_link", "author", "Item.read", "text_color", "icon_url", - "background_color", "read_time", "Feed.name", "Feed.id as feedId", "siteUrl", - "Folder.id as folder_id", "Folder.name as folder_name" + "Item.id", + "Item.remote_id", + "title", + "Item.description", + "content", + "link", + "pub_date", + "image_link", + "author", + "Item.read", + "icon_url", + "color", + "read_time", + "Feed.name", + "Feed.id as feedId", + "siteUrl", + "Folder.id as folder_id", + "Folder.name as folder_name" ) private val SEPARATE_STATE_COLUMNS = @@ -19,7 +33,7 @@ object ItemSelectionQueryBuilder { "Item Inner Join Feed On Item.feed_id = Feed.id Left Join Folder on Folder.id = Feed.folder_id" private const val SEPARATE_STATE_JOIN = - " Left Join ItemState On ItemState.remote_id = Item.remoteId" + " Left Join ItemState On ItemState.remote_id = Item.remote_id" /** * @param separateState Indicates if item state must be retrieved from ItemState table diff --git a/db/src/main/java/com/readrops/db/queries/ItemsQueryBuilder.kt b/db/src/main/java/com/readrops/db/queries/ItemsQueryBuilder.kt index 7510ab2c..cfd61dd6 100644 --- a/db/src/main/java/com/readrops/db/queries/ItemsQueryBuilder.kt +++ b/db/src/main/java/com/readrops/db/queries/ItemsQueryBuilder.kt @@ -17,8 +17,7 @@ object ItemsQueryBuilder { "pub_date", "link", "Feed.name", - "text_color", - "background_color", + "color", "icon_url", "read_time", "Feed.id as feedId",