From c0137ea5e7f18d1ae08ae07fc836c0e1cd340a5a Mon Sep 17 00:00:00 2001 From: davide Date: Sat, 23 Jul 2022 17:40:27 +0200 Subject: [PATCH] Accept article IDs as Int in the Repository It's cleaner to accept ints and not strings, because the ID is internally stored as an Int --- .../apps/readerforselfossv2/android/ReaderActivity.kt | 2 +- .../android/adapters/ItemsAdapter.kt | 4 ++-- .../android/fragments/ArticleFragment.kt | 4 ++-- .../apps/readerforselfossv2/repository/Repository.kt | 6 +++--- .../readerforselfossv2/repository/RepositoryImpl.kt | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index 01a7aa3..f283e3e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -114,7 +114,7 @@ class ReaderActivity : AppCompatActivity(), DIAware { private fun readItem(item: SelfossModel.Item) { if (markOnScroll) { CoroutineScope(Dispatchers.IO).launch { - repository.markAsRead(item.id.toString()) + repository.markAsRead(item.id) // TODO: Handle failure } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index 168b944..58cc99d 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -83,7 +83,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) { val i = items[position] CoroutineScope(Dispatchers.IO).launch { - repository.markAsRead(i.id.toString()) + repository.markAsRead(i.id) // TODO: update db } @@ -102,7 +102,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) { CoroutineScope(Dispatchers.IO).launch { - repository.unmarkAsRead(items[position].id.toString()) + repository.unmarkAsRead(items[position].id) // Todo: SharedItems.unreadItem(app, api, db, items[position]) // TODO: update db diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 43a9013..06e4904 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -170,7 +170,7 @@ class ArticleFragment : Fragment(), DIAware { R.id.unread_action -> if (context != null) { if (this@ArticleFragment.item.unread) { CoroutineScope(Dispatchers.IO).launch { - repository.markAsRead(this@ArticleFragment.item.id.toString()) + repository.markAsRead(this@ArticleFragment.item.id) } this@ArticleFragment.item.unread = false Toast.makeText( @@ -180,7 +180,7 @@ class ArticleFragment : Fragment(), DIAware { ).show() } else { CoroutineScope(Dispatchers.IO).launch { - repository.unmarkAsRead(this@ArticleFragment.item.id.toString()) + repository.unmarkAsRead(this@ArticleFragment.item.id) } this@ArticleFragment.item.unread = true Toast.makeText( diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt index f43c451..acfb4f6 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt @@ -17,11 +17,11 @@ interface Repository { fun getTags(): List suspend fun getSpouts(): Map? suspend fun getSources(): ArrayList? - suspend fun markAsRead(id: String): Boolean - suspend fun unmarkAsRead(id: String): Boolean + suspend fun markAsRead(id: Int): Boolean + suspend fun unmarkAsRead(id: Int): Boolean suspend fun starr(id: Int): Boolean suspend fun unstarr(id: Int): Boolean - fun markAllAsRead(ids: List): Boolean + fun markAllAsRead(ids: List): Boolean suspend fun createSource(title: String, url: String, spout: String, diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index fa6ef71..52fcfcd 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -47,15 +47,15 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return api.sources() } - override suspend fun markAsRead(id: String): Boolean { + override suspend fun markAsRead(id: Int): Boolean { // TODO: Check success, store in DB - api.markAsRead(id) + api.markAsRead(id.toString()) return true } - override suspend fun unmarkAsRead(id: String): Boolean { + override suspend fun unmarkAsRead(id: Int): Boolean { // TODO: Check success, store in DB - api.unmarkAsRead(id) + api.unmarkAsRead(id.toString()) return true } override suspend fun starr(id: Int): Boolean { @@ -70,7 +70,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return true } - override fun markAllAsRead(ids: List): Boolean { + override fun markAllAsRead(ids: List): Boolean { TODO("Not yet implemented") }