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
This commit is contained in:
davide 2022-07-23 17:40:27 +02:00
parent b14a6427da
commit c0137ea5e7
5 changed files with 13 additions and 13 deletions

View File

@ -114,7 +114,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
private fun readItem(item: SelfossModel.Item) { private fun readItem(item: SelfossModel.Item) {
if (markOnScroll) { if (markOnScroll) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(item.id.toString()) repository.markAsRead(item.id)
// TODO: Handle failure // TODO: Handle failure
} }
} }

View File

@ -83,7 +83,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) { private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
val i = items[position] val i = items[position]
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(i.id.toString()) repository.markAsRead(i.id)
// TODO: update db // TODO: update db
} }
@ -102,7 +102,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) { private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unmarkAsRead(items[position].id.toString()) repository.unmarkAsRead(items[position].id)
// Todo: SharedItems.unreadItem(app, api, db, items[position]) // Todo: SharedItems.unreadItem(app, api, db, items[position])
// TODO: update db // TODO: update db

View File

@ -170,7 +170,7 @@ class ArticleFragment : Fragment(), DIAware {
R.id.unread_action -> if (context != null) { R.id.unread_action -> if (context != null) {
if (this@ArticleFragment.item.unread) { if (this@ArticleFragment.item.unread) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(this@ArticleFragment.item.id.toString()) repository.markAsRead(this@ArticleFragment.item.id)
} }
this@ArticleFragment.item.unread = false this@ArticleFragment.item.unread = false
Toast.makeText( Toast.makeText(
@ -180,7 +180,7 @@ class ArticleFragment : Fragment(), DIAware {
).show() ).show()
} else { } else {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unmarkAsRead(this@ArticleFragment.item.id.toString()) repository.unmarkAsRead(this@ArticleFragment.item.id)
} }
this@ArticleFragment.item.unread = true this@ArticleFragment.item.unread = true
Toast.makeText( Toast.makeText(

View File

@ -17,11 +17,11 @@ interface Repository {
fun getTags(): List<SelfossModel.Tag> fun getTags(): List<SelfossModel.Tag>
suspend fun getSpouts(): Map<String, SelfossModel.Spout>? suspend fun getSpouts(): Map<String, SelfossModel.Spout>?
suspend fun getSources(): ArrayList<SelfossModel.Source>? suspend fun getSources(): ArrayList<SelfossModel.Source>?
suspend fun markAsRead(id: String): Boolean suspend fun markAsRead(id: Int): Boolean
suspend fun unmarkAsRead(id: String): Boolean suspend fun unmarkAsRead(id: Int): Boolean
suspend fun starr(id: Int): Boolean suspend fun starr(id: Int): Boolean
suspend fun unstarr(id: Int): Boolean suspend fun unstarr(id: Int): Boolean
fun markAllAsRead(ids: List<String>): Boolean fun markAllAsRead(ids: List<Int>): Boolean
suspend fun createSource(title: String, suspend fun createSource(title: String,
url: String, url: String,
spout: String, spout: String,

View File

@ -47,15 +47,15 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
return api.sources() return api.sources()
} }
override suspend fun markAsRead(id: String): Boolean { override suspend fun markAsRead(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check success, store in DB
api.markAsRead(id) api.markAsRead(id.toString())
return true return true
} }
override suspend fun unmarkAsRead(id: String): Boolean { override suspend fun unmarkAsRead(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check success, store in DB
api.unmarkAsRead(id) api.unmarkAsRead(id.toString())
return true } return true }
override suspend fun starr(id: Int): Boolean { override suspend fun starr(id: Int): Boolean {
@ -70,7 +70,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
return true return true
} }
override fun markAllAsRead(ids: List<String>): Boolean { override fun markAllAsRead(ids: List<Int>): Boolean {
TODO("Not yet implemented") TODO("Not yet implemented")
} }