From f7055626d9a526fe0a6c052b9242792eab6bf261 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 30 Sep 2022 14:56:10 +0200 Subject: [PATCH 1/7] Start monitoring the connectivity before loading the Repository --- .../main/java/bou/amine/apps/readerforselfossv2/android/MyApp.kt | 1 + 1 file changed, 1 insertion(+) 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..a33ac66 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,6 +75,7 @@ class MyApp : MultiDexApplication(), DIAware { ).show() } } + connectivityStatus.start() } From b5b820c64b7117edcf68ef39e2b89b342f3e4cb5 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 30 Sep 2022 15:00:01 +0200 Subject: [PATCH 2/7] Remove database access from the Home --- .../android/HomeActivity.kt | 35 +++++-------------- .../repository/RepositoryImpl.kt | 6 ++-- 2 files changed, 11 insertions(+), 30 deletions(-) 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..877994e 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,7 +95,7 @@ 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?) + data class DrawerData(val tags: List, val sources: List) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -352,28 +349,14 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ) CoroutineScope(Dispatchers.IO).launch { - val drawerData = DrawerData(repository.getDBTags().map { it.toView() }, - repository.getDBSources().map { it.toView() }) + val drawerData = DrawerData(repository.getTags(), 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(drawerData) } } } - 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(drawerData: DrawerData) { binding.mainDrawer.itemAdapter.clear() // Filters title with clear action @@ -387,7 +370,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } // Hidden tags - if (drawerData.tags != null && drawerData.tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) { + if (drawerData.tags.isNotEmpty() && appSettingsService.getHiddenTags().isNotEmpty()) { secondaryItem( withDivider = true, R.string.drawer_item_hidden_tags, @@ -398,13 +381,13 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar // Tags secondaryItem(withDivider = true, R.string.drawer_item_tags, DRAWER_ID_TAGS) - if (drawerData.tags == null && !loadedFromCache) { + if (drawerData.tags.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem() .apply { nameRes = R.string.drawer_error_loading_tags; isSelectable = false } ) } else { - handleTags(drawerData.tags!!) + handleTags(drawerData.tags) } // Sources @@ -412,7 +395,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar startActivity(Intent(v!!.context, SourcesActivity::class.java)) false } - if (drawerData.sources == null && !loadedFromCache) { + if (drawerData.sources.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem().apply { nameRes = R.string.drawer_error_loading_tags @@ -420,7 +403,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } ) } else { - handleSources(drawerData.sources!!) + handleSources(drawerData.sources) } // About action 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..ca9321f 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 @@ -410,11 +410,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() From dc8381b661c4a8181f38b80492566b8c21ddaa07 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 30 Sep 2022 15:00:25 +0200 Subject: [PATCH 3/7] Add missing string --- .../bou/amine/apps/readerforselfossv2/android/HomeActivity.kt | 2 +- androidApp/src/main/res/values/strings.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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 877994e..93f910c 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 @@ -398,7 +398,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar if (drawerData.sources.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem().apply { - nameRes = R.string.drawer_error_loading_tags + nameRes = R.string.drawer_error_loading_sources isSelectable = false } ) diff --git a/androidApp/src/main/res/values/strings.xml b/androidApp/src/main/res/values/strings.xml index 86978a0..88ba142 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 From 713ceb05bfe13676dd0fef8dbff422cbc65316dd Mon Sep 17 00:00:00 2001 From: davidoskky Date: Fri, 30 Sep 2022 15:07:17 +0200 Subject: [PATCH 4/7] Remove unnecessary data class --- .../android/HomeActivity.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) 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 93f910c..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 @@ -95,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) @@ -349,14 +347,15 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar ) CoroutineScope(Dispatchers.IO).launch { - val drawerData = DrawerData(repository.getTags(), repository.getSources()) + val tags = repository.getTags() + val sources = repository.getSources() runOnUiThread { - handleDrawerData(drawerData) + handleDrawerData(tags, sources) } } } - private fun handleDrawerData(drawerData: DrawerData) { + private fun handleDrawerData(tags: List, sources: List) { binding.mainDrawer.itemAdapter.clear() // Filters title with clear action @@ -370,24 +369,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } // Hidden tags - if (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.isEmpty()) { + 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 @@ -395,7 +394,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar startActivity(Intent(v!!.context, SourcesActivity::class.java)) false } - if (drawerData.sources.isEmpty()) { + if (sources.isEmpty()) { binding.mainDrawer.itemAdapter.add( SecondaryDrawerItem().apply { nameRes = R.string.drawer_error_loading_sources @@ -403,7 +402,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar } ) } else { - handleSources(drawerData.sources) + handleSources(sources) } // About action From ebef0b35112724b2aa4ba32f70fc1afb707bd3cc Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 1 Oct 2022 22:43:48 +0200 Subject: [PATCH 5/7] Start monitoring connectivity status when the repository is initiated. --- .../java/bou/amine/apps/readerforselfossv2/android/MyApp.kt | 2 -- .../amine/apps/readerforselfossv2/repository/RepositoryImpl.kt | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) 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 a33ac66..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,8 +75,6 @@ class MyApp : MultiDexApplication(), DIAware { ).show() } } - connectivityStatus.start() - } private fun handleNotificationChannels() { 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 ca9321f..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) From 0bcd55bd4e1bb8a1fd9959aab6fbba1a52689ff0 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 1 Oct 2022 22:51:09 +0200 Subject: [PATCH 6/7] Add translated strings --- androidApp/src/main/res/values-ca-rES/strings.xml | 1 + androidApp/src/main/res/values-de-rDE/strings.xml | 1 + androidApp/src/main/res/values-es-rES/strings.xml | 1 + androidApp/src/main/res/values-fa-rIR/strings.xml | 1 + androidApp/src/main/res/values-fr-rFR/strings.xml | 1 + androidApp/src/main/res/values-gl-rES/strings.xml | 1 + androidApp/src/main/res/values-in-rID/strings.xml | 1 + androidApp/src/main/res/values-it-rIT/strings.xml | 1 + androidApp/src/main/res/values-ko-rKR/strings.xml | 1 + androidApp/src/main/res/values-nl-rNL/strings.xml | 1 + androidApp/src/main/res/values-pt-rBR/strings.xml | 1 + androidApp/src/main/res/values-pt-rPT/strings.xml | 1 + androidApp/src/main/res/values-si-rLK/strings.xml | 1 + androidApp/src/main/res/values-tr-rTR/strings.xml | 1 + androidApp/src/main/res/values-zh-rCN/strings.xml | 1 + androidApp/src/main/res/values-zh-rTW/strings.xml | 1 + androidApp/src/main/res/values/strings.xml | 2 +- 17 files changed, 17 insertions(+), 1 deletion(-) 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 88ba142..0a69bb9 100644 --- a/androidApp/src/main/res/values/strings.xml +++ b/androidApp/src/main/res/values/strings.xml @@ -110,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 From c15bf440326ca4b769b2475859108ca0091704eb Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sun, 2 Oct 2022 01:01:39 +0200 Subject: [PATCH 7/7] Adjust repository tests --- .../amine/apps/readerforselfossv2/repository/RepositoryTest.kt | 2 ++ 1 file changed, 2 insertions(+) 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