From fb8f81a4c80742f734821488a333223414497fd7 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 14:05:57 +0200 Subject: [PATCH 1/6] One call less. --- .../bou/amine/apps/readerforselfossv2/android/HomeActivity.kt | 3 --- 1 file changed, 3 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 4dea1f9..934d9eb 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 @@ -143,9 +143,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar handleSwipeRefreshLayout() - getElementsAccordingToTab() - - CoroutineScope(Dispatchers.Main).launch { repository.tryToCacheItemsAndGetNewOnes() } -- 2.34.1 From 0f000ea359ac5d9146d7a870971752dc87f60468 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:53:39 +0200 Subject: [PATCH 2/6] Only sort if the data is from the DB. This speeds things a little bit. --- .../readerforselfossv2/repository/RepositoryImpl.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 db9a789..e5dcc2f 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 @@ -48,6 +48,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap suspend fun getNewerItems(): ArrayList { // TODO: Use the updatedSince parameter var fetchedItems: SelfossModel.StatusAndData> = SelfossModel.StatusAndData.error() + var fromDB = false if (isNetworkAvailable()) { fetchedItems = api.getItems( displayedItems.type, @@ -59,6 +60,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap ) } else { if (appSettingsService.isItemCachingEnabled()) { + fromDB = true fetchedItems = SelfossModel.StatusAndData.succes( getDBItems().filter { displayedItems == ItemType.ALL || @@ -71,7 +73,9 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap if (fetchedItems.success && fetchedItems.data != null) { items = ArrayList(fetchedItems.data!!) - sortItems() + if (fromDB) { + items.sortByDescending { dateUtils.parseDate(it.datetime) } + } } return items } @@ -92,7 +96,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap if (fetchedItems.success && fetchedItems.data != null) { items.addAll(fetchedItems.data!!) - sortItems() } return items } @@ -118,10 +121,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap } } - private fun sortItems() { - items.sortByDescending { dateUtils.parseDate(it.datetime) } - } - suspend fun reloadBadges(): Boolean { var success = false if (isNetworkAvailable()) { -- 2.34.1 From 90b52232aba163445380e53fad89c1dbb7bb15d1 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:54:11 +0200 Subject: [PATCH 3/6] Updating ktor and changing the engine. This speeds things a little bit too. --- shared/build.gradle.kts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 0a348ad..6240aee 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -28,12 +28,12 @@ kotlin { sourceSets { val commonMain by getting { dependencies { - implementation("io.ktor:ktor-client-core:2.0.1") - implementation("io.ktor:ktor-client-content-negotiation:2.0.1") - implementation("io.ktor:ktor-serialization-kotlinx-json:2.0.1") - implementation("io.ktor:ktor-client-logging:2.0.1") + implementation("io.ktor:ktor-client-core:2.1.1") + implementation("io.ktor:ktor-client-content-negotiation:2.1.1") + implementation("io.ktor:ktor-serialization-kotlinx-json:2.1.1") + implementation("io.ktor:ktor-client-logging:2.1.1") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0") - implementation("io.ktor:ktor-client-auth:2.0.1") + implementation("io.ktor:ktor-client-auth:2.1.1") implementation("org.jsoup:jsoup:1.14.3") //Dependency Injection @@ -60,7 +60,7 @@ kotlin { } val androidMain by getting { dependencies { - implementation("io.ktor:ktor-client-android:2.0.1") + implementation("io.ktor:ktor-client-okhttp:2.1.1") // Sql implementation(SqlDelight.android) @@ -94,7 +94,7 @@ kotlin { iosX64Test.dependsOn(this) iosArm64Test.dependsOn(this) dependencies { - implementation("io.ktor:ktor-client-ios:2.0.1") + implementation("io.ktor:ktor-client-ios:2.1.1") } //iosSimulatorArm64Test.dependsOn(this) } -- 2.34.1 From d9ef301e0f5a0b0e786dd2b09cf1e8fd4fb94a72 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:58:05 +0200 Subject: [PATCH 4/6] Warning. --- androidApp/src/main/res/layout/activity_add_source.xml | 2 +- androidApp/src/main/res/layout/activity_home.xml | 2 +- androidApp/src/main/res/layout/activity_image.xml | 2 +- androidApp/src/main/res/layout/activity_login.xml | 2 +- androidApp/src/main/res/layout/activity_reader.xml | 2 +- androidApp/src/main/res/layout/activity_sources.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/androidApp/src/main/res/layout/activity_add_source.xml b/androidApp/src/main/res/layout/activity_add_source.xml index 7bc31e1..9998207 100644 --- a/androidApp/src/main/res/layout/activity_add_source.xml +++ b/androidApp/src/main/res/layout/activity_add_source.xml @@ -18,7 +18,7 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - app:theme="@style/ToolBarStyle" + android:theme="@style/ToolBarStyle" app:popupTheme="?attr/toolbarPopupTheme" /> diff --git a/androidApp/src/main/res/layout/activity_home.xml b/androidApp/src/main/res/layout/activity_home.xml index 7a84128..f194740 100644 --- a/androidApp/src/main/res/layout/activity_home.xml +++ b/androidApp/src/main/res/layout/activity_home.xml @@ -32,7 +32,7 @@ android:id="@+id/toolBar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - app:theme="@style/ToolBarStyle" + android:theme="@style/ToolBarStyle" app:popupTheme="?attr/toolbarPopupTheme" /> diff --git a/androidApp/src/main/res/layout/activity_image.xml b/androidApp/src/main/res/layout/activity_image.xml index d2d43ef..5703d1c 100644 --- a/androidApp/src/main/res/layout/activity_image.xml +++ b/androidApp/src/main/res/layout/activity_image.xml @@ -17,7 +17,7 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:popupTheme="?attr/toolbarPopupTheme" - app:theme="@style/ToolBarStyle" /> + android:theme="@style/ToolBarStyle" /> diff --git a/androidApp/src/main/res/layout/activity_login.xml b/androidApp/src/main/res/layout/activity_login.xml index 4c37ea3..6fe8d2f 100644 --- a/androidApp/src/main/res/layout/activity_login.xml +++ b/androidApp/src/main/res/layout/activity_login.xml @@ -14,7 +14,7 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - app:theme="@style/ToolBarStyle" + android:theme="@style/ToolBarStyle" app:popupTheme="?attr/toolbarPopupTheme" /> diff --git a/androidApp/src/main/res/layout/activity_reader.xml b/androidApp/src/main/res/layout/activity_reader.xml index b2cfa5a..a423f5c 100644 --- a/androidApp/src/main/res/layout/activity_reader.xml +++ b/androidApp/src/main/res/layout/activity_reader.xml @@ -18,7 +18,7 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:popupTheme="?attr/toolbarPopupTheme" - app:theme="@style/ToolBarStyle" /> + android:theme="@style/ToolBarStyle" /> diff --git a/androidApp/src/main/res/layout/activity_sources.xml b/androidApp/src/main/res/layout/activity_sources.xml index b0dc30a..274b27d 100644 --- a/androidApp/src/main/res/layout/activity_sources.xml +++ b/androidApp/src/main/res/layout/activity_sources.xml @@ -14,7 +14,7 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - app:theme="@style/ToolBarStyle" + android:theme="@style/ToolBarStyle" app:popupTheme="?attr/toolbarPopupTheme" /> -- 2.34.1 From 8106faa45cb2ae6a379746c53b28b5d4d2ff136c Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 16:05:07 +0200 Subject: [PATCH 5/6] Only fetch intems if item caching is enabled. --- .../amine/apps/readerforselfossv2/android/HomeActivity.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 934d9eb..50f212c 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 @@ -143,8 +143,11 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar handleSwipeRefreshLayout() - CoroutineScope(Dispatchers.Main).launch { - repository.tryToCacheItemsAndGetNewOnes() + + if (appSettingsService.isItemCachingEnabled()) { + CoroutineScope(Dispatchers.Main).launch { + repository.tryToCacheItemsAndGetNewOnes() + } } } -- 2.34.1 From 144067d5b6fbec11f3f265ff70169bb18c5437ca Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 16:16:40 +0200 Subject: [PATCH 6/6] This helps a lot. --- androidApp/src/main/res/xml/pref_general.xml | 2 +- .../amine/apps/readerforselfossv2/service/AppSettingsService.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/res/xml/pref_general.xml b/androidApp/src/main/res/xml/pref_general.xml index 6643cb7..7ea909a 100644 --- a/androidApp/src/main/res/xml/pref_general.xml +++ b/androidApp/src/main/res/xml/pref_general.xml @@ -6,7 +6,7 @@