From bd96c67788e54efa9415ce355136e34f176c5a77 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 24 Sep 2022 21:54:50 +0200 Subject: [PATCH 01/18] 2.18 serialization issues fix. Fixes #61. --- .../readerforselfossv2/model/SelfossModel.kt | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index e392786..2543979 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -2,7 +2,14 @@ package bou.amine.apps.readerforselfossv2.model import bou.amine.apps.readerforselfossv2.utils.DateUtils import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded +import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* class SelfossModel { @@ -50,6 +57,7 @@ class SelfossModel { data class Source( val id: Int, val title: String, + @Serializable(with = TagsListSerializer::class) val tags: List, val spout: String, val error: String, @@ -62,12 +70,15 @@ class SelfossModel { val datetime: String, val title: String, val content: String, + @Serializable(with = BooleanSerializer::class) var unread: Boolean, + @Serializable(with = BooleanSerializer::class) var starred: Boolean, val thumbnail: String?, val icon: String?, val link: String, val sourcetitle: String, + @Serializable(with = TagsListSerializer::class) val tags: List ) { // TODO: maybe find a better way to handle these kind of urls @@ -106,6 +117,38 @@ class SelfossModel { } } + // TODO: this seems to be super slow. + object TagsListSerializer : KSerializer> { + override fun deserialize(decoder: Decoder): List { + return when(val json = ((decoder as JsonDecoder).decodeJsonElement())) { + is JsonArray -> json.toList().map { it.toString() } + else -> json.toString().split(",") + } + + } + + override val descriptor: SerialDescriptor + get() = PrimitiveSerialDescriptor("tags", PrimitiveKind.STRING) + + override fun serialize(encoder: Encoder, value: List) { + TODO("Not yet implemented") + } + } + + object BooleanSerializer : KSerializer { + override fun deserialize(decoder: Decoder): Boolean { + val json = ((decoder as JsonDecoder).decodeJsonElement()).jsonPrimitive + return json.booleanOrNull ?: json.int == 1 + } + + override val descriptor: SerialDescriptor + get() = PrimitiveSerialDescriptor("b", PrimitiveKind.BOOLEAN) + + override fun serialize(encoder: Encoder, value: Boolean) { + TODO("Not yet implemented") + } + } + class StatusAndData(val success: Boolean, val data: T? = null) { companion object { fun succes(d: T): StatusAndData { @@ -117,4 +160,4 @@ class SelfossModel { } } } -} \ No newline at end of file +} From 8823cc6c6cb981a3b856adef00c73b4fb1b43497 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 25 Sep 2022 21:39:57 +0200 Subject: [PATCH 02/18] Cleaning. --- androidApp/build.gradle.kts | 2 +- .../apps/readerforselfossv2/android/AddSourceActivity.kt | 2 +- .../amine/apps/readerforselfossv2/android/LoginActivity.kt | 2 +- .../apps/readerforselfossv2/android/adapters/ItemsAdapter.kt | 4 ++-- .../amine/apps/readerforselfossv2/android/utils/LinksUtils.kt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index ed8c38c..00e1abc 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -30,7 +30,7 @@ fun gitVersion(): String { println("Tag found on current commit") execWithOutput("git -C ../ describe --contains HEAD") } - return process.replace("'", "").substring(1).replace("\\.", "").trim() + return process.replace("^0", "").replace("'", "").substring(1).replace("\\.", "").trim() } fun versionCodeFromGit(): Int { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt index 3cec99e..137764b 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt @@ -84,7 +84,7 @@ class AddSourceActivity : AppCompatActivity(), DIAware { super.onResume() val baseUrl = appSettingsService.getBaseUrl() - if (baseUrl.isEmpty() || baseUrl.isBaseUrlInvalid(this@AddSourceActivity)) { + if (baseUrl.isEmpty() || baseUrl.isBaseUrlInvalid()) { mustLoginToAddSource() } else { handleSpoutsSpinner(binding.spoutsSpinner, binding.progress, binding.formContainer) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index bc32762..657feb6 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -122,7 +122,7 @@ class LoginActivity : AppCompatActivity(), DIAware { var cancel = false var focusView: View? = null - if (url.isBaseUrlInvalid(this@LoginActivity)) { + if (url.isBaseUrlInvalid()) { binding.urlView.error = getString(R.string.login_url_problem) focusView = binding.urlView cancel = true diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index 4c43c85..d66be45 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -30,7 +30,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte updateItems(this.items) } - private fun unmarkSnackbar(i: SelfossModel.Item, position: Int) { + private fun unmarkSnackbar(position: Int) { val s = Snackbar .make( app.findViewById(R.id.coordLayout), @@ -87,7 +87,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte notifyItemChanged(position) } if (showSnackbar) { - unmarkSnackbar(i, position) + unmarkSnackbar(position) } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt index 600864b..20cc998 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/LinksUtils.kt @@ -163,7 +163,7 @@ private fun openInBrowser(linkDecoded: String, app: Activity) { fun String.isUrlValid(): Boolean = this.toHttpUrlOrNull() != null && Patterns.WEB_URL.matcher(this).matches() -fun String.isBaseUrlInvalid(ctx: Context): Boolean { +fun String.isBaseUrlInvalid(): Boolean { val baseUrl = this.toHttpUrlOrNull() var existsAndEndsWithSlash = false if (baseUrl != null) { From 91aed5a77792d33952cc499740ed4c4cf1911b77 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 25 Sep 2022 22:19:47 +0200 Subject: [PATCH 03/18] Hacky way to fix #55. --- .../bou/amine/apps/readerforselfossv2/android/HomeActivity.kt | 1 + 1 file changed, 1 insertion(+) 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 b1d5ce6..4dea1f9 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,6 +95,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { appSettingsService.refreshUserSettings() + recreate() } override val di by closestDI() From fb8f81a4c80742f734821488a333223414497fd7 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 14:05:57 +0200 Subject: [PATCH 04/18] 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() } From 0f000ea359ac5d9146d7a870971752dc87f60468 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:53:39 +0200 Subject: [PATCH 05/18] 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()) { From 90b52232aba163445380e53fad89c1dbb7bb15d1 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:54:11 +0200 Subject: [PATCH 06/18] 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) } From d9ef301e0f5a0b0e786dd2b09cf1e8fd4fb94a72 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 15:58:05 +0200 Subject: [PATCH 07/18] 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" /> From 8106faa45cb2ae6a379746c53b28b5d4d2ff136c Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 16:05:07 +0200 Subject: [PATCH 08/18] 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() + } } } From 144067d5b6fbec11f3f265ff70169bb18c5437ca Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Sep 2022 16:16:40 +0200 Subject: [PATCH 09/18] 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 @@ Date: Tue, 27 Sep 2022 10:21:42 +0200 Subject: [PATCH 10/18] Daark theme working. --- androidApp/build.gradle.kts | 2 - .../android/AddSourceActivity.kt | 5 -- .../android/HomeActivity.kt | 32 ++-------- .../android/LoginActivity.kt | 3 + .../apps/readerforselfossv2/android/MyApp.kt | 11 ---- .../android/ReaderActivity.kt | 5 -- .../android/SourcesActivity.kt | 5 -- .../android/settings/SettingsActivity.kt | 22 ------- .../android/themes/AppColors.kt | 54 ++--------------- .../main/res/drawable/background_splash.xml | 7 ++- .../main/res/layout/activity_add_source.xml | 7 +-- .../src/main/res/layout/activity_home.xml | 10 ++-- .../src/main/res/layout/activity_image.xml | 4 +- .../src/main/res/layout/activity_login.xml | 4 +- .../src/main/res/layout/activity_reader.xml | 4 +- .../src/main/res/layout/activity_settings.xml | 2 +- .../src/main/res/layout/activity_sources.xml | 4 +- .../src/main/res/menu/settings_theme.xml | 10 ---- .../src/main/res/values-night/styles.xml | 13 +++++ androidApp/src/main/res/values/attrs.xml | 1 + androidApp/src/main/res/values/colors.xml | 2 - androidApp/src/main/res/values/styles.xml | 58 ++----------------- androidApp/src/main/res/xml/pref_theme.xml | 24 -------- .../service/AppSettingsService.kt | 13 +++++ 24 files changed, 67 insertions(+), 235 deletions(-) delete mode 100644 androidApp/src/main/res/menu/settings_theme.xml create mode 100644 androidApp/src/main/res/values-night/styles.xml diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 00e1abc..665c3af 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -167,8 +167,6 @@ dependencies { implementation("com.mikepenz:materialdrawer:8.4.5") // Themes - implementation("com.52inc:scoops:1.0.0") - implementation("com.jaredrummler:colorpicker:1.1.0") implementation("com.github.rubensousa:floatingtoolbar:1.5.1") // Pager diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt index 137764b..f199700 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt @@ -13,7 +13,6 @@ import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid import bou.amine.apps.readerforselfossv2.model.NetworkUnavailableException import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -42,10 +41,6 @@ class AddSourceActivity : AppCompatActivity(), DIAware { setContentView(view) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - val drawable = binding.nameInput.background drawable.setTint(appColors.colorAccent) 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 50f212c..3acb5f1 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,6 +15,9 @@ 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 @@ -43,7 +46,6 @@ import com.ashokvarma.bottomnavigation.BottomNavigationItem import com.ashokvarma.bottomnavigation.TextBadgeItem import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.ftinc.scoop.Scoop import com.mikepenz.aboutlibraries.LibsBuilder import com.mikepenz.materialdrawer.holder.BadgeStyle import com.mikepenz.materialdrawer.holder.ColorHolder @@ -95,7 +97,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar private val settingsLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { appSettingsService.refreshUserSettings() - recreate() + AppCompatDelegate.setDefaultNightMode(if (appSettingsService.isDarkThemeEnabled()) MODE_NIGHT_YES else MODE_NIGHT_NO) } override val di by closestDI() @@ -127,8 +129,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar setContentView(view) - handleThemeBinding() - setSupportActionBar(binding.toolBar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setHomeButtonEnabled(true) @@ -234,27 +234,24 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar tabNewBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) tabArchiveBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) tabStarredBadge = TextBadgeItem() .setText("") .setHideOnSelect(false).hide(false) - .setBackgroundColor(appColors.colorPrimary) val tabNew = BottomNavigationItem( R.drawable.ic_tab_fiber_new_black_24dp, getString(R.string.tab_new) - ).setActiveColor(appColors.colorAccent) + ) .setBadgeItem(tabNewBadge) val tabArchive = BottomNavigationItem( R.drawable.ic_tab_archive_black_24dp, getString(R.string.tab_read) - ).setActiveColor(appColors.colorAccentDark) + ) .setBadgeItem(tabArchiveBadge) val tabStarred = BottomNavigationItem( @@ -270,7 +267,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar .setFirstSelectedPosition(0) .initialise() binding.bottomBar.setMode(BottomNavigationBar.MODE_SHIFTING) - binding.bottomBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC) if (fromTabShortcut) { binding.bottomBar.selectTab(elementsShown.position - 1) @@ -284,8 +280,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar handleDrawerItems() - handleThemeUpdate() - reloadLayoutManager() if (appSettingsService.isInfiniteLoadingEnabled()) { @@ -310,20 +304,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar customTabActivityHelper.unbindCustomTabsService(this) } - private fun handleThemeBinding() { - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - } - - private fun handleThemeUpdate() { - - val scoop = Scoop.getInstance() - scoop.update(Toppings.PRIMARY.value, appColors.colorPrimary) - - scoop.update(Toppings.PRIMARY_DARK.value, appColors.colorPrimaryDark) - } - private fun initDrawer() { DrawerImageLoader.init(object : AbstractDrawerImageLoader() { override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index 657feb6..af70159 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -12,6 +12,7 @@ import android.view.inputmethod.EditorInfo import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlInvalid @@ -41,6 +42,8 @@ class LoginActivity : AppCompatActivity(), DIAware { appColors = AppColors(this@LoginActivity) super.onCreate(savedInstanceState) + AppCompatDelegate.setDefaultNightMode(if (appSettingsService.isDarkThemeEnabled()) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) + binding = ActivityLoginBinding.inflate(layoutInflater) val view = binding.root 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 4e7c2d4..0268a1e 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 @@ -21,7 +21,6 @@ import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions -import com.ftinc.scoop.Scoop import com.github.ln_12.library.ConnectivityStatus import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader import com.mikepenz.materialdrawer.util.DrawerImageLoader @@ -54,8 +53,6 @@ class MyApp : MultiDexApplication(), DIAware { initDrawerImageLoader() - initTheme() - tryToHandleBug() handleNotificationChannels() @@ -117,14 +114,6 @@ class MyApp : MultiDexApplication(), DIAware { }) } - private fun initTheme() { - Scoop.waffleCone() - .addFlavor(getString(R.string.default_theme), R.style.NoBar, true) - .addFlavor(getString(R.string.default_dark_theme), R.style.NoBarDark, false) - .setSharedPreferences(PreferenceManager.getDefaultSharedPreferences(this)) - .initialize() - } - private fun tryToHandleBug() { val oldHandler = Thread.getDefaultUncaughtExceptionHandler() diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index ad6a23c..0bb6186 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -17,7 +17,6 @@ import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -62,10 +61,6 @@ class ReaderActivity : AppCompatActivity(), DIAware { setContentView(view) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolBar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - setSupportActionBar(binding.toolBar) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt index d28b290..15d93bd 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt @@ -12,7 +12,6 @@ import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository -import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -33,10 +32,6 @@ class SourcesActivity : AppCompatActivity(), DIAware { binding = ActivitySourcesBinding.inflate(layoutInflater) val view = binding.root - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - super.onCreate(savedInstanceState) setContentView(view) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index 67148bb..dc0e046 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -22,7 +22,6 @@ import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBin import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.service.AppSettingsService -import com.ftinc.scoop.Scoop private const val TITLE_TAG = "settingsActivityTitle" @@ -31,15 +30,8 @@ class SettingsActivity : AppCompatActivity(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false)) { - setTheme(R.style.NoBarDark) - } val binding = ActivitySettingsBinding.inflate(layoutInflater) - val scoop = Scoop.getInstance() - scoop.bind(this, Toppings.PRIMARY.value, binding.toolbar) - scoop.bindStatusBar(this, Toppings.PRIMARY_DARK.value) - setContentView(binding.root) if (savedInstanceState == null) { supportFragmentManager @@ -171,20 +163,6 @@ class SettingsActivity : AppCompatActivity(), setPreferencesFromResource(R.xml.pref_theme, rootKey) setHasOptionsMenu(true) } - - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.settings_theme, menu) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.itemId - if (id == R.id.clear) { - AppColors.resetColors() - requireActivity().recreate() - } - return super.onOptionsItemSelected(item) - } } class LinksPreferenceFragment : PreferenceFragmentCompat() { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt index bd01677..59619b1 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/themes/AppColors.kt @@ -7,66 +7,20 @@ import com.russhwolf.settings.Settings class AppColors(a: Activity) { - @ColorInt val colorPrimary: Int - @ColorInt val colorPrimaryDark: Int - @ColorInt val colorAccent: Int - @ColorInt val colorAccentDark: Int - @ColorInt val colorBackground: Int - @ColorInt val textColor: Int + @ColorInt val colorPrimary: Int = a.resources.getColor(R.color.colorPrimary) + @ColorInt val colorPrimaryDark: Int = a.resources.getColor(R.color.colorPrimaryDark) + @ColorInt val colorAccent: Int = a.resources.getColor(R.color.colorAccent) + @ColorInt val colorAccentDark: Int = a.resources.getColor(R.color.colorAccentDark) val isDarkTheme: Boolean init { val settings = Settings() - - colorPrimary = - settings.getInt( - "color_primary", - a.resources.getColor(R.color.colorPrimary) - ) - colorPrimaryDark = - settings.getInt( - "color_primary_dark", - a.resources.getColor(R.color.colorPrimaryDark) - ) - colorAccent = - settings.getInt( - "color_accent", - a.resources.getColor(R.color.colorAccent) - ) - colorAccentDark = - settings.getInt( - "color_accent_dark", - a.resources.getColor(R.color.colorAccentDark) - ) isDarkTheme = settings.getBoolean( "dark_theme", false ) - colorBackground = if (isDarkTheme) { - a.setTheme(R.style.NoBarDark) - a.resources.getColor(R.color.darkBackground) - } else { - a.setTheme(R.style.NoBar) - a.resources.getColor(R.color.grey_50) - } - - textColor = if (isDarkTheme) { - a.resources.getColor(R.color.white) - } else { - a.resources.getColor(R.color.grey_900) - } } - companion object { - fun resetColors() { - val settings = Settings() - settings.remove("color_primary") - settings.remove("color_primary_dark") - settings.remove("color_accent") - settings.remove("color_accent_dark") - settings.remove("dark_theme") - } - } } diff --git a/androidApp/src/main/res/drawable/background_splash.xml b/androidApp/src/main/res/drawable/background_splash.xml index 32241ec..bef5ded 100644 --- a/androidApp/src/main/res/drawable/background_splash.xml +++ b/androidApp/src/main/res/drawable/background_splash.xml @@ -1,8 +1,11 @@ - + + + + + + + /> @@ -107,8 +107,7 @@ app:layout_constraintTop_toBottomOf="@+id/tags" app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent" - android:layout_height="40dp" - android:theme="@style/App.Spinner"/> + android:layout_height="40dp"/>