mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Minor clean
This commit is contained in:
parent
9a9b127e9f
commit
1a7ad4fd68
@ -2,10 +2,10 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.BottomSheetItemBinding
|
||||
import com.github.libretube.obj.BottomSheetItem
|
||||
import com.github.libretube.ui.extensions.setDrawables
|
||||
import com.github.libretube.ui.viewholders.BottomSheetViewHolder
|
||||
|
||||
class BottomSheetAdapter(
|
||||
@ -23,19 +23,10 @@ class BottomSheetAdapter(
|
||||
|
||||
override fun onBindViewHolder(holder: BottomSheetViewHolder, position: Int) {
|
||||
val item = items[position]
|
||||
holder.binding.sheetItem.apply {
|
||||
holder.binding.root.apply {
|
||||
val current = item.getCurrent()
|
||||
text = if (current != null) "${item.title} ($current)" else item.title
|
||||
setCompoundDrawablesRelative(
|
||||
if (item.drawable != null) {
|
||||
AppCompatResources.getDrawable(context, item.drawable)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null
|
||||
)
|
||||
setDrawables(start = item.drawable)
|
||||
|
||||
setOnClickListener {
|
||||
item.onClick.invoke()
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.github.libretube.ui.extensions
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.widget.TextViewCompat
|
||||
|
||||
fun TextView.setDrawables(
|
||||
start: Int? = null,
|
||||
top: Int? = null,
|
||||
end: Int? = null,
|
||||
bottom: Int? = null
|
||||
) {
|
||||
setDrawables(
|
||||
start?.let { AppCompatResources.getDrawable(context, it) },
|
||||
top?.let { AppCompatResources.getDrawable(context, it) },
|
||||
end?.let { AppCompatResources.getDrawable(context, it) },
|
||||
bottom?.let { AppCompatResources.getDrawable(context, it) }
|
||||
)
|
||||
}
|
||||
|
||||
fun TextView.setDrawables(
|
||||
start: Drawable? = null,
|
||||
top: Drawable? = null,
|
||||
end: Drawable? = null,
|
||||
bottom: Drawable? = null
|
||||
) {
|
||||
TextViewCompat.setCompoundDrawablesRelative(this, start, top, end, bottom)
|
||||
}
|
@ -11,6 +11,7 @@ import com.github.libretube.R
|
||||
|
||||
/**
|
||||
* TextView with custom sizable drawable support.
|
||||
* It may only be used for icons as it gives same width and height to the drawable.
|
||||
*/
|
||||
class DrawableTextView(
|
||||
context: Context,
|
||||
@ -101,7 +102,7 @@ class DrawableTextView(
|
||||
)
|
||||
}
|
||||
|
||||
fun setDrawableStartDimension(
|
||||
fun setDrawablesDimension(
|
||||
start: Float = drawableStartDimen,
|
||||
top: Float = drawableTopDimen,
|
||||
end: Float = drawableEndDimen,
|
||||
@ -111,5 +112,7 @@ class DrawableTextView(
|
||||
drawableTopDimen = top
|
||||
drawableEndDimen = end
|
||||
drawableBottomDimen = bottom
|
||||
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.appcompat.widget.AppCompatTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/sheet_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
|
Loading…
x
Reference in New Issue
Block a user