选中UI刷新和抽象
This commit is contained in:
parent
2426f6b8bd
commit
cdc13082de
|
|
@ -10,7 +10,7 @@ import com.dylanc.loadingstateview.BgColorType
|
||||||
import com.remax.visualnovel.app.base.BaseBindingFragment
|
import com.remax.visualnovel.app.base.BaseBindingFragment
|
||||||
import com.remax.visualnovel.databinding.FragmentMainActorBinding
|
import com.remax.visualnovel.databinding.FragmentMainActorBinding
|
||||||
import com.remax.visualnovel.utils.Routers
|
import com.remax.visualnovel.utils.Routers
|
||||||
import com.remax.visualnovel.widget.custom.TagItem
|
import com.remax.visualnovel.widget.custom.AbsTagBean
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlin.getValue
|
import kotlin.getValue
|
||||||
|
|
||||||
|
|
@ -42,22 +42,22 @@ class ActorListFragment : BaseBindingFragment<FragmentMainActorBinding>() {
|
||||||
with(binding) {
|
with(binding) {
|
||||||
// 模拟数据
|
// 模拟数据
|
||||||
val tags = listOf(
|
val tags = listOf(
|
||||||
TagItem("1", "Youth"),
|
ActorTagBean("1", "Youth"),
|
||||||
TagItem("2", "Lolita"),
|
ActorTagBean("2", "Lolita"),
|
||||||
TagItem("2", "Lolita2"),
|
ActorTagBean("2", "Lolita2"),
|
||||||
TagItem("3", "Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
|
ActorTagBean("3", "Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
|
||||||
TagItem("3", "ggggggggggg CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
|
ActorTagBean("3", "ggggggggggg CEO ABCDEFG Overbearing CEO ABCDEFG Overbearing CEO ABCDEFG"),
|
||||||
TagItem("4", "Uncle"),
|
ActorTagBean("4", "Uncle"),
|
||||||
TagItem("5", "Character Status"),
|
ActorTagBean("5", "Character Status"),
|
||||||
TagItem("6", "Imouto"),
|
ActorTagBean("6", "Imouto"),
|
||||||
TagItem("7", "Fanwork"),
|
ActorTagBean("7", "Fanwork"),
|
||||||
TagItem("8", "LastLine"),
|
ActorTagBean("8", "LastLine"),
|
||||||
)
|
)
|
||||||
|
|
||||||
tagFlowLayout.setTagDataList(tags)
|
tagFlowLayout.setTagDataList(tags)
|
||||||
|
|
||||||
tagFlowLayout.setOnTagClickListener { tag ->
|
tagFlowLayout.setOnTagClickListener { tag ->
|
||||||
Toast.makeText(context, "Clicked: ${tag.text}", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "Clicked: ${tag.showStr}", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
tagFlowLayout.setOnExpandStateChangeListener { isExpanded ->
|
tagFlowLayout.setOnExpandStateChangeListener { isExpanded ->
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.remax.visualnovel.ui.main.actor
|
||||||
|
|
||||||
|
import com.remax.visualnovel.widget.custom.AbsTagBean
|
||||||
|
|
||||||
|
data class ActorTagBean(val tagId: String, override val showStr: String) : AbsTagBean(showStr) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.remax.visualnovel.widget.custom
|
package com.remax.visualnovel.widget.custom
|
||||||
|
|
||||||
data class TagItem(
|
abstract class AbsTagBean(
|
||||||
val id: String,
|
open val showStr: String,
|
||||||
val text: String,
|
|
||||||
var isSelected: Boolean = false
|
var isSelected: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
@ -17,6 +17,7 @@ import com.remax.visualnovel.extension.spToPx
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import androidx.core.content.withStyledAttributes
|
import androidx.core.content.withStyledAttributes
|
||||||
|
import kotlin.collections.mutableListOf
|
||||||
|
|
||||||
class TagFlowLayout2 @JvmOverloads constructor(
|
class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
|
|
@ -29,6 +30,7 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
private var verticalSpacing = 8f.dpToPx()
|
private var verticalSpacing = 8f.dpToPx()
|
||||||
private var textSize = 12f.spToPx()
|
private var textSize = 12f.spToPx()
|
||||||
private var textColor = context.resources.getColor(R.color.tag_text_color)
|
private var textColor = context.resources.getColor(R.color.tag_text_color)
|
||||||
|
private var textColorSelected = context.resources.getColor(R.color.white)
|
||||||
private var tagBackground: Drawable? = null
|
private var tagBackground: Drawable? = null
|
||||||
private var maxLinesWhileShrink = 1
|
private var maxLinesWhileShrink = 1
|
||||||
private var eachLineMaxTagNum = 2
|
private var eachLineMaxTagNum = 2
|
||||||
|
|
@ -43,12 +45,12 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
private var eachLineAvailableWidth = 0
|
private var eachLineAvailableWidth = 0
|
||||||
|
|
||||||
// 数据
|
// 数据
|
||||||
private val tagItems = mutableListOf<TagItem>()
|
private val tagItems = mutableListOf<AbsTagBean>()
|
||||||
private val tagViews = mutableListOf<TextView>()
|
private val tagViews = mutableListOf<TextView>()
|
||||||
private lateinit var expandIcon: ImageView
|
private lateinit var expandIcon: ImageView
|
||||||
|
|
||||||
// 监听器
|
// 监听器
|
||||||
private var onTagClickListener: ((TagItem) -> Unit)? = null
|
private var onTagClickListener: ((AbsTagBean) -> Unit)? = null
|
||||||
private var onExpandStateChangeListener: ((Boolean) -> Unit)? = null
|
private var onExpandStateChangeListener: ((Boolean) -> Unit)? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
@ -113,7 +115,7 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun setTagDataList(tags: List<TagItem>) {
|
fun setTagDataList(tags: List<AbsTagBean>) {
|
||||||
tagItems.clear()
|
tagItems.clear()
|
||||||
tagViews.forEach { removeView(it) }
|
tagViews.forEach { removeView(it) }
|
||||||
tagViews.clear()
|
tagViews.clear()
|
||||||
|
|
@ -128,9 +130,9 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTagView(tag: TagItem): TextView {
|
private fun createTagView(tag: AbsTagBean): TextView {
|
||||||
return TextView(context).apply {
|
return TextView(context).apply {
|
||||||
text = tag.text
|
text = tag.showStr
|
||||||
setTextColor(textColor)
|
setTextColor(textColor)
|
||||||
textSize = textSize / resources.displayMetrics.scaledDensity
|
textSize = textSize / resources.displayMetrics.scaledDensity
|
||||||
setPadding(10.dpToPx(), 7.dpToPx(), 10.dpToPx(), 7.dpToPx())
|
setPadding(10.dpToPx(), 7.dpToPx(), 10.dpToPx(), 7.dpToPx())
|
||||||
|
|
@ -142,6 +144,13 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
|
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
onTagClickListener?.invoke(tag)
|
onTagClickListener?.invoke(tag)
|
||||||
|
with(tag) {
|
||||||
|
isSelected = !isSelected
|
||||||
|
}
|
||||||
|
|
||||||
|
setTextColor(if (tag.isSelected) textColorSelected else textColor)
|
||||||
|
setBackgroundResource(if (tag.isSelected) R.drawable.tag_flow_item_bg_selected else R.drawable.tag_flow_item_bg)
|
||||||
|
requestLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -289,7 +298,7 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
expandIcon.setImageDrawable(indicator)
|
expandIcon.setImageDrawable(indicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnTagClickListener(listener: (TagItem) -> Unit) {
|
fun setOnTagClickListener(listener: (AbsTagBean) -> Unit) {
|
||||||
onTagClickListener = listener
|
onTagClickListener = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,5 +326,9 @@ class TagFlowLayout2 @JvmOverloads constructor(
|
||||||
requestLayout()
|
requestLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSelectedTagList() : List<AbsTagBean> {
|
||||||
|
return tagItems.filter { it.isSelected }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle" >
|
||||||
|
<corners android:radius="15dp" />
|
||||||
|
<solid android:color="@color/tag_bg_color_selected" />
|
||||||
|
</shape>
|
||||||
|
|
@ -183,6 +183,7 @@
|
||||||
|
|
||||||
<!-- new added -->
|
<!-- new added -->
|
||||||
<color name="tag_bg_color">#ffbac5d2</color>
|
<color name="tag_bg_color">#ffbac5d2</color>
|
||||||
|
<color name="tag_bg_color_selected">#ff0065ff</color>
|
||||||
<color name="tag_text_color">#ffe5f1ff</color>
|
<color name="tag_text_color">#ffe5f1ff</color>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue