CircleImageView: directly transform the text into appropriate Drawable String
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
davidoskky 2023-03-25 21:58:36 +01:00
parent 1ad529067d
commit 10ab67d071
4 changed files with 7 additions and 9 deletions

View File

@ -9,7 +9,6 @@ import android.widget.ImageView.ScaleType
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding import bou.amine.apps.readerforselfossv2.android.databinding.CardItemBinding
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener
import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.bitmapCenterCrop
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
@ -80,7 +79,7 @@ class ItemCardAdapter(
} }
if (itm.getIcon(repository.baseUrl).isEmpty()) { if (itm.getIcon(repository.baseUrl).isEmpty()) {
binding.sourceImage.setBackgroundAndText(itm.title.getHtmlDecoded(), itm.title.getHtmlDecoded().toTextDrawableString()) binding.sourceImage.setBackgroundAndText(itm.sourcetitle.getHtmlDecoded())
} else { } else {
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage) c.circularDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage)
} }

View File

@ -7,7 +7,6 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding import bou.amine.apps.readerforselfossv2.android.databinding.ListItemBinding
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener import bou.amine.apps.readerforselfossv2.android.utils.LinkOnTouchListener
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
@ -52,7 +51,7 @@ class ItemListAdapter(
if (itm.getThumbnail(repository.baseUrl).isEmpty()) { if (itm.getThumbnail(repository.baseUrl).isEmpty()) {
if (itm.getIcon(repository.baseUrl).isEmpty()) { if (itm.getIcon(repository.baseUrl).isEmpty()) {
binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded(), itm.title.getHtmlDecoded().toTextDrawableString()) binding.itemImage.setBackgroundAndText(itm.sourcetitle.getHtmlDecoded())
} else { } else {
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage) c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
} }

View File

@ -13,7 +13,6 @@ import androidx.recyclerview.widget.RecyclerView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.UpsertSourceActivity import bou.amine.apps.readerforselfossv2.android.UpsertSourceActivity
import bou.amine.apps.readerforselfossv2.android.databinding.SourceListItemBinding import bou.amine.apps.readerforselfossv2.android.databinding.SourceListItemBinding
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
import bou.amine.apps.readerforselfossv2.model.SelfossModel import bou.amine.apps.readerforselfossv2.model.SelfossModel
import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.repository.Repository
@ -46,7 +45,7 @@ class SourcesListAdapter(
val itm = items[position] val itm = items[position]
if (itm.getIcon(repository.baseUrl).isEmpty()) { if (itm.getIcon(repository.baseUrl).isEmpty()) {
binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded(), itm.title.getHtmlDecoded().toTextDrawableString()) binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded())
} else { } else {
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage) c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
} }

View File

@ -8,6 +8,7 @@ import android.view.View
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.TextView import android.widget.TextView
import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.R
import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString
import com.google.android.material.imageview.ShapeableImageView import com.google.android.material.imageview.ShapeableImageView
import kotlin.math.abs import kotlin.math.abs
@ -46,13 +47,13 @@ class CircleImageView @JvmOverloads constructor(
textView = view.findViewById(R.id.circleText) textView = view.findViewById(R.id.circleText)
} }
fun setBackgroundAndText(colorIdentifier: String, text: String) { fun setBackgroundAndText(text: String) {
val circleDrawable = GradientDrawable() val circleDrawable = GradientDrawable()
val color = colorFromIdentifier(colorIdentifier) val color = colorFromIdentifier(text)
circleDrawable.setColor(color) circleDrawable.setColor(color)
imageView.setImageDrawable(circleDrawable) imageView.setImageDrawable(circleDrawable)
textView.text = text textView.text = text.toTextDrawableString()
} }
private fun colorFromIdentifier(key: String): Int { private fun colorFromIdentifier(key: String): Int {