|
@@ -3,12 +3,10 @@ package com.atmob.keyboard_android.mvvm.viewmodel
|
|
|
import androidx.lifecycle.LiveData
|
|
import androidx.lifecycle.LiveData
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.ViewModel
|
|
|
-import com.atmob.keyboard_android.R
|
|
|
|
|
import com.atmob.keyboard_android.enums.HelpMode
|
|
import com.atmob.keyboard_android.enums.HelpMode
|
|
|
import com.atmob.keyboard_android.enums.KeyboardGlobalType
|
|
import com.atmob.keyboard_android.enums.KeyboardGlobalType
|
|
|
import com.atmob.keyboard_android.model.KeyboardSelectModel
|
|
import com.atmob.keyboard_android.model.KeyboardSelectModel
|
|
|
import com.atmob.keyboard_android.mvvm.repository.KeyboardRepository
|
|
import com.atmob.keyboard_android.mvvm.repository.KeyboardRepository
|
|
|
-import com.atmob.keyboard_android.util.ContextUtil
|
|
|
|
|
import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
|
|
import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
|
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.CharacterListResp
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.CharacterListResp
|
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.PrologueListResp.PrologueListItem
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.PrologueListResp.PrologueListItem
|
|
@@ -68,11 +66,10 @@ class KeyboardViewModel : ViewModel() {
|
|
|
val keyboardGlobalType: LiveData<KeyboardGlobalType> = _keyboardGlobalType
|
|
val keyboardGlobalType: LiveData<KeyboardGlobalType> = _keyboardGlobalType
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 键盘名称
|
|
|
|
|
|
|
+ * 当前键盘信息
|
|
|
*/
|
|
*/
|
|
|
- private val _keyboardName =
|
|
|
|
|
- MutableLiveData(ContextUtil.getContext().resources.getString(R.string.common_keyboard))
|
|
|
|
|
- val keyboardName: LiveData<String> = _keyboardName
|
|
|
|
|
|
|
+ private val _currentKeyboardInfo = MutableLiveData<KeyboardSelectModel>()
|
|
|
|
|
+ val currentKeyboardInfo: LiveData<KeyboardSelectModel> = _currentKeyboardInfo
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 当前选中的开场白Tab
|
|
* 当前选中的开场白Tab
|
|
@@ -206,21 +203,42 @@ class KeyboardViewModel : ViewModel() {
|
|
|
onFail: (msg: String) -> Unit
|
|
onFail: (msg: String) -> Unit
|
|
|
) {
|
|
) {
|
|
|
mKeyboardRepository.selectedKeyboard(selectModel.id, onSuccess = {
|
|
mKeyboardRepository.selectedKeyboard(selectModel.id, onSuccess = {
|
|
|
- // 更新键盘名称
|
|
|
|
|
- _keyboardName.value = selectModel.name
|
|
|
|
|
|
|
+ // 更新键盘信息
|
|
|
|
|
+ _currentKeyboardInfo.value = selectModel
|
|
|
onSuccess.invoke(it)
|
|
onSuccess.invoke(it)
|
|
|
}, onFail)
|
|
}, onFail)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 获取当前键盘信息
|
|
|
|
|
+ */
|
|
|
|
|
+ fun getCurrentKeyboardInfo() {
|
|
|
|
|
+ mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
|
|
+ // 更新键盘名称
|
|
|
|
|
+ _currentKeyboardInfo.value = 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
|
|
|
|
|
+ )
|
|
|
|
|
+ }, onFail = {})
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 获取人设列表
|
|
* 获取人设列表
|
|
|
*/
|
|
*/
|
|
|
fun getCharacterList(
|
|
fun getCharacterList(
|
|
|
onSuccess: (CharacterListResp) -> Unit,
|
|
onSuccess: (CharacterListResp) -> Unit,
|
|
|
onFail: (String) -> Unit
|
|
onFail: (String) -> Unit
|
|
|
) {
|
|
) {
|
|
|
- mKeyboardRepository.getCurrentKeyboardId(onSuccess = {
|
|
|
|
|
- val keyboardId = it.id ?: ""
|
|
|
|
|
|
|
+ // 先获取当前键盘信息,得到键盘Id
|
|
|
|
|
+ mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
|
|
+ val keyboardId = it.id
|
|
|
|
|
+ // 查询该键盘下的人设列表
|
|
|
mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
|
|
mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
|
|
|
}, onFail)
|
|
}, onFail)
|
|
|
}
|
|
}
|