Remove Selfoss Service from Home Activity
Initial implementation of the missing functions in the repository
This commit is contained in:
parent
11eac7b141
commit
924f4da1ec
@ -34,7 +34,6 @@ import bou.amine.apps.readerforselfossv2.android.persistence.AndroidDeviceDataba
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.AndroidDeviceDatabaseService
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.database.AppDatabase
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.entities.ActionEntity
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.entities.AndroidItemEntity
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_1_2
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_2_3
|
||||
import bou.amine.apps.readerforselfossv2.android.persistence.migrations.MIGRATION_3_4
|
||||
@ -49,13 +48,11 @@ import bou.amine.apps.readerforselfossv2.android.utils.network.isNetworkAvailabl
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toEntity
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.persistence.toView
|
||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossApiImpl
|
||||
import bou.amine.apps.readerforselfossv2.rest.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.service.ApiDetailsService
|
||||
import bou.amine.apps.readerforselfossv2.service.SearchService
|
||||
import bou.amine.apps.readerforselfossv2.service.SelfossService
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.longHash
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationBar
|
||||
import com.ashokvarma.bottomnavigation.BottomNavigationItem
|
||||
@ -92,7 +89,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
private lateinit var dataBase: AndroidDeviceDatabase
|
||||
private lateinit var dbService: AndroidDeviceDatabaseService
|
||||
private lateinit var searchService: SearchService
|
||||
private lateinit var service: SelfossService<AndroidItemEntity>
|
||||
private val MENU_PREFERENCES = 12302
|
||||
private val DRAWER_ID_TAGS = 100101L
|
||||
private val DRAWER_ID_HIDDEN_TAGS = 101100L
|
||||
@ -204,7 +200,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
dataBase = AndroidDeviceDatabase(applicationContext)
|
||||
searchService = SearchService(DateUtils(repository.apiMajorVersion))
|
||||
dbService = AndroidDeviceDatabaseService(dataBase, searchService)
|
||||
service = SelfossService(api, dbService, searchService)
|
||||
|
||||
handleBottomBar()
|
||||
handleDrawer()
|
||||
@ -1154,7 +1149,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
|
||||
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
val success = service.readAll(items.map { it.id.toString() }, applicationContext.isNetworkAvailable())
|
||||
val success = repository.markAllAsRead(items.map { it.id })
|
||||
if (success) {
|
||||
Toast.makeText(
|
||||
this@HomeActivity,
|
||||
|
@ -19,14 +19,14 @@ interface Repository {
|
||||
suspend fun getNewerItems(): ArrayList<SelfossModel.Item>
|
||||
suspend fun getOlderItems(): ArrayList<SelfossModel.Item>
|
||||
suspend fun reloadBadges(): Boolean
|
||||
fun getTags(): List<SelfossModel.Tag>
|
||||
suspend fun getTags(): List<SelfossModel.Tag>?
|
||||
suspend fun getSpouts(): Map<String, SelfossModel.Spout>?
|
||||
suspend fun getSources(): ArrayList<SelfossModel.Source>?
|
||||
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<Int>): Boolean
|
||||
suspend fun markAllAsRead(ids: List<Int>): Boolean
|
||||
suspend fun createSource(title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
|
@ -36,8 +36,11 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
|
||||
override var apiMajorVersion = 0
|
||||
override var badgeUnread = 0
|
||||
set(value) {field = if (value < 0) { 0 } else { value } }
|
||||
override var badgeAll = 0
|
||||
set(value) {field = if (value < 0) { 0 } else { value } }
|
||||
override var badgeStarred = 0
|
||||
set(value) {field = if (value < 0) { 0 } else { value } }
|
||||
|
||||
init {
|
||||
// TODO: Dispatchers.IO not available in KMM, an alternative solution should be found
|
||||
@ -121,8 +124,9 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
return success
|
||||
}
|
||||
|
||||
override fun getTags(): List<SelfossModel.Tag> {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun getTags(): List<SelfossModel.Tag>? {
|
||||
// TODO: Check success, store in DB
|
||||
return api.tags()
|
||||
}
|
||||
|
||||
override suspend fun getSpouts(): Map<String, SelfossModel.Spout>? {
|
||||
@ -144,9 +148,13 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
|
||||
override suspend fun unmarkAsRead(id: Int): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
api.unmarkAsRead(id.toString())
|
||||
badgeUnread += 1
|
||||
return true }
|
||||
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||
|
||||
if (success) {
|
||||
markAsReadLocally(id)
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
override suspend fun starr(id: Int): Boolean {
|
||||
// TODO: Check success, store in DB
|
||||
@ -162,8 +170,25 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
||||
return true
|
||||
}
|
||||
|
||||
override fun markAllAsRead(ids: List<Int>): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun markAllAsRead(ids: List<Int>): Boolean {
|
||||
// TODO: Check Internet connectivity, store in DB
|
||||
|
||||
val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true
|
||||
|
||||
if (success) {
|
||||
for (id in ids) {
|
||||
markAsReadLocally(id)
|
||||
}
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
private fun markAsReadLocally(id: Int) {
|
||||
// TODO: Mark also in the database
|
||||
if (items.first {it.id == id}.unread) {
|
||||
items.first {it.id == id}.unread = false
|
||||
badgeUnread -= 1
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun createSource(
|
||||
|
Loading…
Reference in New Issue
Block a user