From 10ab67d071b85e7f7555fa0f32248809ea871608 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sat, 25 Mar 2023 21:58:36 +0100 Subject: [PATCH] CircleImageView: directly transform the text into appropriate Drawable String --- .../readerforselfossv2/android/adapters/ItemCardAdapter.kt | 3 +-- .../readerforselfossv2/android/adapters/ItemListAdapter.kt | 3 +-- .../android/adapters/SourcesListAdapter.kt | 3 +-- .../readerforselfossv2/android/utils/CircleImageView.kt | 7 ++++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index 3e98d9c..11f6f62 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -9,7 +9,6 @@ import android.widget.ImageView.ScaleType import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R 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.glide.bitmapCenterCrop import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable @@ -80,7 +79,7 @@ class ItemCardAdapter( } if (itm.getIcon(repository.baseUrl).isEmpty()) { - binding.sourceImage.setBackgroundAndText(itm.title.getHtmlDecoded(), itm.title.getHtmlDecoded().toTextDrawableString()) + binding.sourceImage.setBackgroundAndText(itm.sourcetitle.getHtmlDecoded()) } else { c.circularDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage) } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index 1cbe9ba..c557b10 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -7,7 +7,6 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R 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.glide.circularDrawable import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl @@ -52,7 +51,7 @@ class ItemListAdapter( if (itm.getThumbnail(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 { c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage) } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt index 8315eb6..731ec51 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/SourcesListAdapter.kt @@ -13,7 +13,6 @@ import androidx.recyclerview.widget.RecyclerView import bou.amine.apps.readerforselfossv2.android.R import bou.amine.apps.readerforselfossv2.android.UpsertSourceActivity 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.model.SelfossModel import bou.amine.apps.readerforselfossv2.repository.Repository @@ -46,7 +45,7 @@ class SourcesListAdapter( val itm = items[position] if (itm.getIcon(repository.baseUrl).isEmpty()) { - binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded(), itm.title.getHtmlDecoded().toTextDrawableString()) + binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded()) } else { c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage) } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/CircleImageView.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/CircleImageView.kt index 2ebd1d4..afe81ce 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/CircleImageView.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/utils/CircleImageView.kt @@ -8,6 +8,7 @@ import android.view.View import android.widget.RelativeLayout import android.widget.TextView import bou.amine.apps.readerforselfossv2.android.R +import bou.amine.apps.readerforselfossv2.android.model.toTextDrawableString import com.google.android.material.imageview.ShapeableImageView import kotlin.math.abs @@ -46,13 +47,13 @@ class CircleImageView @JvmOverloads constructor( textView = view.findViewById(R.id.circleText) } - fun setBackgroundAndText(colorIdentifier: String, text: String) { + fun setBackgroundAndText(text: String) { val circleDrawable = GradientDrawable() - val color = colorFromIdentifier(colorIdentifier) + val color = colorFromIdentifier(text) circleDrawable.setColor(color) imageView.setImageDrawable(circleDrawable) - textView.text = text + textView.text = text.toTextDrawableString() } private fun colorFromIdentifier(key: String): Int {