A simple text choice for your e-commerce store client. Written in Kotlin + coroutines.
minSdkVersion 16
- AndroidX
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation "com.github.tim4dev:textbar:VERSION"
}
<dev.tim4.textbar.TextBar
android:id="@+id/textBarDemo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:textBarTextColor="#650000"
app:textBarColorChecked="#4FFF2C"
app:textBarColorStroke="#999999"
app:textBarColorUnchecked="#fff"
app:textBarColumns="7"
app:textBarMarginsDp="2dp"
app:textBarSizeSp="20sp" />
val texts = listOf(
TextRectangleData(text = "S", tag = 111),
TextRectangleData(text = "L", isChecked = true, tag = 222),
TextRectangleData(text = "XL", tag = 333),
TextRectangleData(text = "XXL", tag = 444),
TextRectangleData(text = "39", tag = 555)
)
val textBarDemo = findViewById<TextBar>(R.id.textBarDemo)
textBarDemo.setupTextBar(texts)
// NOTE. GlobalScope is used here only as an example app.
GlobalScope.launch(Dispatchers.Main) {
textBarDemo.valueFlow.collect { data ->
Log.d(TAG, "collect = $data")
log.text = "${data.text}, ${data.isChecked}, ${data.tag}"
}
}