diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index 29c7835..d0a9c5e 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -15,9 +15,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.ActionBarDrawerToggle import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity -import androidx.appcompat.app.AppCompatDelegate -import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO -import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import androidx.appcompat.widget.SearchView import androidx.core.view.doOnNextLayout import androidx.drawerlayout.widget.DrawerLayout @@ -98,8 +95,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private val repository : Repository by instance() private val appSettingsService : AppSettingsService by instance() - data class DrawerData(val tags: List?, val sources: List?) - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityHomeBinding.inflate(layoutInflater) @@ -352,28 +347,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ) CoroutineScope(Dispatchers.IO).launch { - val drawerData = DrawerData(repository.getDBTags().map { it.toView() }, - repository.getDBSources().map { it.toView() }) + val tags = repository.getTags() + val sources = repository.getSources() runOnUiThread { - // TODO: All this logic should be handled by the repository, simplify and remove direct DB access - // Only refresh if there is no data in the DB, or if the `UpdateSources` setting is enabled - if (drawerData.sources?.isEmpty() == true || appSettingsService.isUpdateSourcesEnabled()) { - drawerApiCalls(drawerData) - } else { - handleDrawerData(drawerData, loadedFromCache = true) - } + handleDrawerData(tags, sources) } } } - private fun drawerApiCalls(drawerData: DrawerData) { - CoroutineScope(Dispatchers.Main).launch { - val apiDrawerData = DrawerData(repository.getTags(), repository.getSources()) - handleDrawerData(if (drawerData != apiDrawerData) apiDrawerData else drawerData) - } - } - - private fun handleDrawerData(drawerData: DrawerData, loadedFromCache: Boolean = false) { + private fun handleDrawerData(tags: List, sources: List) { binding.mainDrawer.itemAdapter.clear() // Filters title with clear action @@ -387,24 +369,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } // Hidden tags - if (drawerData.tags != null && drawerData.tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) { + if (tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) { secondaryItem( withDivider = true, R.string.drawer_item_hidden_tags, DRAWER_ID_HIDDEN_TAGS ) - handleHiddenTags(drawerData.tags) + handleHiddenTags(tags) } // Tags secondaryItem(withDivider = true, R.string.drawer_item_tags, DRAWER_ID_TAGS) - if (drawerData.tags == null && !loadedFromCache) { + if (tags.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem() .apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false } ) } else { - handleTags(drawerData.tags!!) + handleTags(tags) } // Sources @@ -412,15 +394,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar startActivity(Intent(v!!.context, SourcesActivity::class.java)) false } - if (drawerData.sources == null && !loadedFromCache) { + if (sources.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem().apply { - nameRes = R.string.drawer_error_loading_tags + nameRes = R.string.drawer_error_loading_sources isSelectable = false } ) } else { - handleSources(drawerData.sources!!) + handleSources(sources) } // About action 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 0268a1e..49c803c 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 @@ -75,7 +75,6 @@ class MyApp : MultiDexApplication(), DIAware { ).show() } } - } private fun handleNotificationChannels() { diff --git a/androidApp/src/main/res/values-ca-rES/strings.xml b/androidApp/src/main/res/values-ca-rES/strings.xml index 81b73b2..2b3b632 100644 --- a/androidApp/src/main/res/values-ca-rES/strings.xml +++ b/androidApp/src/main/res/values-ca-rES/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-de-rDE/strings.xml b/androidApp/src/main/res/values-de-rDE/strings.xml index 0ed6a9a..5dd30bf 100644 --- a/androidApp/src/main/res/values-de-rDE/strings.xml +++ b/androidApp/src/main/res/values-de-rDE/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-es-rES/strings.xml b/androidApp/src/main/res/values-es-rES/strings.xml index 2ffb60f..c7ebc34 100644 --- a/androidApp/src/main/res/values-es-rES/strings.xml +++ b/androidApp/src/main/res/values-es-rES/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-fa-rIR/strings.xml b/androidApp/src/main/res/values-fa-rIR/strings.xml index a61ae5f..9b12fa3 100644 --- a/androidApp/src/main/res/values-fa-rIR/strings.xml +++ b/androidApp/src/main/res/values-fa-rIR/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-fr-rFR/strings.xml b/androidApp/src/main/res/values-fr-rFR/strings.xml index 11e381e..31f87cb 100644 --- a/androidApp/src/main/res/values-fr-rFR/strings.xml +++ b/androidApp/src/main/res/values-fr-rFR/strings.xml @@ -132,4 +132,5 @@ Thème sombre Utiliser les paramètres système Thème clair + Error loading sources… diff --git a/androidApp/src/main/res/values-gl-rES/strings.xml b/androidApp/src/main/res/values-gl-rES/strings.xml index 488bcd8..111efb8 100644 --- a/androidApp/src/main/res/values-gl-rES/strings.xml +++ b/androidApp/src/main/res/values-gl-rES/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-in-rID/strings.xml b/androidApp/src/main/res/values-in-rID/strings.xml index 9d8e828..9be67a8 100644 --- a/androidApp/src/main/res/values-in-rID/strings.xml +++ b/androidApp/src/main/res/values-in-rID/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-it-rIT/strings.xml b/androidApp/src/main/res/values-it-rIT/strings.xml index fbe1c19..63b1f8b 100644 --- a/androidApp/src/main/res/values-it-rIT/strings.xml +++ b/androidApp/src/main/res/values-it-rIT/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-ko-rKR/strings.xml b/androidApp/src/main/res/values-ko-rKR/strings.xml index e6913c5..1ac49f8 100644 --- a/androidApp/src/main/res/values-ko-rKR/strings.xml +++ b/androidApp/src/main/res/values-ko-rKR/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-nl-rNL/strings.xml b/androidApp/src/main/res/values-nl-rNL/strings.xml index 8161047..c1fff12 100644 --- a/androidApp/src/main/res/values-nl-rNL/strings.xml +++ b/androidApp/src/main/res/values-nl-rNL/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-pt-rBR/strings.xml b/androidApp/src/main/res/values-pt-rBR/strings.xml index c5d671b..b72186c 100644 --- a/androidApp/src/main/res/values-pt-rBR/strings.xml +++ b/androidApp/src/main/res/values-pt-rBR/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-pt-rPT/strings.xml b/androidApp/src/main/res/values-pt-rPT/strings.xml index a5b0c67..098cffb 100644 --- a/androidApp/src/main/res/values-pt-rPT/strings.xml +++ b/androidApp/src/main/res/values-pt-rPT/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-si-rLK/strings.xml b/androidApp/src/main/res/values-si-rLK/strings.xml index c653406..093df0d 100644 --- a/androidApp/src/main/res/values-si-rLK/strings.xml +++ b/androidApp/src/main/res/values-si-rLK/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-tr-rTR/strings.xml b/androidApp/src/main/res/values-tr-rTR/strings.xml index 3b8b67e..cab7d99 100644 --- a/androidApp/src/main/res/values-tr-rTR/strings.xml +++ b/androidApp/src/main/res/values-tr-rTR/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values-zh-rCN/strings.xml b/androidApp/src/main/res/values-zh-rCN/strings.xml index 3d97d0a..0f61ea8 100644 --- a/androidApp/src/main/res/values-zh-rCN/strings.xml +++ b/androidApp/src/main/res/values-zh-rCN/strings.xml @@ -132,4 +132,5 @@ 深色模式 遵循系统设置 浅色模式 + Error loading sources… diff --git a/androidApp/src/main/res/values-zh-rTW/strings.xml b/androidApp/src/main/res/values-zh-rTW/strings.xml index 089a6b2..95fbb4a 100644 --- a/androidApp/src/main/res/values-zh-rTW/strings.xml +++ b/androidApp/src/main/res/values-zh-rTW/strings.xml @@ -132,4 +132,5 @@ Dark mode Follow the system setting Light mode + Error loading sources… diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 86978a0..0a69bb9 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -63,6 +63,7 @@ Card height will be fixed Source code Error loading tags… + Error loading sources… Filters clear Tags @@ -109,7 +110,7 @@ Articles will periodically be synced = 15 minutes)]]> Only refresh when phone is charging - Loading ... + Loading … Selfoss is syncing your articles Sync notification New items notification 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 8a1fa86..f2635eb 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 @@ -42,6 +42,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap init { // TODO: Dispatchers.IO not available in KMM, an alternative solution should be found + connectivityStatus.start() runBlocking { updateApiVersion() dateUtils = DateUtils(appSettingsService) @@ -410,11 +411,9 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap private fun deleteDBAction(action: ACTION) = db.actionsQueries.deleteAction(action.id) - // TODO: This function should be private - fun getDBTags(): List = db.tagsQueries.tags().executeAsList() + private fun getDBTags(): List = db.tagsQueries.tags().executeAsList() - // TODO: This function should be private - fun getDBSources(): List = db.sourcesQueries.sources().executeAsList() + private fun getDBSources(): List = db.sourcesQueries.sources().executeAsList() private fun resetDBTagsWithData(tagEntities: List) { db.tagsQueries.deleteAllTags() diff --git a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt index 1d99897..decac9d 100644 --- a/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt +++ b/shared/src/commonTest/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryTest.kt @@ -42,6 +42,8 @@ class RepositoryTest() { every { db.tagsQueries.deleteAllTags() } returns Unit every { db.tagsQueries.transaction(any(), any()) } returns Unit every { db.tagsQueries.insertTag(any()) } returns Unit + + every { connectivityStatus.start() } returns Unit } @Test