PR issues
This commit is contained in:
parent
5074dfe443
commit
81c6d972d7
|
|
@ -95,14 +95,14 @@ val selectorView = ListSelectionView(newContext)
|
|||
### Как использовать
|
||||
``` kotlin
|
||||
binding.tagItemLayout
|
||||
.setSpacing(16)
|
||||
.setSelectionType(SelectionType.MULTI_SELECT) // по умолчанию
|
||||
.isSingleLine(false) // по умолчанию
|
||||
.onPropertySelectedAction { filterProperty: FilterProperty ->
|
||||
//Do something
|
||||
}
|
||||
.build(getFilterItem())
|
||||
.Builder(getFilterItem())
|
||||
.setSpacing(16)
|
||||
.setSelectionType(SelectionType.MULTI_SELECT) // по умолчанию
|
||||
.isSingleLine(false) // по умолчанию
|
||||
.onPropertySelectedAction { filterProperty: FilterProperty ->
|
||||
//Do something
|
||||
}
|
||||
.build()
|
||||
```
|
||||
### Конфигурации
|
||||
* метод `setSelectionType(SelectionType)` конфигурирует тип выбора:
|
||||
|
|
@ -112,6 +112,7 @@ binding.tagItemLayout
|
|||
* `setTagLayout(Int)` устанавливает разметку для тега. Если не задано - то используется дефолтная разметка `layout_default_tag.xml`
|
||||
* `setMaxTagCount(Int)` позволяет ограничить количество отображаемых тегов. По умолчанию ограничения нет.
|
||||
* `setMoreTagLayout(Int, String)` устанавливает разметку для тега, который отображается для дополнительного тега. Если не указана - то тег не будет создан
|
||||
* `setSpacing(Int)`, `setSpacingHorizontal(Int`) и мsetSpacingVertical(Int)` можно использовать для настройки расстояния между тегами. По умолчанию - 0
|
||||
* `setSpacing(Int)`, `setSpacingHorizontal(Int)` и `setSpacingVertical(Int)` можно использовать для настройки расстояния между тегами. По умолчанию - 0
|
||||
* `onMoreValuesAction(FilterMoreAction)` и `onPropertySelectedAction(PropertySelectedAction)` используются для передачи колбэков на клик по тегу типа "Еще" и обычного тега соответственно
|
||||
* после вызова конфигурационных методов обязательно необходимо вызать метод `build(FilterItem)`
|
||||
* после вызова конфигурационных методов обязательно необходимо вызать метод `build()`
|
||||
* в Builder необходимо передать объект `filterItem: FilterItem`
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@ package ru.touchin.roboswag.base_filters.tags
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import ru.touchin.roboswag.base_filters.R
|
||||
import ru.touchin.roboswag.base_filters.SelectionType
|
||||
import ru.touchin.roboswag.base_filters.databinding.TagSelectionLayoutBinding
|
||||
import ru.touchin.roboswag.base_filters.tags.model.FilterItem
|
||||
import ru.touchin.roboswag.base_filters.tags.model.FilterProperty
|
||||
import ru.touchin.roboswag.components.utils.UiUtils
|
||||
|
|
@ -27,10 +24,9 @@ class TagLayoutView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : FrameLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val binding = TagSelectionLayoutBinding.inflate(LayoutInflater.from(context), this)
|
||||
private var filterItem: FilterItem by Delegates.notNull()
|
||||
|
||||
private var tagsContainer: ChipGroup = binding.multiLineTagGroup
|
||||
private var tagsContainer: ChipGroup by Delegates.notNull()
|
||||
|
||||
private var propertySelectedAction: PropertySelectedAction? = null
|
||||
private var moreValuesAction: FilterMoreAction? = null
|
||||
|
|
@ -44,82 +40,16 @@ class TagLayoutView @JvmOverloads constructor(
|
|||
private var tagLayout: Int = R.layout.layout_default_tag
|
||||
|
||||
private var moreTagText: String = ""
|
||||
private var maxTagCount: Int? = null
|
||||
private var maxTagCount = Int.MAX_VALUE
|
||||
|
||||
@LayoutRes
|
||||
private var moreTagLayout: Int? = null
|
||||
private var moreTagLayout: Int = tagLayout
|
||||
|
||||
fun onMoreValuesAction(action: FilterMoreAction) = apply {
|
||||
moreValuesAction = action
|
||||
}
|
||||
|
||||
fun onPropertySelectedAction(action: PropertySelectedAction) = apply {
|
||||
propertySelectedAction = action
|
||||
}
|
||||
|
||||
fun setMaxTagCount(count: Int) = apply {
|
||||
maxTagCount = count
|
||||
}
|
||||
|
||||
fun setSpacingHorizontal(horizontalSpacingDp: Int) = apply {
|
||||
tagSpacingHorizontalDp = horizontalSpacingDp
|
||||
}
|
||||
|
||||
fun setSpacingVertical(verticalSpacingDp: Int) = apply {
|
||||
tagSpacingVerticalDp = verticalSpacingDp
|
||||
}
|
||||
|
||||
fun setSpacing(value: Int) = apply {
|
||||
tagSpacingHorizontalDp = value
|
||||
tagSpacingVerticalDp = value
|
||||
}
|
||||
|
||||
fun setSelectionType(type: SelectionType) = apply {
|
||||
selectionType = type
|
||||
}
|
||||
|
||||
fun isSingleLine(value: Boolean) = apply {
|
||||
isSingleLine = value
|
||||
}
|
||||
|
||||
fun setTagLayout(@LayoutRes layoutId: Int) = apply {
|
||||
tagLayout = layoutId
|
||||
}
|
||||
|
||||
fun setMoreTagLayout(@LayoutRes layoutId: Int, text: String) = apply {
|
||||
moreTagLayout = layoutId
|
||||
moreTagText = text
|
||||
}
|
||||
|
||||
fun build(filterItem: FilterItem) {
|
||||
this.filterItem = filterItem
|
||||
tagsContainer = getTagView(isSingleLine)
|
||||
|
||||
with(tagsContainer) {
|
||||
removeAllViews()
|
||||
|
||||
this.isSingleLine = isSingleLine
|
||||
|
||||
chipSpacingHorizontal = tagSpacingHorizontalDp.px
|
||||
chipSpacingVertical = tagSpacingVerticalDp.px
|
||||
|
||||
val properties = maxTagCount
|
||||
?.let { count -> filterItem.properties.take(count) }
|
||||
?: filterItem.properties
|
||||
properties.forEach { property ->
|
||||
addView(createTag(property))
|
||||
}
|
||||
|
||||
if (maxTagCount != null && filterItem.properties.size > maxTagCount!!) {
|
||||
createMoreChip(filterItem)?.let { addView(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTagView(isSingleLine: Boolean): ChipGroup {
|
||||
binding.lineTagContainer.isVisible = isSingleLine
|
||||
binding.multiLineTagGroup.isVisible = !isSingleLine
|
||||
return if (isSingleLine) binding.singleLineTagGroup else binding.multiLineTagGroup
|
||||
private fun inflateAndGetChipGroup(isSingleLine: Boolean): ChipGroup {
|
||||
val layoutId = if (isSingleLine) R.layout.layout_single_line_tag_group else R.layout.layout_multi_line_tag_group
|
||||
return UiUtils.inflate(layoutId, this)
|
||||
.also { addView(it) }
|
||||
.findViewById(R.id.tag_group)
|
||||
}
|
||||
|
||||
private fun createTag(property: FilterProperty): TagView =
|
||||
|
|
@ -138,12 +68,11 @@ class TagLayoutView @JvmOverloads constructor(
|
|||
}
|
||||
} ?: throw IllegalArgumentException("Layout for tag must be extended from TagView")
|
||||
|
||||
private fun createMoreChip(filter: FilterItem): View? = moreTagLayout?.let {
|
||||
(UiUtils.inflate(it, this) as? TextView)?.apply {
|
||||
text = moreTagText
|
||||
setOnClickListener { moreValuesAction?.invoke(filter) }
|
||||
}
|
||||
}
|
||||
private fun createMoreChip(filter: FilterItem): View? =
|
||||
(UiUtils.inflate(moreTagLayout, this) as? TextView)?.apply {
|
||||
text = moreTagText
|
||||
setOnClickListener { moreValuesAction?.invoke(filter) }
|
||||
}
|
||||
|
||||
private fun clearCheck(selectedId: Int) {
|
||||
for (i in 0 until tagsContainer.childCount) {
|
||||
|
|
@ -164,4 +93,71 @@ class TagLayoutView @JvmOverloads constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner class Builder(private val filterItem: FilterItem) {
|
||||
|
||||
fun onMoreValuesAction(action: FilterMoreAction) = apply {
|
||||
moreValuesAction = action
|
||||
}
|
||||
|
||||
fun onPropertySelectedAction(action: PropertySelectedAction) = apply {
|
||||
propertySelectedAction = action
|
||||
}
|
||||
|
||||
fun setMaxTagCount(count: Int) = apply {
|
||||
maxTagCount = count
|
||||
}
|
||||
|
||||
fun setSpacingHorizontal(horizontalSpacingDp: Int) = apply {
|
||||
tagSpacingHorizontalDp = horizontalSpacingDp
|
||||
}
|
||||
|
||||
fun setSpacingVertical(verticalSpacingDp: Int) = apply {
|
||||
tagSpacingVerticalDp = verticalSpacingDp
|
||||
}
|
||||
|
||||
fun setSpacing(value: Int) = apply {
|
||||
tagSpacingHorizontalDp = value
|
||||
tagSpacingVerticalDp = value
|
||||
}
|
||||
|
||||
fun setSelectionType(type: SelectionType) = apply {
|
||||
selectionType = type
|
||||
}
|
||||
|
||||
fun isSingleLine(value: Boolean) = apply {
|
||||
isSingleLine = value
|
||||
}
|
||||
|
||||
fun setTagLayout(@LayoutRes layoutId: Int) = apply {
|
||||
tagLayout = layoutId
|
||||
}
|
||||
|
||||
fun setMoreTagLayout(@LayoutRes layoutId: Int, text: String) = apply {
|
||||
moreTagLayout = layoutId
|
||||
moreTagText = text
|
||||
}
|
||||
|
||||
fun build() {
|
||||
this@TagLayoutView.filterItem = filterItem
|
||||
tagsContainer = inflateAndGetChipGroup(isSingleLine)
|
||||
|
||||
with(tagsContainer) {
|
||||
removeAllViews()
|
||||
|
||||
this.isSingleLine = isSingleLine
|
||||
|
||||
chipSpacingHorizontal = tagSpacingHorizontalDp.px
|
||||
chipSpacingVertical = tagSpacingVerticalDp.px
|
||||
|
||||
filterItem.properties.take(maxTagCount).forEach { property ->
|
||||
addView(createTag(property))
|
||||
}
|
||||
|
||||
if (filterItem.properties.size > maxTagCount) {
|
||||
createMoreChip(filterItem)?.let { addView(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/tag_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:chipSpacing="8dp"
|
||||
app:selectionRequired="false"
|
||||
app:singleLine="false"
|
||||
app:singleSelection="true" />
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<HorizontalScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/line_tag_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/tag_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:selectionRequired="true" />
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/multi_line_tag_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:selectionRequired="false"
|
||||
app:singleLine="false"
|
||||
app:singleSelection="true"
|
||||
app:chipSpacing="8dp"/>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/line_tag_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/single_line_tag_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:selectionRequired="true"/>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
</merge>
|
||||
Loading…
Reference in New Issue