|
|
@@ -13,6 +13,7 @@ import com.atmob.keyboard_android.util.bridge.model.req.SuperSpeakReq
|
|
|
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.Topic
|
|
|
+import com.atmob.keyboard_android.util.error.ErrorHandler
|
|
|
|
|
|
/**
|
|
|
* 键盘ViewModel
|
|
|
@@ -200,29 +201,35 @@ class KeyboardViewModel : ViewModel() {
|
|
|
* 用户是否已登录
|
|
|
*/
|
|
|
fun isLogin(
|
|
|
- onSuccess: (resultObj: Boolean) -> Unit,
|
|
|
- onFail: (msg: String) -> Unit
|
|
|
+ onSuccess: (resultObj: Boolean) -> Unit
|
|
|
) {
|
|
|
- mKeyboardRepository.isLogin(onSuccess, onFail)
|
|
|
+ mKeyboardRepository.isLogin(
|
|
|
+ onSuccess,
|
|
|
+ onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户是否为VIP
|
|
|
*/
|
|
|
fun isMember(
|
|
|
- onSuccess: (resultObj: Boolean) -> Unit,
|
|
|
- onFail: (msg: String) -> Unit
|
|
|
+ onSuccess: (resultObj: Boolean) -> Unit
|
|
|
) {
|
|
|
- mKeyboardRepository.isMember(onSuccess, onFail)
|
|
|
+ mKeyboardRepository.isMember(onSuccess, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取键盘列表
|
|
|
*/
|
|
|
- fun getKeyboardList(onFail: (msg: String) -> Unit) {
|
|
|
+ fun getKeyboardList() {
|
|
|
mKeyboardRepository.getKeyboardList(onSuccess = {
|
|
|
_keyboardList.value = it.keyboardInfos
|
|
|
- }, onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -232,14 +239,15 @@ class KeyboardViewModel : ViewModel() {
|
|
|
*/
|
|
|
fun selectedKeyboard(
|
|
|
selectModel: KeyboardSelectModel,
|
|
|
- onSuccess: (resultObj: EmptyResp) -> Unit,
|
|
|
- onFail: (msg: String) -> Unit
|
|
|
+ onSuccess: (resultObj: EmptyResp) -> Unit
|
|
|
) {
|
|
|
mKeyboardRepository.selectedKeyboard(selectModel.id, onSuccess = {
|
|
|
// 更新键盘信息
|
|
|
_currentKeyboardInfo.value = selectModel
|
|
|
onSuccess.invoke(it)
|
|
|
- }, onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -257,31 +265,37 @@ class KeyboardViewModel : ViewModel() {
|
|
|
imageUrl = it.imageUrl,
|
|
|
isSelect = it.isSelect
|
|
|
)
|
|
|
- }, onFail = {})
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取人设列表
|
|
|
*/
|
|
|
fun getCharacterList(
|
|
|
- onSuccess: (CharacterListResp) -> Unit,
|
|
|
- onFail: (String) -> Unit
|
|
|
+ onSuccess: (CharacterListResp) -> Unit
|
|
|
) {
|
|
|
+ val errorCallback = { errorCode: Int, errorMsg: String ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ }
|
|
|
// 先获取当前键盘信息,得到键盘Id
|
|
|
getCurrentKeyboardInfoWithDefault(onSuccess = {
|
|
|
val keyboardId = it.id
|
|
|
// 查询该键盘下的人设列表
|
|
|
- mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
|
|
|
- }, onFail)
|
|
|
+ mKeyboardRepository.getCharacterList(keyboardId, onSuccess, errorCallback)
|
|
|
+ }, onFail = errorCallback)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取开场白列表
|
|
|
*/
|
|
|
- fun getPrologueList(onFail: (String) -> Unit) {
|
|
|
+ fun getPrologueList() {
|
|
|
mKeyboardRepository.getPrologueList(onSuccess = {
|
|
|
_prologueList.value = it.prologues ?: listOf()
|
|
|
- }, onFail = onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -321,7 +335,10 @@ class KeyboardViewModel : ViewModel() {
|
|
|
// 只有一条数据,直接添加到输入框
|
|
|
_chatSuperReplyResult.value = it.content
|
|
|
onSuccess.invoke()
|
|
|
- }, onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ onFail.invoke(errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -347,7 +364,10 @@ class KeyboardViewModel : ViewModel() {
|
|
|
// 有多条数据,需要跳转列表页面中显示
|
|
|
_superSpeakChatListResult.value = it.list
|
|
|
onSuccess.invoke()
|
|
|
- }, onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ onFail.invoke(errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -363,7 +383,10 @@ class KeyboardViewModel : ViewModel() {
|
|
|
// 有多条数据,需要跳转列表页面中显示
|
|
|
_prologueChatListResult.value = it.list
|
|
|
onSuccess.invoke()
|
|
|
- }, onFail)
|
|
|
+ }, onFail = { errorCode, errorMsg ->
|
|
|
+ ErrorHandler.handleError(errorCode, errorMsg)
|
|
|
+ onFail.invoke(errorMsg)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -371,7 +394,7 @@ class KeyboardViewModel : ViewModel() {
|
|
|
*/
|
|
|
fun getCurrentKeyboardInfoWithDefault(
|
|
|
onSuccess: (model: KeyboardSelectModel) -> Unit,
|
|
|
- onFail: (String) -> Unit
|
|
|
+ onFail: (errorCode: Int, errorMsg: String) -> Unit
|
|
|
) {
|
|
|
mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
|
|
|
if (it.id.isNullOrBlank()) {
|