From 14ff4dbd0546bacc3576ea05f5e9786946987f74 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Wed, 3 Jan 2024 21:35:58 +0100 Subject: [PATCH] fix: handle three characters lenght hexcode colors. --- .../android/fragments/FilterSheetFragment.kt | 5 +++-- .../amine/apps/readerforselfossv2/utils/EntityUtils.kt | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt index 5b56504..cca1876 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/FilterSheetFragment.kt @@ -17,6 +17,7 @@ import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.databinding.FilterFragmentBinding import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.repository.Repository +import bou.amine.apps.readerforselfossv2.utils.getColorHexCode import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded import bou.amine.apps.readerforselfossv2.utils.getIcon import com.bumptech.glide.Glide @@ -147,9 +148,9 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware { val gd = GradientDrawable() val gdColor = try { - Color.parseColor(tag.color) + Color.parseColor(tag.getColorHexCode()) } catch (e: IllegalArgumentException) { - e.sendSilentlyWithAcraWithName("color issue " + tag.color) + e.sendSilentlyWithAcraWithName("color issue " + tag.color + " / " + tag.getColorHexCode()) resources.getColor(R.color.colorPrimary) } gd.setColor(gdColor) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt index 57e9c96..60efc42 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt @@ -73,3 +73,13 @@ fun SelfossModel.Item.toEntity(): ITEM = this.tags.joinToString(","), this.author, ) + +fun SelfossModel.Tag.getColorHexCode(): String = + if (this.color.length == 4) { // #000 + val char1 = this.color.get(1) + val char2 = this.color.get(2) + val char3 = this.color.get(3) + "#$char1$char1$char2$char2$char3$char3" + } else { + this.color + } \ No newline at end of file