|
|
@@ -227,8 +227,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
* 获取当前键盘信息
|
|
|
*/
|
|
|
fun getCurrentKeyboardInfo() {
|
|
|
- mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
- // 更新键盘名称
|
|
|
+ getCurrentKeyboardInfoWithDefault(onSuccess = {
|
|
|
_currentKeyboardInfo.value = KeyboardSelectModel(
|
|
|
id = it.id,
|
|
|
type = it.type,
|
|
|
@@ -250,7 +249,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
onFail: (String) -> Unit
|
|
|
) {
|
|
|
// 先获取当前键盘信息,得到键盘Id
|
|
|
- mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
+ getCurrentKeyboardInfoWithDefault(onSuccess = {
|
|
|
val keyboardId = it.id
|
|
|
// 查询该键盘下的人设列表
|
|
|
mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
|
|
|
@@ -347,4 +346,34 @@ class KeyboardViewModel : ViewModel() {
|
|
|
onSuccess.invoke()
|
|
|
}, onFail)
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取键盘信息,如果没有,则返回第一个键盘信息
|
|
|
+ */
|
|
|
+ fun getCurrentKeyboardInfoWithDefault(
|
|
|
+ onSuccess: (model: KeyboardSelectModel) -> Unit,
|
|
|
+ onFail: (String) -> Unit
|
|
|
+ ) {
|
|
|
+ mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
+ if (it.id.isNullOrBlank()) {
|
|
|
+ mKeyboardRepository.getKeyboardList(onSuccess = {
|
|
|
+ val defaultItem = it.keyboardInfos[0]
|
|
|
+ onSuccess.invoke(defaultItem)
|
|
|
+ }, onFail)
|
|
|
+ } else {
|
|
|
+ // 更新键盘
|
|
|
+ val item = KeyboardSelectModel(
|
|
|
+ id = it.id,
|
|
|
+ type = it.type,
|
|
|
+ name = it.name,
|
|
|
+ gender = it.gender,
|
|
|
+ birthday = it.birthday,
|
|
|
+ intimacy = it.intimacy,
|
|
|
+ imageUrl = it.imageUrl,
|
|
|
+ isSelect = it.isSelect
|
|
|
+ )
|
|
|
+ onSuccess.invoke(item)
|
|
|
+ }
|
|
|
+ }, onFail)
|
|
|
+ }
|
|
|
}
|