From a658d427e0fa293b2f5b291cd99ee69a2c19c1a0 Mon Sep 17 00:00:00 2001 From: Marco Gomiero Date: Mon, 3 Jun 2024 17:23:46 -0400 Subject: [PATCH] Migrate all id from Int to String --- .../android/home/components/HomeAppBar.kt | 6 +- .../feedflow/core/model/CategoriesState.kt | 2 +- .../prof18/feedflow/core/model/CategoryId.kt | 2 +- .../prof18/feedflow/core/model/FeedItem.kt | 2 +- .../prof18/feedflow/core/model/FeedItemId.kt | 2 +- .../feedflow/core/model/FeedItemUrlInfo.kt | 2 +- .../prof18/feedflow/core/model/FeedSource.kt | 2 +- .../feedflow/core/model/FeedSourceCategory.kt | 2 +- .../feedflow/core/model/ParsedFeedSource.kt | 2 + .../feedflow/database/DatabaseHelper.kt | 31 ++--- .../com/prof18/feedflow/db/FeedItem.sq | 4 +- .../com/prof18/feedflow/db/FeedSearch.sq | 2 +- .../com/prof18/feedflow/db/FeedSource.sq | 4 +- .../prof18/feedflow/db/FeedSourceCategory.sq | 6 +- .../com/prof18/feedflow/migrations/6.sqm | 125 ++++++++++++++++++ .../com/prof18/feedflow/schema/7.db | Bin 0 -> 57344 bytes .../AddFeed/AddFeedScreenContent.swift | 2 +- .../feed/manager/FeedManagerRepository.kt | 4 +- .../feed/retriever/FeedRetrieverRepository.kt | 5 +- .../shared/domain/mappers/RssChannelMapper.kt | 2 +- .../shared/presentation/AddFeedViewModel.kt | 5 +- .../shared/presentation/HomeViewModel.kt | 2 +- .../presentation/preview/PreviewItems.kt | 78 +++++------ 23 files changed, 208 insertions(+), 84 deletions(-) create mode 100644 database/src/commonMain/sqldelight/com/prof18/feedflow/migrations/6.sqm create mode 100644 database/src/commonMain/sqldelight/com/prof18/feedflow/schema/7.db diff --git a/androidApp/src/main/kotlin/com/prof18/feedflow/android/home/components/HomeAppBar.kt b/androidApp/src/main/kotlin/com/prof18/feedflow/android/home/components/HomeAppBar.kt index f5cbb8bc..bbbf2121 100644 --- a/androidApp/src/main/kotlin/com/prof18/feedflow/android/home/components/HomeAppBar.kt +++ b/androidApp/src/main/kotlin/com/prof18/feedflow/android/home/components/HomeAppBar.kt @@ -6,8 +6,8 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.MenuOpen import androidx.compose.material.icons.filled.Menu -import androidx.compose.material.icons.filled.MenuOpen import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.Search import androidx.compose.material3.Icon @@ -148,7 +148,7 @@ private fun DrawerIcon(onDrawerMenuClick: () -> Unit, isDrawerOpen: Boolean) { ) { Icon( imageVector = if (isDrawerOpen) { - Icons.Default.MenuOpen + Icons.AutoMirrored.Filled.MenuOpen } else { Icons.Default.Menu }, @@ -164,7 +164,7 @@ private fun HomeAppBarPreview() { HomeAppBar( currentFeedFilter = FeedFilter.Source( feedSource = FeedSource( - id = 0, + id = "0", url = "", title = "A very very very very very very long title", category = null, diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoriesState.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoriesState.kt index c05201e3..d6018e11 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoriesState.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoriesState.kt @@ -7,7 +7,7 @@ data class CategoriesState( ) { data class CategoryItem( - val id: Long, + val id: String, val name: String?, val isSelected: Boolean, val onClick: (CategoryId) -> Unit, diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoryId.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoryId.kt index 3523a433..743eae84 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoryId.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/CategoryId.kt @@ -1,5 +1,5 @@ package com.prof18.feedflow.core.model data class CategoryId( - val value: Long, + val value: String, ) diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItem.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItem.kt index 2e78c0f0..42912907 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItem.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItem.kt @@ -4,7 +4,7 @@ import androidx.compose.runtime.Immutable @Immutable data class FeedItem( - val id: Int, + val id: String, val url: String, val title: String?, val subtitle: String?, diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemId.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemId.kt index 00c62dd8..acdf0d3d 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemId.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemId.kt @@ -1,5 +1,5 @@ package com.prof18.feedflow.core.model data class FeedItemId( - val id: Int, + val id: String, ) diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemUrlInfo.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemUrlInfo.kt index dbff3aba..3e9949d2 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemUrlInfo.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedItemUrlInfo.kt @@ -1,7 +1,7 @@ package com.prof18.feedflow.core.model data class FeedItemUrlInfo( - val id: Int, + val id: String, val url: String, val title: String?, val openOnlyOnBrowser: Boolean = false, diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSource.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSource.kt index 76521c1b..1e1697f4 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSource.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSource.kt @@ -1,7 +1,7 @@ package com.prof18.feedflow.core.model data class FeedSource( - val id: Int, + val id: String, val url: String, val title: String, val category: FeedSourceCategory?, diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSourceCategory.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSourceCategory.kt index a3c5d7a0..cbd1d377 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSourceCategory.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/FeedSourceCategory.kt @@ -1,6 +1,6 @@ package com.prof18.feedflow.core.model data class FeedSourceCategory( - val id: Long, + val id: String, val title: String, ) diff --git a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/ParsedFeedSource.kt b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/ParsedFeedSource.kt index 1a8795d8..47bbfc48 100644 --- a/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/ParsedFeedSource.kt +++ b/core/src/commonMain/kotlin/com/prof18/feedflow/core/model/ParsedFeedSource.kt @@ -1,6 +1,7 @@ package com.prof18.feedflow.core.model data class ParsedFeedSource( + val id: String, val url: String, val title: String, val categoryName: CategoryName?, @@ -29,6 +30,7 @@ data class ParsedFeedSource( return null } return ParsedFeedSource( + id = url.hashCode().toString(), url = url!!, title = title!!, categoryName = if (category != null) { diff --git a/database/src/commonMain/kotlin/com/prof18/feedflow/database/DatabaseHelper.kt b/database/src/commonMain/kotlin/com/prof18/feedflow/database/DatabaseHelper.kt index cdedd181..d0a8cfe4 100644 --- a/database/src/commonMain/kotlin/com/prof18/feedflow/database/DatabaseHelper.kt +++ b/database/src/commonMain/kotlin/com/prof18/feedflow/database/DatabaseHelper.kt @@ -2,7 +2,6 @@ package com.prof18.feedflow.database import app.cash.sqldelight.Transacter import app.cash.sqldelight.TransactionWithoutReturn -import app.cash.sqldelight.adapter.primitive.IntColumnAdapter import app.cash.sqldelight.coroutines.asFlow import app.cash.sqldelight.coroutines.mapToList import app.cash.sqldelight.coroutines.mapToOneOrDefault @@ -16,8 +15,6 @@ import com.prof18.feedflow.core.model.FeedSource import com.prof18.feedflow.core.model.FeedSourceCategory import com.prof18.feedflow.core.model.ParsedFeedSource import com.prof18.feedflow.db.FeedFlowDB -import com.prof18.feedflow.db.Feed_item -import com.prof18.feedflow.db.Feed_source import com.prof18.feedflow.db.Search import com.prof18.feedflow.db.SelectFeedUrls import com.prof18.feedflow.db.SelectFeeds @@ -34,16 +31,7 @@ class DatabaseHelper( private val backgroundDispatcher: CoroutineDispatcher, private val logger: Logger, ) { - private val dbRef: FeedFlowDB = FeedFlowDB( - sqlDriver, - feed_itemAdapter = Feed_item.Adapter( - url_hashAdapter = IntColumnAdapter, - feed_source_idAdapter = IntColumnAdapter, - ), - feed_sourceAdapter = Feed_source.Adapter( - url_hashAdapter = IntColumnAdapter, - ), - ) + private val dbRef: FeedFlowDB = FeedFlowDB(sqlDriver) suspend fun getFeedSources(): List = withContext(backgroundDispatcher) { dbRef.feedSourceQueries @@ -86,7 +74,10 @@ class DatabaseHelper( suspend fun insertCategories(categories: List) = dbRef.transactionWithContext(backgroundDispatcher) { categories.forEach { category -> - dbRef.feedSourceCategoryQueries.insertFeedSourceCategory(category.name) + dbRef.feedSourceCategoryQueries.insertFeedSourceCategory( + id = category.name.hashCode().toString(), + title = category.name, + ) } } @@ -95,7 +86,7 @@ class DatabaseHelper( feedSource.forEach { feedSource -> if (feedSource.categoryName != null) { dbRef.feedSourceQueries.insertFeedSource( - url_hash = feedSource.hashCode(), + url_hash = feedSource.hashCode().toString(), url = feedSource.url, title = feedSource.title, title_ = feedSource.categoryName?.name.toString(), @@ -103,7 +94,7 @@ class DatabaseHelper( ) } else { dbRef.feedSourceQueries.insertFeedSourceWithNoCategory( - url_hash = feedSource.hashCode(), + url_hash = feedSource.id, url = feedSource.url, title = feedSource.title, logo_url = feedSource.logoUrl, @@ -226,7 +217,7 @@ class DatabaseHelper( .mapToOneOrDefault(0, backgroundDispatcher) .flowOn(backgroundDispatcher) - suspend fun deleteCategory(id: Long) = + suspend fun deleteCategory(id: String) = dbRef.transactionWithContext(backgroundDispatcher) { dbRef.feedSourceQueries.resetCategory(categoryId = id) dbRef.feedSourceCategoryQueries.delete(id = id) @@ -240,7 +231,7 @@ class DatabaseHelper( ) } - suspend fun updateFeedSourceName(feedSourceId: Int, newName: String) = + suspend fun updateFeedSourceName(feedSourceId: String, newName: String) = dbRef.transactionWithContext(backgroundDispatcher) { dbRef.feedSourceQueries.updateFeedSourceTitle( title = newName, @@ -267,7 +258,7 @@ class DatabaseHelper( } } - private fun FeedFilter.getFeedSourceId(): Int? { + private fun FeedFilter.getFeedSourceId(): String? { return when (this) { is FeedFilter.Source -> feedSource.id @@ -279,7 +270,7 @@ class DatabaseHelper( } } - private fun FeedFilter.getCategoryId(): Long? { + private fun FeedFilter.getCategoryId(): String? { return when (this) { is FeedFilter.Category -> feedCategory.id diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedItem.sq b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedItem.sq index d131be3e..0e7f1e08 100644 --- a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedItem.sq +++ b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedItem.sq @@ -2,13 +2,13 @@ import kotlin.Boolean; import kotlin.Int; CREATE TABLE feed_item ( - url_hash INTEGER AS Int NOT NULL PRIMARY KEY, + url_hash TEXT NOT NULL PRIMARY KEY, -- New 'url_hash' as TEXT url TEXT NOT NULL, title TEXT, subtitle TEXT, content TEXT, image_url TEXT, - feed_source_id INTEGER AS Int NOT NULL, + feed_source_id TEXT NOT NULL, -- Updated 'feed_source_id' to TEXT is_read INTEGER AS Boolean NOT NULL DEFAULT 0, is_bookmarked INTEGER AS Boolean NOT NULL DEFAULT 0, pub_date INTEGER, diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSearch.sq b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSearch.sq index ba67cb26..935259d6 100644 --- a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSearch.sq +++ b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSearch.sq @@ -1,7 +1,7 @@ import kotlin.Int; CREATE VIRTUAL TABLE IF NOT EXISTS feed_search USING FTS4( - url_hash INTEGER AS Int NOT NULL PRIMARY KEY, + url_hash TEXT NOT NULL PRIMARY KEY, title TEXT, subtitle TEXT, tokenize="unicode61" diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSource.sq b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSource.sq index 04df37d5..1ac335bb 100644 --- a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSource.sq +++ b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSource.sq @@ -1,10 +1,10 @@ import kotlin.Int; CREATE TABLE feed_source ( - url_hash INTEGER AS Int NOT NULL PRIMARY KEY, + url_hash TEXT NOT NULL PRIMARY KEY, url TEXT NOT NULL, title TEXT NOT NULL, - category_id INTEGER, + category_id TEXT, last_sync_timestamp INTEGER, logo_url TEXT ); diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSourceCategory.sq b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSourceCategory.sq index fe4d60e6..96e1eae8 100644 --- a/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSourceCategory.sq +++ b/database/src/commonMain/sqldelight/com/prof18/feedflow/db/FeedSourceCategory.sq @@ -1,11 +1,11 @@ CREATE TABLE feed_source_category ( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + id TEXT NOT NULL PRIMARY KEY, title TEXT NOT NULL UNIQUE ); insertFeedSourceCategory: -INSERT OR IGNORE INTO feed_source_category(title) -VALUES (?); +INSERT OR IGNORE INTO feed_source_category(id, title) +VALUES (?,?); getCategoryByName: SELECT * FROM feed_source_category WHERE title = ?; diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/migrations/6.sqm b/database/src/commonMain/sqldelight/com/prof18/feedflow/migrations/6.sqm new file mode 100644 index 00000000..0c27d537 --- /dev/null +++ b/database/src/commonMain/sqldelight/com/prof18/feedflow/migrations/6.sqm @@ -0,0 +1,125 @@ +-------- FEED SOURCE CATEGORY -------- +-- Migration of category to change 'id' to a string type (without autoincrement) +CREATE TABLE new_feed_source_category ( + id TEXT NOT NULL PRIMARY KEY, + title TEXT NOT NULL UNIQUE +); + +-- Copy existing data +INSERT INTO new_feed_source_category (id, title) +SELECT + CAST(id AS TEXT), + title +FROM feed_source_category; + +-- Drop old table +DROP TABLE feed_source_category; + +-- Rename new table to original name +ALTER TABLE new_feed_source_category RENAME TO feed_source_category; + +-------- FEED SOURCE -------- +-- Drop existing triggers (as they reference the old table structure) +DROP TRIGGER IF EXISTS populate_feed_search; +DROP TRIGGER IF EXISTS delete_feed_search; + +-- Migration to change 'url_hash' to a string type in 'feed_source' +CREATE TABLE new_feed_source ( + url_hash TEXT NOT NULL PRIMARY KEY, + url TEXT NOT NULL, + title TEXT NOT NULL, + category_id TEXT, -- Assuming 'category_id' is now TEXT from previous migration + last_sync_timestamp INTEGER, + logo_url TEXT +); + +-- Copy existing data, converting url_hash to TEXT +INSERT INTO new_feed_source (url_hash, url, title, category_id, last_sync_timestamp, logo_url) +SELECT + CAST(url_hash AS TEXT), + url, + title, + CAST(category_id AS TEXT), + last_sync_timestamp, + logo_url +FROM feed_source; + +-- Drop old table +DROP TABLE feed_source; + +-- Rename new table to original name +ALTER TABLE new_feed_source RENAME TO feed_source; + +-------- FEED ITEM -------- +-- Migration to change 'url_hash' to a string type +CREATE TABLE new_feed_item ( + url_hash TEXT NOT NULL PRIMARY KEY, -- New 'url_hash' as TEXT + url TEXT NOT NULL, + title TEXT, + subtitle TEXT, + content TEXT, + image_url TEXT, + feed_source_id TEXT NOT NULL, -- Updated 'feed_source_id' to TEXT + is_read INTEGER AS Boolean NOT NULL DEFAULT 0, + is_bookmarked INTEGER AS Boolean NOT NULL DEFAULT 0, + pub_date INTEGER, + comments_url TEXT +); + +-- Copy existing data, converting url_hash to TEXT +INSERT INTO new_feed_item (url_hash, url, title, subtitle, content, image_url, feed_source_id, is_read, is_bookmarked, pub_date, comments_url) +SELECT + CAST(url_hash AS TEXT), -- Directly convert url_hash to strings (no NULL check needed) + url, + title, + subtitle, + content, + image_url, + CAST(feed_source_id AS TEXT), -- Convert feed_source_id to TEXT + is_read, + is_bookmarked, + pub_date, + comments_url +FROM feed_item; + +-- Drop old table +DROP TABLE feed_item; + +-- Rename new table to original name +ALTER TABLE new_feed_item RENAME TO feed_item; + + +-------- FEED SEARCH -------- +-- Version 1.3 +-- Migration to change 'url_hash' to a string type in 'feed_search' and update triggers + +DROP TABLE IF EXISTS feed_search; + +-- Recreate the FTS4 table with TEXT url_hash and a temporary name +CREATE VIRTUAL TABLE IF NOT EXISTS feed_search USING FTS4( + url_hash TEXT NOT NULL PRIMARY KEY, + title TEXT, + subtitle TEXT, + tokenize="unicode61" +); + +-- Populate the new table (converting url_hash to TEXT) +INSERT INTO feed_search (url_hash, title, subtitle) +SELECT + url_hash, + title, + subtitle +FROM feed_item; + +-- Recreate triggers with updated references +CREATE TRIGGER populate_feed_search +AFTER INSERT ON feed_item +BEGIN + INSERT OR IGNORE INTO feed_search(url_hash, title, subtitle) VALUES (new.url_hash, new.title, new.subtitle); +END; + +CREATE TRIGGER delete_feed_search +BEFORE DELETE ON feed_item +BEGIN + DELETE FROM feed_search WHERE url_hash = old.url_hash; +END; diff --git a/database/src/commonMain/sqldelight/com/prof18/feedflow/schema/7.db b/database/src/commonMain/sqldelight/com/prof18/feedflow/schema/7.db new file mode 100644 index 0000000000000000000000000000000000000000..8d1bd36a3f9b6b72e88613d226b63bee5540b78c GIT binary patch literal 57344 zcmeI(+i%-c9Ki8pmn3s9tHeVd3hL1&mPAUYWm|bclSnr=L}V$X$;JedabvHu>cqiz zx(%MPNj&hxzr!EEKfpi06Yo4B9yz|HNz;__YJDxGJw876`JKT1Ll$5|009ILNTeb-p1 z-7}92%bjadn6t9H?&y?K*)~s1J85{;GTuzn64CXwL)+;ePxEY3KQTSc92#d1Eate5 z|~+}X)a zK0Z%nU=Drn%voWca-mFEq*M;uzN}*+m~dE3iYw8$=q<$1cZR-&Eg3;u05* zi&FpI*tNA+y7#J76{UX7w|v_SllQ&xVYFA7JXG?<+qVnvYG)&xi6{=_S+mpa)m!ld znK>?c2hDav>~#+wmK7nlq+-!kzwV0mzWnrBt+`nfmJ5Rj3suAYB(9k(-#Ipia)>{= zH6B`h$1p#s-BK!(J2wXMRtyzg2^N2Y6-wkb!)Oi*D`j+jBh*l9L`sk>NG*;V)U zJF0l1wp2O)_uFE6t~}Iewv!`!o&BfLv1l0)&p%h?dDGTD5{_-$O?E$3)b^8!R>*Je z$Uw(&pd)8Aw)M+}dR|$jzSotlXtod3PWQZ6lOwWBqa8F$u37uDQJ0edt0MHTiiEu) zp4D4D^+1$|=Id!Ysv_8niw4PQ@u-EH*Q5FMVrB$6W4CW=ec8?<$9)_1%6wif>6UP{ zJ+Fj_#*&;~mmWo@L#@|te$`WzN+X{uezSA&5;7l{cK^I!3XRm8pKmY**5I_I{1Q0*~ z0R#|0ApHWo|4)A((?SFgKmY**5I_I{1Q0*~0R(ve&lo@e0R#|0009ILKmY**5I`XP z0=)lEe;?CA1Q0*~0R#|0009ILKmY**c>ZS$Ab#n1$h2Xe;?CA1Q0*~ z0R#|0009ILKmY**`2T;#00IagfB*srAb{00IagfB*sr iAb Void - let deleteCategory: (Int64) -> Void + let deleteCategory: (String) -> Void let addNewCategory: (CategoryName) -> Void let addFeed: () -> Void diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/manager/FeedManagerRepository.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/manager/FeedManagerRepository.kt index e097f8c7..6efa2b95 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/manager/FeedManagerRepository.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/manager/FeedManagerRepository.kt @@ -126,11 +126,11 @@ internal class FeedManagerRepository( } } - suspend fun deleteCategory(categoryId: Long) { + suspend fun deleteCategory(categoryId: String) { databaseHelper.deleteCategory(categoryId) } - suspend fun updateFeedSourceName(feedSourceId: Int, newName: String) { + suspend fun updateFeedSourceName(feedSourceId: String, newName: String) { databaseHelper.updateFeedSourceName(feedSourceId, newName) } } diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/retriever/FeedRetrieverRepository.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/retriever/FeedRetrieverRepository.kt index 1070d8cb..d220f002 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/retriever/FeedRetrieverRepository.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/feed/retriever/FeedRetrieverRepository.kt @@ -228,6 +228,7 @@ internal class FeedRetrieverRepository( val logoUrl = feedSourceLogoRetriever.getFeedSourceLogoUrl(rssChannel) val parsedFeedSource = ParsedFeedSource( + id = urlToSave.hashCode().toString(), url = urlToSave, title = title, categoryName = category?.title?.let { @@ -250,13 +251,13 @@ internal class FeedRetrieverRepository( val parsedFeedSource = feedFound.parsedFeedSource val currentTimestamp = dateFormatter.currentTimeMillis() val feedSource = FeedSource( - id = parsedFeedSource.hashCode(), + id = parsedFeedSource.hashCode().toString(), url = parsedFeedSource.url, title = parsedFeedSource.title, lastSyncTimestamp = currentTimestamp, category = parsedFeedSource.categoryName?.let { categoryName -> FeedSourceCategory( - id = 2, + id = categoryName.name.hashCode().toString(), title = categoryName.name, ) }, diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/mappers/RssChannelMapper.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/mappers/RssChannelMapper.kt index c5cd790d..e67f45f4 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/mappers/RssChannelMapper.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/domain/mappers/RssChannelMapper.kt @@ -37,7 +37,7 @@ internal class RssChannelMapper( null } else { FeedItem( - id = url.hashCode(), + id = url.hashCode().toString(), url = url, title = title, subtitle = rssItem.description?.let { description -> diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/AddFeedViewModel.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/AddFeedViewModel.kt index 504f3ddd..75a16422 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/AddFeedViewModel.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/AddFeedViewModel.kt @@ -87,7 +87,7 @@ class AddFeedViewModel internal constructor( } } - fun deleteCategory(categoryId: Long) { + fun deleteCategory(categoryId: String) { scope.launch { feedManagerRepository.deleteCategory(categoryId) } @@ -164,6 +164,7 @@ class AddFeedViewModel internal constructor( ) private companion object { - private const val EMPTY_CATEGORY_ID = Long.MAX_VALUE + // To maintain backward compatibility + private const val EMPTY_CATEGORY_ID = Long.MAX_VALUE.toString() } } diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/HomeViewModel.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/HomeViewModel.kt index b7d39754..35e2b3e7 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/HomeViewModel.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/HomeViewModel.kt @@ -194,7 +194,7 @@ class HomeViewModel internal constructor( } } - fun markAsRead(feedItemId: Int) { + fun markAsRead(feedItemId: String) { scope.launch { feedRetrieverRepository.markAsRead( hashSetOf( diff --git a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/preview/PreviewItems.kt b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/preview/PreviewItems.kt index 7fc4db79..6805b88e 100644 --- a/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/preview/PreviewItems.kt +++ b/shared/src/commonMain/kotlin/com/prof18/feedflow/shared/presentation/preview/PreviewItems.kt @@ -19,18 +19,18 @@ import kotlinx.collections.immutable.persistentListOf val feedItemsForPreview = persistentListOf( FeedItem( - id = 0, + id = "0", url = "https://www.ilpost.it/2023/02/11/scheumorfismo/", title = "Le forme e gli oggetti che ci portiamo dietro nonostante il progresso", subtitle = null, content = null, imageUrl = "", feedSource = FeedSource( - id = 1, + id = "1", url = "https://www.ilpost.it", title = "Windows Central - News, Forums, Reviews, Help for Windows", category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), lastSyncTimestamp = null, @@ -43,19 +43,19 @@ val feedItemsForPreview = persistentListOf( isBookmarked = true, ), FeedItem( - id = 1, + id = "1", url = "https://www.androidpolice.com/google-pixel-7-pro-vs-pixel-6-pro/", title = "Google Pixel 7 Pro vs. Pixel 6 Pro: Should you upgrade?", subtitle = "The Pixel 7 Pro might not be a dramatic overhaul the way the 6 Pro was, but small refinements elevate the experience", content = null, imageUrl = "https://static1.anpoimages.com/wordpress/wp-content/uploads/2022/10/Pixel-7-Pro-vs-Pixel-6-Pro-comparison.jpg", feedSource = FeedSource( - id = 2, + id = "2", url = "", title = "Android Police", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, @@ -67,19 +67,19 @@ val feedItemsForPreview = persistentListOf( isBookmarked = true, ), FeedItem( - id = 3, + id = "3", url = "https://9to5linux.com/obs-studio-29-0-1-is-out-to-fix-linux-crash-on-wayland-x11-capture-issue", title = "OBS Studio 29.0.1 Is Out to Fix Linux Crash on Wayland, X11 Capture Issue", subtitle = "

OBS Studio 29.0.1 open-source and free software for live streaming and screen recording is now available for download with several bug fixes.

The post OBS Studio 29.0.1 Is Out to Fix Linux Crash on Wayland, X11 Capture Issue appeared first on 9to5Linux - do not reproduce this article without permission. This RSS feed is intended for readers, not scrapers.

", content = null, imageUrl = null, feedSource = FeedSource( - id = 3, + id = "3", url = "https://9to5linux.com", title = "9to5 Linux", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, @@ -91,19 +91,19 @@ val feedItemsForPreview = persistentListOf( isBookmarked = false, ), FeedItem( - id = 4, + id = "4", url = "https://androiddev.social/@marcogom/111096537433708200", title = null, subtitle = "

Back to writing after a while!

In this article, I cover how I used the HiddenFromObjC and ObjCName annotations introduced with #Kotlin 1.8 to improve the architecture of MoneyFlow!

https://www.marcogomiero.com/posts/2023/objc-annotiations-better-kmp-api/

", content = null, imageUrl = null, feedSource = FeedSource( - id = 3, + id = "3", url = "https://9to5linux.com", title = "9to5 Linux", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, @@ -131,34 +131,34 @@ val browsersForPreview = persistentListOf( val feedSourcesForPreview = persistentListOf( FeedSource( - id = 0, + id = "0", url = "https://www.site1.com", title = "Site 1", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, ), FeedSource( - id = 1, + id = "1", url = "https://www.site2.com", title = "Site 2", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 1, + id = "1", title = "News", ), logoUrl = null, ), FeedSource( - id = 2, + id = "2", url = "https://www.site3.com", title = "Site 3", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, @@ -177,12 +177,14 @@ val importExportStates = listOf( FeedImportExportState.ImportSuccess( notValidFeedSources = persistentListOf( ParsedFeedSource( + id = "1", url = "https://www.ilpost.it", title = "Il Post", categoryName = null, logoUrl = null, ), ParsedFeedSource( + id = "1", url = "https://www.techcrunch.it", title = "Tech Crunch", categoryName = null, @@ -197,19 +199,19 @@ val categoriesExpandedState = CategoriesState( header = "No category selected", categories = listOf( CategoryItem( - id = 0, + id = "0", name = "Android", isSelected = true, onClick = {}, ), CategoryItem( - id = 0, + id = "0", name = "Apple", isSelected = false, onClick = {}, ), CategoryItem( - id = 0, + id = "0", name = "Tech", isSelected = false, onClick = {}, @@ -222,19 +224,19 @@ val categoriesCollapsedState = CategoriesState( header = "Android", categories = listOf( CategoryItem( - id = 0, + id = "0", name = "Android", isSelected = true, onClick = {}, ), CategoryItem( - id = 0, + id = "0", name = "Apple", isSelected = false, onClick = {}, ), CategoryItem( - id = 0, + id = "0", name = "Tech", isSelected = false, onClick = {}, @@ -244,19 +246,19 @@ val categoriesCollapsedState = CategoriesState( val feedSourcesState = persistentListOf( FeedSourceState( - categoryId = CategoryId(1), + categoryId = CategoryId("1"), categoryName = "Tech", isExpanded = true, feedSources = feedSourcesForPreview, ), FeedSourceState( - categoryId = CategoryId(1), + categoryId = CategoryId("1"), categoryName = "News", isExpanded = false, feedSources = feedSourcesForPreview, ), FeedSourceState( - categoryId = CategoryId(1), + categoryId = CategoryId("1"), categoryName = "Mobile", isExpanded = true, feedSources = feedSourcesForPreview, @@ -274,13 +276,13 @@ val navDrawerState = NavDrawerState( categories = listOf( DrawerItem.DrawerCategory( category = FeedSourceCategory( - id = 9398, + id = "9398", title = "News", ), ), DrawerItem.DrawerCategory( category = FeedSourceCategory( - id = 9398, + id = "9398", title = "Basket", ), ), @@ -289,18 +291,18 @@ val navDrawerState = NavDrawerState( feedSourcesByCategory = mapOf( DrawerItem.DrawerFeedSource.FeedSourceCategoryWrapper( feedSourceCategory = FeedSourceCategory( - id = 9398, + id = "9398", title = "News", ), ) to listOf( DrawerItem.DrawerFeedSource( feedSource = FeedSource( - id = 0, + id = "0", url = "https://www.site1.com", title = "Site 1", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 2, + id = "2", title = "Tech", ), logoUrl = null, @@ -308,12 +310,12 @@ val navDrawerState = NavDrawerState( ), DrawerItem.DrawerFeedSource( feedSource = FeedSource( - id = 1, + id = "1", url = "https://www.site2.com", title = "Site 2", lastSyncTimestamp = null, category = FeedSourceCategory( - id = 1, + id = "1", title = "News", ), logoUrl = null, @@ -327,12 +329,14 @@ val navDrawerState = NavDrawerState( val feedImportSuccessWithErrorState = FeedImportExportState.ImportSuccess( notValidFeedSources = persistentListOf( ParsedFeedSource( + id = "1", url = "https://www.ilpost.it", title = "Il Post", categoryName = null, logoUrl = null, ), ParsedFeedSource( + id = "2", url = "https://www.techcrunch.it", title = "Tech Crunch", categoryName = null, @@ -347,19 +351,19 @@ val feedImportSuccessState = FeedImportExportState.ImportSuccess( val categoryItems = listOf( CategoryItem( - id = 0, + id = "0", name = "Android", isSelected = true, onClick = {}, ), CategoryItem( - id = 1, + id = "1", name = "Apple", isSelected = false, onClick = {}, ), CategoryItem( - id = 2, + id = "2", name = "Tech", isSelected = false, onClick = {},