fix: handle three characters lenght hexcode colors.

This commit is contained in:
aminecmi 2024-01-03 21:35:58 +01:00
parent 390c2d0cf3
commit 14ff4dbd05
2 changed files with 13 additions and 2 deletions

View File

@ -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.databinding.FilterFragmentBinding
import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.android.sendSilentlyWithAcraWithName
import bou.amine.apps.readerforselfossv2.repository.Repository 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.getHtmlDecoded
import bou.amine.apps.readerforselfossv2.utils.getIcon import bou.amine.apps.readerforselfossv2.utils.getIcon
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
@ -147,9 +148,9 @@ class FilterSheetFragment : BottomSheetDialogFragment(), DIAware {
val gd = GradientDrawable() val gd = GradientDrawable()
val gdColor = val gdColor =
try { try {
Color.parseColor(tag.color) Color.parseColor(tag.getColorHexCode())
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
e.sendSilentlyWithAcraWithName("color issue " + tag.color) e.sendSilentlyWithAcraWithName("color issue " + tag.color + " / " + tag.getColorHexCode())
resources.getColor(R.color.colorPrimary) resources.getColor(R.color.colorPrimary)
} }
gd.setColor(gdColor) gd.setColor(gdColor)

View File

@ -73,3 +73,13 @@ fun SelfossModel.Item.toEntity(): ITEM =
this.tags.joinToString(","), this.tags.joinToString(","),
this.author, 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
}