chore: replace textDrawable library (#136)
## Types of changes - [x] I have read the **CONTRIBUTING** document. - [x] My code follows the code style of this project. - [ ] I have updated the documentation accordingly. - [ ] I have added tests to cover my changes. - [x] All new and existing tests passed. - [x] This is **NOT** translation related. This closes issue #120 Removed the dependency `com.amulyakhare.textdrawable` and slightly simplified the logic required to set circular images. Co-authored-by: davidoskky <davidoskky@yahoo.it> Reviewed-on: https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/pulls/136 Co-authored-by: davidoskky <davidoskky@hidden.hidden> Co-committed-by: davidoskky <davidoskky@hidden.hidden>
This commit is contained in:
parent
00eb3333fe
commit
8d7d3174aa
@ -142,7 +142,6 @@ dependencies {
|
||||
|
||||
// Material-ish things
|
||||
implementation("com.ashokvarma.android:bottom-navigation-bar:2.2.0")
|
||||
implementation("com.amulyakhare:com.amulyakhare.textdrawable:1.0.1")
|
||||
|
||||
// glide
|
||||
kapt("com.github.bumptech.glide:compiler:4.15.0")
|
||||
|
@ -9,10 +9,9 @@ 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.circularBitmapDrawable
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.openInBrowserAsNewTask
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.shareLink
|
||||
@ -22,8 +21,6 @@ import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
||||
import bou.amine.apps.readerforselfossv2.utils.getThumbnail
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -38,7 +35,6 @@ class ItemCardAdapter(
|
||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
||||
) : ItemsAdapter<ItemCardAdapter.ViewHolder>() {
|
||||
private val c: Context = app.baseContext
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private val imageMaxHeight: Int =
|
||||
c.resources.getDimension(R.dimen.card_image_max_height).toInt()
|
||||
|
||||
@ -83,16 +79,9 @@ class ItemCardAdapter(
|
||||
}
|
||||
|
||||
if (itm.getIcon(repository.baseUrl).isEmpty()) {
|
||||
val color = generator.getColor(itm.title.getHtmlDecoded())
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.title.getHtmlDecoded().toTextDrawableString(), color)
|
||||
binding.sourceImage.setImageDrawable(drawable)
|
||||
binding.sourceImage.setBackgroundAndText(itm.sourcetitle.getHtmlDecoded())
|
||||
} else {
|
||||
c.circularBitmapDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage)
|
||||
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.sourceImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,8 @@ 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.bitmapCenterCrop
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularBitmapDrawable
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.openItemUrl
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||
@ -18,8 +16,6 @@ import bou.amine.apps.readerforselfossv2.service.AppSettingsService
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
||||
import bou.amine.apps.readerforselfossv2.utils.getThumbnail
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import org.kodein.di.DI
|
||||
import org.kodein.di.android.closestDI
|
||||
import org.kodein.di.instance
|
||||
@ -29,7 +25,6 @@ class ItemListAdapter(
|
||||
override var items: ArrayList<SelfossModel.Item>,
|
||||
override val updateItems: (ArrayList<SelfossModel.Item>) -> Unit
|
||||
) : ItemsAdapter<ItemListAdapter.ViewHolder>() {
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private val c: Context = app.baseContext
|
||||
|
||||
override val di: DI by closestDI(app)
|
||||
@ -56,20 +51,12 @@ class ItemListAdapter(
|
||||
if (itm.getThumbnail(repository.baseUrl).isEmpty()) {
|
||||
|
||||
if (itm.getIcon(repository.baseUrl).isEmpty()) {
|
||||
val color = generator.getColor(itm.title.getHtmlDecoded())
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.title.getHtmlDecoded().toTextDrawableString(), color)
|
||||
|
||||
binding.itemImage.setImageDrawable(drawable)
|
||||
binding.itemImage.setBackgroundAndText(itm.sourcetitle.getHtmlDecoded())
|
||||
} else {
|
||||
c.circularBitmapDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
|
||||
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
|
||||
}
|
||||
} else {
|
||||
c.bitmapCenterCrop(itm.getThumbnail(repository.baseUrl), binding.itemImage)
|
||||
c.circularDrawable(itm.getThumbnail(repository.baseUrl), binding.itemImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,14 @@ import android.widget.Button
|
||||
import android.widget.Toast
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import bou.amine.apps.readerforselfossv2.android.UpsertSourceActivity
|
||||
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.circularBitmapDrawable
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.glide.circularDrawable
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
import bou.amine.apps.readerforselfossv2.repository.Repository
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import bou.amine.apps.readerforselfossv2.utils.getIcon
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -34,7 +31,6 @@ class SourcesListAdapter(
|
||||
private val items: ArrayList<SelfossModel.SourceDetail>
|
||||
) : RecyclerView.Adapter<SourcesListAdapter.ViewHolder>(), DIAware {
|
||||
private val c: Context = app.baseContext
|
||||
private val generator: ColorGenerator = ColorGenerator.MATERIAL
|
||||
private lateinit var binding: SourceListItemBinding
|
||||
|
||||
override val di: DI by closestDI(app)
|
||||
@ -49,16 +45,9 @@ class SourcesListAdapter(
|
||||
val itm = items[position]
|
||||
|
||||
if (itm.getIcon(repository.baseUrl).isEmpty()) {
|
||||
val color = generator.getColor(itm.title.getHtmlDecoded())
|
||||
|
||||
val drawable =
|
||||
TextDrawable
|
||||
.builder()
|
||||
.round()
|
||||
.build(itm.title.getHtmlDecoded().toTextDrawableString(), color)
|
||||
binding.itemImage.setImageDrawable(drawable)
|
||||
binding.itemImage.setBackgroundAndText(itm.title.getHtmlDecoded())
|
||||
} else {
|
||||
c.circularBitmapDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
|
||||
c.circularDrawable(itm.getIcon(repository.baseUrl), binding.itemImage)
|
||||
}
|
||||
|
||||
if (!itm.error.isNullOrBlank()) {
|
||||
|
@ -0,0 +1,62 @@
|
||||
package bou.amine.apps.readerforselfossv2.android.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
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
|
||||
|
||||
class CircleImageView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : RelativeLayout(context, attrs, defStyleAttr) {
|
||||
val view: View
|
||||
val imageView: ShapeableImageView
|
||||
val textView: TextView
|
||||
|
||||
private val colorScheme = listOf(
|
||||
-0x1a8c8d,
|
||||
-0xf9d6e,
|
||||
-0x459738,
|
||||
-0x6a8a33,
|
||||
-0x867935,
|
||||
-0x9b4a0a,
|
||||
-0xb03c09,
|
||||
-0xb22f1f,
|
||||
-0xb24954,
|
||||
-0x7e387c,
|
||||
-0x512a7f,
|
||||
-0x759b,
|
||||
-0x2b1ea9,
|
||||
-0x2ab1,
|
||||
-0x48b3,
|
||||
-0x5e7781,
|
||||
-0x6f5b52
|
||||
)
|
||||
|
||||
init {
|
||||
view = LayoutInflater.from(context).inflate(R.layout.circle_image_view, this, true)
|
||||
imageView = view.findViewById(R.id.circleImage)
|
||||
textView = view.findViewById(R.id.circleText)
|
||||
}
|
||||
|
||||
fun setBackgroundAndText(text: String) {
|
||||
val circleDrawable = GradientDrawable()
|
||||
val color = colorFromIdentifier(text)
|
||||
circleDrawable.setColor(color)
|
||||
imageView.setImageDrawable(circleDrawable)
|
||||
|
||||
textView.text = text.toTextDrawableString()
|
||||
}
|
||||
|
||||
private fun colorFromIdentifier(key: String): Int {
|
||||
return colorScheme[abs(key.hashCode()) % colorScheme.size]
|
||||
}
|
||||
}
|
@ -3,10 +3,9 @@ package bou.amine.apps.readerforselfossv2.android.utils.glide
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.widget.ImageView
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory
|
||||
import bou.amine.apps.readerforselfossv2.android.utils.CircleImageView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.bumptech.glide.request.target.BitmapImageViewTarget
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
@ -18,21 +17,13 @@ fun Context.bitmapCenterCrop(url: String, iv: ImageView) =
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(iv)
|
||||
|
||||
fun Context.circularBitmapDrawable(url: String, iv: ImageView) =
|
||||
fun Context.circularDrawable(url: String, view: CircleImageView) {
|
||||
view.textView.text =""
|
||||
|
||||
Glide.with(this)
|
||||
.asBitmap()
|
||||
.load(url)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(object : BitmapImageViewTarget(iv) {
|
||||
override fun setResource(resource: Bitmap?) {
|
||||
val circularBitmapDrawable = RoundedBitmapDrawableFactory.create(
|
||||
resources,
|
||||
resource
|
||||
)
|
||||
circularBitmapDrawable.isCircular = true
|
||||
iv.setImageDrawable(circularBitmapDrawable)
|
||||
}
|
||||
})
|
||||
.into(view.imageView)
|
||||
}
|
||||
|
||||
fun getBitmapInputStream(bitmap:Bitmap,compressFormat: Bitmap.CompressFormat): InputStream {
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
|
@ -39,7 +39,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/itemImage">
|
||||
|
||||
<ImageView
|
||||
<bou.amine.apps.readerforselfossv2.android.utils.CircleImageView
|
||||
android:id="@+id/sourceImage"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
|
26
androidApp/src/main/res/layout/circle_image_view.xml
Normal file
26
androidApp/src/main/res/layout/circle_image_view.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/circleImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
app:shapeAppearanceOverlay="@style/circleImageView"
|
||||
app:srcCompat="@drawable/background_splash" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/circleText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:ellipsize="none"
|
||||
android:gravity="center"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/white"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="20sp"
|
||||
android:typeface="normal" />
|
||||
</RelativeLayout>
|
@ -5,7 +5,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
<bou.amine.apps.readerforselfossv2.android.utils.CircleImageView
|
||||
android:id="@+id/itemImage"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
|
@ -25,7 +25,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<ImageView
|
||||
<bou.amine.apps.readerforselfossv2.android.utils.CircleImageView
|
||||
android:id="@+id/itemImage"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
|
@ -32,4 +32,10 @@
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
</style>
|
||||
|
||||
<style name="circleImageView" parent="">
|
||||
<item name="cornerFamily">rounded</item>
|
||||
<item name="cornerSize">50%</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user