|
|
@@ -6,13 +6,13 @@ import androidx.lifecycle.ViewModel
|
|
|
import com.atmob.keyboard_android.enums.HelpMode
|
|
|
import com.atmob.keyboard_android.enums.KeyboardGlobalType
|
|
|
import com.atmob.keyboard_android.enums.KeyboardType
|
|
|
-import com.atmob.keyboard_android.model.KeyboardSelectModel
|
|
|
import com.atmob.keyboard_android.mvvm.repository.KeyboardRepository
|
|
|
import com.atmob.keyboard_android.util.LogUtil
|
|
|
import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
|
|
|
import com.atmob.keyboard_android.util.bridge.model.req.SuperReplyReq
|
|
|
import com.atmob.keyboard_android.util.bridge.model.req.SuperSpeakReq
|
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.CharacterListResp.CharacterInfo
|
|
|
+import com.atmob.keyboard_android.util.bridge.model.resp.KeyboardInfo
|
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.PrologueListResp.PrologueListItem
|
|
|
import com.atmob.keyboard_android.util.bridge.model.resp.PrologueListResp.Topic
|
|
|
import com.atmob.keyboard_android.util.error.ErrorHandler
|
|
|
@@ -79,8 +79,8 @@ class KeyboardViewModel : ViewModel() {
|
|
|
/**
|
|
|
* 当前键盘信息
|
|
|
*/
|
|
|
- private val _currentKeyboardInfo = MutableLiveData<KeyboardSelectModel>()
|
|
|
- val currentKeyboardInfo: LiveData<KeyboardSelectModel> = _currentKeyboardInfo
|
|
|
+ private val _currentKeyboardInfo = MutableLiveData<KeyboardInfo>()
|
|
|
+ val currentKeyboardInfo: LiveData<KeyboardInfo> = _currentKeyboardInfo
|
|
|
|
|
|
/**
|
|
|
* 当前选中的开场白Tab
|
|
|
@@ -128,8 +128,8 @@ class KeyboardViewModel : ViewModel() {
|
|
|
/**
|
|
|
* 键盘选择列表数据
|
|
|
*/
|
|
|
- private val _keyboardList = MutableLiveData<List<KeyboardSelectModel>>()
|
|
|
- val keyboardList: LiveData<List<KeyboardSelectModel>> = _keyboardList
|
|
|
+ private val _keyboardList = MutableLiveData<List<KeyboardInfo>>()
|
|
|
+ val keyboardList: LiveData<List<KeyboardInfo>> = _keyboardList
|
|
|
|
|
|
// ----------------------------------- 更新状态方法 -----------------------------------
|
|
|
|
|
|
@@ -235,8 +235,11 @@ class KeyboardViewModel : ViewModel() {
|
|
|
fun getKeyboardList() {
|
|
|
mKeyboardRepository.getKeyboardList(onSuccess = {
|
|
|
val infos = it.keyboardInfos
|
|
|
+ val keyboardList = infos.map {
|
|
|
+ fixKeyboardSelectField(it)
|
|
|
+ }.toList()
|
|
|
// 如果所有都没选中,则默认选中通用键盘
|
|
|
- val hasSelectKeyboard = infos.filter {
|
|
|
+ val hasSelectKeyboard = keyboardList.filter {
|
|
|
it.isSelect == true
|
|
|
}.toList().isNotEmpty()
|
|
|
if (!hasSelectKeyboard) {
|
|
|
@@ -258,7 +261,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
/**
|
|
|
* 更新当前键盘信息
|
|
|
*/
|
|
|
- fun updateCurrentKeyboardInfo(keyboardInfo: KeyboardSelectModel) {
|
|
|
+ fun updateCurrentKeyboardInfo(keyboardInfo: KeyboardInfo) {
|
|
|
_currentKeyboardInfo.value = keyboardInfo
|
|
|
}
|
|
|
|
|
|
@@ -268,10 +271,10 @@ class KeyboardViewModel : ViewModel() {
|
|
|
* @param selectModel 键盘选择信息
|
|
|
*/
|
|
|
fun selectedKeyboard(
|
|
|
- selectModel: KeyboardSelectModel,
|
|
|
+ selectModel: KeyboardInfo,
|
|
|
onSuccess: (resultObj: EmptyResp) -> Unit
|
|
|
) {
|
|
|
- mKeyboardRepository.selectedKeyboard(selectModel.id, onSuccess = {
|
|
|
+ mKeyboardRepository.selectedKeyboard(selectModel.id!!, onSuccess = {
|
|
|
// 更新键盘信息
|
|
|
_currentKeyboardInfo.value = selectModel
|
|
|
onSuccess.invoke(it)
|
|
|
@@ -285,16 +288,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
*/
|
|
|
fun getCurrentKeyboardInfo() {
|
|
|
getCurrentKeyboardInfoWithDefault(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
|
|
|
- )
|
|
|
+ _currentKeyboardInfo.value = fixKeyboardSelectField(it)
|
|
|
}, onFail = { errorCode, errorMsg ->
|
|
|
ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
})
|
|
|
@@ -309,7 +303,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
}
|
|
|
// 先获取当前键盘信息,得到键盘Id
|
|
|
getCurrentKeyboardInfoWithDefault(onSuccess = { keyboardInfo ->
|
|
|
- val keyboardId = keyboardInfo.id
|
|
|
+ val keyboardId = keyboardInfo.id!!
|
|
|
val keyboardName = keyboardInfo.name
|
|
|
LogUtil.d("加载人设列表, id: ${keyboardId}, name: $keyboardName")
|
|
|
// 查询该键盘下的人设列表
|
|
|
@@ -429,43 +423,56 @@ class KeyboardViewModel : ViewModel() {
|
|
|
* 获取键盘信息,如果没有,则返回第一个键盘信息
|
|
|
*/
|
|
|
fun getCurrentKeyboardInfoWithDefault(
|
|
|
- onSuccess: (model: KeyboardSelectModel) -> Unit,
|
|
|
+ onSuccess: (model: KeyboardInfo) -> Unit,
|
|
|
onFail: (errorCode: Int, errorMsg: String) -> Unit
|
|
|
) {
|
|
|
mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
+ // 如果当前未在键盘中,手动选择过,就会为null
|
|
|
if (it.id.isNullOrBlank()) {
|
|
|
mKeyboardRepository.getKeyboardList(onSuccess = {
|
|
|
- val infos = it.keyboardInfos
|
|
|
+ val infos = it.keyboardInfos.map {
|
|
|
+ fixKeyboardSelectField(it)
|
|
|
+ }
|
|
|
// 数据为空
|
|
|
if (infos.isEmpty()) {
|
|
|
onFail.invoke(-1, "")
|
|
|
} else {
|
|
|
- // 默认使用系统键盘
|
|
|
- val systemKeyboard = infos.filter {
|
|
|
- KeyboardType.isSystem(it.type ?: "")
|
|
|
- }.toList()
|
|
|
- if (systemKeyboard.isNotEmpty()) {
|
|
|
- onSuccess.invoke(systemKeyboard.first())
|
|
|
+ // 先找已选中的键盘,否则找系统键盘
|
|
|
+ val selectedKeyboard = infos.filter {
|
|
|
+ it.isSelect == true
|
|
|
+ }.toList().firstOrNull()
|
|
|
+ if (selectedKeyboard != null) {
|
|
|
+ onSuccess.invoke(selectedKeyboard)
|
|
|
} else {
|
|
|
- // 连系统键盘都没有,则取第一个
|
|
|
- onSuccess.invoke(infos[0])
|
|
|
+ // 没有找到选中的键盘,则使用系统键盘
|
|
|
+ val systemKeyboard = infos.filter {
|
|
|
+ KeyboardType.isSystem(it.type ?: "")
|
|
|
+ }.toList()
|
|
|
+ if (systemKeyboard.isNotEmpty()) {
|
|
|
+ onSuccess.invoke(systemKeyboard.first())
|
|
|
+ } else {
|
|
|
+ // 连系统键盘都没有,则取第一个
|
|
|
+ onSuccess.invoke(infos[0])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}, 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)
|
|
|
+ onSuccess.invoke(fixKeyboardSelectField(it))
|
|
|
}
|
|
|
}, onFail)
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理isSelect字段
|
|
|
+ */
|
|
|
+ private fun fixKeyboardSelectField(info: KeyboardInfo): KeyboardInfo {
|
|
|
+ // 统一使用isSelect字段,优先使用isSelect字段,代表是用户手动在键盘中操作过的,否则就用isChoose,是其他页面中选择过的
|
|
|
+ info.isSelect = if (info.isSelect != null) {
|
|
|
+ info.isSelect == true
|
|
|
+ } else {
|
|
|
+ info.isChoose == true
|
|
|
+ }
|
|
|
+ return info
|
|
|
+ }
|
|
|
}
|