From edc705ec8e65d59e75516e81d6b37ac1bfac7e84 Mon Sep 17 00:00:00 2001 From: davide Date: Tue, 16 Aug 2022 11:23:03 +0200 Subject: [PATCH] Remove unused class --- .../service/SelfossService.kt | 109 ------------------ 1 file changed, 109 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SelfossService.kt diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SelfossService.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SelfossService.kt deleted file mode 100644 index 365abe9..0000000 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/service/SelfossService.kt +++ /dev/null @@ -1,109 +0,0 @@ -package bou.amine.apps.readerforselfossv2.service - - -import bou.amine.apps.readerforselfossv2.rest.SelfossApi -import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import kotlinx.coroutines.* - -class SelfossService(val api: SelfossApi, private val dbService: DeviceDataBaseService, private val searchService: SearchService) { - - suspend fun getReadItems(itemsNumber: Int, offset: Int, isNetworkAvailable: Boolean): List? = withContext( - Dispatchers.Default) { - if (isNetworkAvailable) { - val apiItems = readItems( itemsNumber, offset) - // SAVE OR UPDATE IN DB - return@withContext apiItems - } else { - // GET FROM DB - return@withContext emptyList() - } - } - - suspend fun getUnreadItems(itemsNumber: Int, offset: Int, isNetworkAvailable: Boolean): List? = withContext( - Dispatchers.Default) { - if (isNetworkAvailable) { - val apiItems = newItems(itemsNumber, offset) - // SAVE OR UPDATE IN DB - return@withContext apiItems - } else { - // GET FROM DB - return@withContext emptyList() - } - } - - suspend fun getStarredItems(itemsNumber: Int, offset: Int, isNetworkAvailable: Boolean): List? = withContext( - Dispatchers.Default) { - if (isNetworkAvailable) { - val apiItems = starredItems(itemsNumber, offset) - // SAVE OR UPDATE IN DB - return@withContext apiItems - } else { - // GET FROM DB - return@withContext emptyList() - } - } - - suspend fun readAll(ids: List, isNetworkAvailable: Boolean): Boolean { - // Add ids params - var success = false - if (isNetworkAvailable) { - success = api.markAllAsRead(ids)?.isSuccess == true - // SAVE OR UPDATE IN DB - } - // refresh view - return success - } - - suspend fun reloadBadges(isNetworkAvailable: Boolean) = withContext(Dispatchers.Default) { - if (isNetworkAvailable) { - try { - val response = api.stats() - if (response != null) { - searchService.badgeUnread = response.unread - searchService.badgeAll = response.total - searchService.badgeStarred = response.starred - } - } catch (e: Throwable) {} - } else { - dbService.computeBadges() - } - } - - private fun enqueueArticles(response: List?, clearDatabase: Boolean) { - if (response != null) { - if (clearDatabase) { - CoroutineScope(Dispatchers.Default).launch { - dbService.clearDBItems() - } - } - dbService.appendNewItems(response) - } - } - - suspend fun allNewItems(): List? = - readItems(200, 0) - - suspend fun allReadItems(): List? = - newItems(200, 0) - - suspend fun allStarredItems(): List? = - starredItems(200, 0) - - private suspend fun readItems( - itemsNumber: Int, - offset: Int - ): List? = - api.getItems("read", itemsNumber, offset, searchService.tagFilter, searchService.sourceIDFilter, searchService.searchFilter) - - private suspend fun newItems( - itemsNumber: Int, - offset: Int - ): List? = - api.getItems("unread", itemsNumber, offset, searchService.tagFilter, searchService.sourceIDFilter, searchService.searchFilter) - - private suspend fun starredItems( - itemsNumber: Int, - offset: Int - ): List? = - api.getItems("starred", itemsNumber, offset, searchService.tagFilter, searchService.sourceIDFilter, searchService.searchFilter) -} \ No newline at end of file