You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.2 KiB
94 lines
2.2 KiB
package com.gyf.csams.uikit
|
|
|
|
import androidx.compose.material.SnackbarDuration
|
|
import androidx.lifecycle.LiveData
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.ViewModel
|
|
import com.orhanobut.logger.Logger
|
|
|
|
interface FormLength {
|
|
val nameLengthError: String
|
|
}
|
|
|
|
abstract class FormName<T>(val formDesc: String) {
|
|
protected val _formValue = MutableLiveData<T>()
|
|
val formValue: LiveData<T> = _formValue
|
|
val formPlaceholder = "请输入$formDesc"
|
|
|
|
abstract fun onChange(value: T)
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 文本输入框控制
|
|
*
|
|
* @property textLength
|
|
* @constructor
|
|
*
|
|
* @param formDesc
|
|
*/
|
|
open class StringForm(formDesc: String, val textLength: Int) :
|
|
FormName<String>(formDesc = formDesc),
|
|
FormLength {
|
|
|
|
constructor(formDesc: String, textLength: Int, value: String) : this(
|
|
formDesc = formDesc,
|
|
textLength = textLength
|
|
) {
|
|
_formValue.value = value
|
|
}
|
|
|
|
override val nameLengthError = "${formDesc}不能超过最大长度$textLength"
|
|
|
|
override fun onChange(value: String) {
|
|
if (value.length > textLength) {
|
|
_formValue.value = value.slice(IntRange(0, textLength - 1))
|
|
} else {
|
|
_formValue.value = value
|
|
}
|
|
Logger.i("${formDesc}更新值:${_formValue.value}")
|
|
}
|
|
}
|
|
|
|
|
|
data class SnackBar(
|
|
val message: String?,
|
|
val actionLabel: String? = null,
|
|
val duration: SnackbarDuration = SnackbarDuration.Short,
|
|
val callback: () -> Unit?
|
|
)
|
|
|
|
/**
|
|
* snackbar
|
|
*
|
|
*/
|
|
class ScaffoldModel : ViewModel() {
|
|
private val _data = MutableLiveData<SnackBar>()
|
|
val data: LiveData<SnackBar> = _data
|
|
|
|
fun update(message: String? = null, actionLabel: String? = null, callback: () -> Unit? = {}) {
|
|
if (message == null) {
|
|
_data.value = null
|
|
} else {
|
|
_data.value =
|
|
SnackBar(message = message, actionLabel = actionLabel, callback = callback)
|
|
}
|
|
}
|
|
}
|
|
|
|
abstract class ScrollList<T> : ViewModel() {
|
|
protected val _data = MutableLiveData<MutableList<T>>(mutableListOf())
|
|
val data: LiveData<MutableList<T>> = _data
|
|
|
|
abstract val initSize: Int
|
|
|
|
//加载列表
|
|
abstract fun load()
|
|
|
|
//加载更多数据
|
|
abstract fun loadMore(callback: (message: String) -> Unit)
|
|
}
|
|
|
|
|
|
|
|
|