From 00ef93f0c561302f5d420fcdca7d658033541fdd Mon Sep 17 00:00:00 2001 From: davide Date: Tue, 16 Aug 2022 11:49:53 +0200 Subject: [PATCH] Remove unused repository interface --- .../apps/readerforselfossv2/android/MyApp.kt | 4 +- .../repository/Repository.kt | 52 ---------------- .../repository/RepositoryImpl.kt | 60 +++++++++---------- 3 files changed, 31 insertions(+), 85 deletions(-) delete mode 100644 shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt index 53bb28e..d0e190e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt @@ -13,7 +13,6 @@ import bou.amine.apps.readerforselfossv2.DI.networkModule import bou.amine.apps.readerforselfossv2.android.utils.Config import bou.amine.apps.readerforselfossv2.android.utils.glide.loadMaybeBasicAuth import bou.amine.apps.readerforselfossv2.repository.Repository -import bou.amine.apps.readerforselfossv2.repository.RepositoryImpl import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions import com.ftinc.scoop.Scoop @@ -21,13 +20,12 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader import com.russhwolf.settings.Settings import org.kodein.di.* -import java.util.UUID.randomUUID class MyApp : MultiDexApplication(), DIAware { override val di by DI.lazy { import(networkModule) - bind() with singleton { RepositoryImpl(instance(), instance()) } + bind() with singleton { Repository(instance(), instance()) } } private lateinit var config: Config 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 deleted file mode 100644 index e926a0b..0000000 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/Repository.kt +++ /dev/null @@ -1,52 +0,0 @@ -package bou.amine.apps.readerforselfossv2.repository - -import bou.amine.apps.readerforselfossv2.rest.SelfossModel -import bou.amine.apps.readerforselfossv2.utils.DateUtils -import bou.amine.apps.readerforselfossv2.utils.ItemType - -interface Repository { - - // TODO: remove the items variables in favor of storing everything in the database - var items: ArrayList - var baseUrl: String - var dateUtils: DateUtils - - var displayedItems: ItemType - - // Settings - var itemsCaching: Boolean - - // API - var apiMajorVersion: Int - var badgeUnread: Int - var badgeAll: Int - var badgeStarred: Int - - var tagFilter: SelfossModel.Tag? - var sourceFilter: SelfossModel.Source? - var searchFilter: String? - - suspend fun getNewerItems(): ArrayList - suspend fun getOlderItems(): ArrayList - suspend fun allItems(itemType: ItemType): List? - suspend fun reloadBadges(): Boolean - suspend fun getTags(): List? - suspend fun getSpouts(): Map? - suspend fun getSources(): ArrayList? - suspend fun markAsRead(id: Int): Boolean - suspend fun unmarkAsRead(id: Int): Boolean - suspend fun starr(id: Int): Boolean - suspend fun unstarr(id: Int): Boolean - suspend fun markAllAsRead(ids: List): Boolean - suspend fun createSource(title: String, - url: String, - spout: String, - tags: String, - filter: String): Boolean - suspend fun deleteSource(id: Int): Boolean - suspend fun updateRemote(): Boolean - suspend fun login(): Boolean - fun refreshLoginInformation(url: String, login: String, password: String, - httpLogin: String, httpPassword: String, - isSelfSignedCert: Boolean) -} \ No newline at end of file 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 1c5fe54..c9fed74 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 @@ -11,28 +11,28 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDetailsService) : Repository { +class Repository(private val api: SelfossApi, private val apiDetails: ApiDetailsService) { val settings = Settings() - override var items = ArrayList() + var items = ArrayList() - override var baseUrl = apiDetails.getBaseUrl() - override lateinit var dateUtils: DateUtils + var baseUrl = apiDetails.getBaseUrl() + lateinit var dateUtils: DateUtils - override var displayedItems = ItemType.UNREAD + var displayedItems = ItemType.UNREAD - override var tagFilter: SelfossModel.Tag? = null - override var sourceFilter: SelfossModel.Source? = null - override var searchFilter: String? = null + var tagFilter: SelfossModel.Tag? = null + var sourceFilter: SelfossModel.Source? = null + var searchFilter: String? = null - override var itemsCaching = settings.getBoolean("items_caching", false) + var itemsCaching = settings.getBoolean("items_caching", false) - override var apiMajorVersion = 0 - override var badgeUnread = 0 + var apiMajorVersion = 0 + var badgeUnread = 0 set(value) {field = if (value < 0) { 0 } else { value } } - override var badgeAll = 0 + var badgeAll = 0 set(value) {field = if (value < 0) { 0 } else { value } } - override var badgeStarred = 0 + var badgeStarred = 0 set(value) {field = if (value < 0) { 0 } else { value } } init { @@ -44,7 +44,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet } } - override suspend fun getNewerItems(): ArrayList { + suspend fun getNewerItems(): ArrayList { // TODO: Check connectivity, use the updatedSince parameter val fetchedItems = api.getItems(displayedItems.type, settings.getString("prefer_api_items_number", "200").toInt(), @@ -60,7 +60,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return items } - override suspend fun getOlderItems(): ArrayList { + suspend fun getOlderItems(): ArrayList { // TODO: Check connectivity val offset = items.size val fetchedItems = api.getItems(displayedItems.type, @@ -77,7 +77,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return items } - override suspend fun allItems(itemType: ItemType): List? = + suspend fun allItems(itemType: ItemType): List? = api.getItems(itemType.type, 200, 0, tagFilter?.tag, sourceFilter?.id?.toLong(), searchFilter, null) private fun appendItems(fetchedItems: List) { @@ -93,7 +93,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet items.sortByDescending { dateUtils.parseDate(it.datetime) } } - override suspend fun reloadBadges(): Boolean { + suspend fun reloadBadges(): Boolean { // TODO: Check connectivity, calculate from DB var success = false val response = api.stats() @@ -106,22 +106,22 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun getTags(): List? { + suspend fun getTags(): List? { // TODO: Check success, store in DB return api.tags() } - override suspend fun getSpouts(): Map? { + suspend fun getSpouts(): Map? { // TODO: Check success, store in DB return api.spouts() } - override suspend fun getSources(): ArrayList? { + suspend fun getSources(): ArrayList? { // TODO: Check success return api.sources() } - override suspend fun markAsRead(id: Int): Boolean { + suspend fun markAsRead(id: Int): Boolean { // TODO: Check internet connection val success = api.markAsRead(id.toString())?.isSuccess == true @@ -131,7 +131,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun unmarkAsRead(id: Int): Boolean { + suspend fun unmarkAsRead(id: Int): Boolean { // TODO: Check internet connection val success = api.unmarkAsRead(id.toString())?.isSuccess == true @@ -141,7 +141,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun starr(id: Int): Boolean { + suspend fun starr(id: Int): Boolean { // TODO: Check success, store in DB val success = api.starr(id.toString())?.isSuccess == true @@ -151,7 +151,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun unstarr(id: Int): Boolean { + suspend fun unstarr(id: Int): Boolean { // TODO: Check internet connection val success = api.unstarr(id.toString())?.isSuccess == true @@ -161,7 +161,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun markAllAsRead(ids: List): Boolean { + suspend fun markAllAsRead(ids: List): Boolean { // TODO: Check Internet connectivity, store in DB val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true @@ -207,7 +207,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet } } - override suspend fun createSource( + suspend fun createSource( title: String, url: String, spout: String, @@ -227,7 +227,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return response != null } - override suspend fun deleteSource(id: Int): Boolean { + suspend fun deleteSource(id: Int): Boolean { // TODO: Check connectivity, store in DB var success = false val response = api.deleteSource(id) @@ -238,13 +238,13 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return success } - override suspend fun updateRemote(): Boolean { + suspend fun updateRemote(): Boolean { // TODO: Handle connectivity issues val response = api.update() return response?.isSuccess ?: false } - override suspend fun login(): Boolean { + suspend fun login(): Boolean { var result = false try { val response = api.login() @@ -257,7 +257,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet return result } - override fun refreshLoginInformation(url: String, login: String, password: String, + fun refreshLoginInformation(url: String, login: String, password: String, httpLogin: String, httpPassword: String, isSelfSignedCert: Boolean) { settings.putString("url", url)