Explorar el Código

[feat]键盘插件,错误处理器,判断服务端的code,跳登录页或VIP页

hezihao hace 7 meses
padre
commit
614046df30
Se han modificado 15 ficheros con 146 adiciones y 103 borrados
  1. 0 5
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardCommonPanelComponent.kt
  2. 1 6
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardProloguePanelComponent.kt
  3. 3 10
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/KeyboardSelectComponent.kt
  4. 16 0
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/enums/ServerErrorCode.kt
  5. 10 10
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/mvvm/repository/KeyboardRepository.kt
  6. 45 22
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/mvvm/viewmodel/KeyboardViewModel.kt
  7. 0 5
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/UserInfoHelper.kt
  8. 10 10
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/FlutterBridgeManager.kt
  9. 3 3
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/AiChatApi.kt
  10. 5 5
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/KeyboardApi.kt
  11. 2 2
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/UserApi.kt
  12. 0 19
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/model/base/CallResultList.kt
  13. 5 5
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/util/FlutterMethodCaller.kt
  14. 45 0
      plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/error/ErrorHandler.kt
  15. 1 1
      plugins/keyboard_android/android/src/main/res/values/string.xml

+ 0 - 5
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardCommonPanelComponent.kt

@@ -324,8 +324,6 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
 
                 // 显示键盘引导页
                 tryShowKeyboardGuide()
-            }, onFail = {
-                ToastUtils.showShort(it)
             })
     }
 
@@ -462,7 +460,6 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
             finishCallback?.invoke()
         }, onFail = {
             // 获取失败
-            ToastUtils.showShort(it)
             finishCallback?.invoke()
         })
     }
@@ -475,7 +472,6 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
         viewModel?.chatSuperSpeak(characterId, onSuccess = {
             finishCallback?.invoke()
         }, onFail = {
-            ToastUtils.showShort(it)
         })
     }
 
@@ -487,7 +483,6 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
         viewModel?.chatPrologue(name, onSuccess = {
             finishCallback?.invoke()
         }, onFail = {
-            ToastUtils.showShort(it)
         })
     }
 }

+ 1 - 6
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardProloguePanelComponent.kt

@@ -321,9 +321,7 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
     @SuppressLint("NotifyDataSetChanged")
     private fun setData() {
         // 拉取开场白列表
-        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getPrologueList(onFail = {
-            ToastUtils.showShort(it)
-        })
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getPrologueList()
         // 监听重新生成按钮点击
         vPrologueAiChatComponent.setOnActionClickListener(object :
             AiChatComponent.OnActionClickListener {
@@ -436,7 +434,6 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
         val viewModel = KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
         viewModel?.chatSuperReply(characterId, onSuccess = {
         }, onFail = {
-            ToastUtils.showShort(it)
         })
     }
 
@@ -447,7 +444,6 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
         val viewModel = KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
         viewModel?.chatSuperSpeak(characterId, onSuccess = {
         }, onFail = {
-            ToastUtils.showShort(it)
         })
     }
 
@@ -458,7 +454,6 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
         val viewModel = KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
         viewModel?.chatPrologue(name, onSuccess = {
         }, onFail = {
-            ToastUtils.showShort(it)
         })
     }
 }

+ 3 - 10
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/KeyboardSelectComponent.kt

@@ -20,7 +20,6 @@ import com.atmob.keyboard_android.model.KeyboardSelectModel
 import com.atmob.keyboard_android.util.KeyboardHolder
 import com.atmob.keyboard_android.util.recyclerview.GridDivider
 import com.blankj.utilcode.util.ConvertUtils
-import com.blankj.utilcode.util.ToastUtils
 import me.drakeet.multitype.Items
 import me.drakeet.multitype.MultiTypeAdapter
 
@@ -66,8 +65,6 @@ class KeyboardSelectComponent @JvmOverloads constructor(
             selectedKeyboard(selectKeyboard, onSuccess = {
                 // 关闭选择器
                 hide()
-            }, onFail = {
-                ToastUtils.showShort(it)
             })
         }
 
@@ -163,9 +160,7 @@ class KeyboardSelectComponent @JvmOverloads constructor(
      * 加载键盘数据
      */
     private fun loadKeyboardList() {
-        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getKeyboardList {
-            ToastUtils.showLong(it)
-        }
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getKeyboardList()
     }
 
     /**
@@ -173,15 +168,13 @@ class KeyboardSelectComponent @JvmOverloads constructor(
      */
     private fun selectedKeyboard(
         selectModel: KeyboardSelectModel,
-        onSuccess: () -> Unit,
-        onFail: (msg: String) -> Unit
+        onSuccess: () -> Unit
     ) {
         KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.selectedKeyboard(
             selectModel,
             onSuccess = {
                 onSuccess.invoke()
-            },
-            onFail = onFail
+            }
         )
     }
 }

+ 16 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/enums/ServerErrorCode.kt

@@ -0,0 +1,16 @@
+package com.atmob.keyboard_android.enums
+
+/**
+ * 服务端错误码
+ */
+enum class ServerErrorCode(val code: Int) {
+    /**
+     * 需要VIP
+     */
+    NEED_VIP(1008),
+
+    /**
+     * 未登录
+     */
+    NO_LOGIN(1006),
+}

+ 10 - 10
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/mvvm/repository/KeyboardRepository.kt

@@ -21,7 +21,7 @@ class KeyboardRepository {
      */
     fun isLogin(
         onSuccess: (resultObj: Boolean) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.isLogin(onSuccess, onFail)
     }
@@ -31,7 +31,7 @@ class KeyboardRepository {
      */
     fun isMember(
         onSuccess: (resultObj: Boolean) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.isMember(onSuccess, onFail)
     }
@@ -41,7 +41,7 @@ class KeyboardRepository {
      */
     fun getKeyboardList(
         onSuccess: (resultObj: KeyboardListResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.getKeyboardList(onSuccess, onFail)
     }
@@ -52,7 +52,7 @@ class KeyboardRepository {
     fun selectedKeyboard(
         keyboardId: String,
         onSuccess: (resultObj: EmptyResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.selectedKeyboard(
             keyboardId,
@@ -66,7 +66,7 @@ class KeyboardRepository {
      */
     fun getCurrentKeyboardInfo(
         onSuccess: (resultObj: CurrentKeyboardIdResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.getCurrentKeyboardInfo(onSuccess, onFail)
     }
@@ -77,7 +77,7 @@ class KeyboardRepository {
     fun getCharacterList(
         keyboardId: String,
         onSuccess: (CharacterListResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.getCharacterList(keyboardId, onSuccess, onFail)
     }
@@ -87,7 +87,7 @@ class KeyboardRepository {
      */
     fun getPrologueList(
         onSuccess: (PrologueListResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.getPrologueList(onSuccess, onFail)
     }
@@ -98,7 +98,7 @@ class KeyboardRepository {
     fun chatSuperReply(
         req: SuperReplyReq,
         onSuccess: (SuperReplyResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.chatSuperReply(req, onSuccess, onFail)
     }
@@ -109,7 +109,7 @@ class KeyboardRepository {
     fun chatSuperSpeak(
         req: SuperSpeakReq,
         onSuccess: (SuperSpeakResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.chatSuperSpeak(req, onSuccess, onFail)
     }
@@ -120,7 +120,7 @@ class KeyboardRepository {
     fun chatPrologue(
         name: String,
         onSuccess: (PrologueResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         FlutterBridgeManager.chatPrologue(name, onSuccess, onFail)
     }

+ 45 - 22
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/mvvm/viewmodel/KeyboardViewModel.kt

@@ -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()) {

+ 0 - 5
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/UserInfoHelper.kt

@@ -2,7 +2,6 @@ package com.atmob.keyboard_android.util
 
 import com.atmob.keyboard_android.component.ComponentMediator
 import com.atmob.keyboard_android.component.root.IKeyboardRootComponent
-import com.blankj.utilcode.util.ToastUtils
 
 /**
  * 用户信息工具类
@@ -15,8 +14,6 @@ object UserInfoHelper {
         KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
             ?.isLogin(onSuccess = {
                 callback.invoke(it)
-            }, onFail = {
-                ToastUtils.showShort(it)
             })
     }
 
@@ -30,8 +27,6 @@ object UserInfoHelper {
                 KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
                     ?.isMember(onSuccess = {
                         callback.invoke(it)
-                    }, onFail = {
-                        ToastUtils.showShort(it)
                     })
             } else {
                 // 未登录,则直接返回false

+ 10 - 10
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/FlutterBridgeManager.kt

@@ -48,7 +48,7 @@ object FlutterBridgeManager : IBridgeApi {
         mNativeEventRegistry.init(flutterEngine)
     }
 
-    override fun isLogin(onSuccess: (Boolean) -> Unit, onFail: (String) -> Unit) {
+    override fun isLogin(onSuccess: (Boolean) -> Unit, onFail: (errorCode: Int, errorMsg: String) -> Unit) {
         mFlutterMethodCaller.callMethod<Boolean>(
             FlutterMethod.IS_LOGIN.methodName,
             isReturnJson = false,
@@ -58,7 +58,7 @@ object FlutterBridgeManager : IBridgeApi {
         )
     }
 
-    override fun isMember(onSuccess: (Boolean) -> Unit, onFail: (String) -> Unit) {
+    override fun isMember(onSuccess: (Boolean) -> Unit, onFail: (errorCode: Int, errorMsg: String) -> Unit) {
         mFlutterMethodCaller.callMethod<Boolean>(
             FlutterMethod.IS_MEMBER.methodName,
             isReturnJson = false,
@@ -96,7 +96,7 @@ object FlutterBridgeManager : IBridgeApi {
 
     override fun getKeyboardList(
         onSuccess: (resultObj: KeyboardListResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<KeyboardListResp>(
             FlutterMethod.GET_KEYBOARD_LIST.methodName,
@@ -109,7 +109,7 @@ object FlutterBridgeManager : IBridgeApi {
     override fun selectedKeyboard(
         keyboardId: String,
         onSuccess: (EmptyResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<EmptyResp>(
             FlutterMethod.SELECTED_KEY_BOARD.methodName,
@@ -123,7 +123,7 @@ object FlutterBridgeManager : IBridgeApi {
 
     override fun getCurrentKeyboardInfo(
         onSuccess: (CurrentKeyboardIdResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<CurrentKeyboardIdResp>(
             FlutterMethod.GET_CURRENT_KEYBOARD_INFO.methodName,
@@ -136,7 +136,7 @@ object FlutterBridgeManager : IBridgeApi {
     override fun getCharacterList(
         keyboardId: String,
         onSuccess: (CharacterListResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<CharacterListResp>(
             FlutterMethod.GET_CHARACTER_LIST.methodName,
@@ -149,7 +149,7 @@ object FlutterBridgeManager : IBridgeApi {
 
     override fun getPrologueList(
         onSuccess: (PrologueListResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<PrologueListResp>(
             FlutterMethod.GET_PROLOGUE_LIST.methodName,
@@ -162,7 +162,7 @@ object FlutterBridgeManager : IBridgeApi {
     override fun chatSuperReply(
         req: SuperReplyReq,
         onSuccess: (SuperReplyResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<SuperReplyResp>(
             FlutterMethod.CHAT_SUPER_REPLY.methodName,
@@ -180,7 +180,7 @@ object FlutterBridgeManager : IBridgeApi {
     override fun chatSuperSpeak(
         req: SuperSpeakReq,
         onSuccess: (SuperSpeakResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<SuperSpeakResp>(
             FlutterMethod.CHAT_SUPER_SPEAK.methodName,
@@ -198,7 +198,7 @@ object FlutterBridgeManager : IBridgeApi {
     override fun chatPrologue(
         name: String,
         onSuccess: (PrologueResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<PrologueResp>(
             FlutterMethod.CHAT_PROLOGUE.methodName,

+ 3 - 3
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/AiChatApi.kt

@@ -16,7 +16,7 @@ interface AiChatApi {
     fun chatSuperReply(
         req: SuperReplyReq,
         onSuccess: (SuperReplyResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -25,7 +25,7 @@ interface AiChatApi {
     fun chatSuperSpeak(
         req: SuperSpeakReq,
         onSuccess: (SuperSpeakResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -34,6 +34,6 @@ interface AiChatApi {
     fun chatPrologue(
         name: String,
         onSuccess: (PrologueResp) -> Unit,
-        onFail: (String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 }

+ 5 - 5
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/KeyboardApi.kt

@@ -15,7 +15,7 @@ interface KeyboardApi {
      */
     fun getKeyboardList(
         onSuccess: (resultObj: KeyboardListResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -24,7 +24,7 @@ interface KeyboardApi {
     fun selectedKeyboard(
         keyboardId: String,
         onSuccess: (resultObj: EmptyResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -32,7 +32,7 @@ interface KeyboardApi {
      */
     fun getCurrentKeyboardInfo(
         onSuccess: (CurrentKeyboardIdResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -41,7 +41,7 @@ interface KeyboardApi {
     fun getCharacterList(
         keyboardId: String,
         onSuccess: (resultObj: CharacterListResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -49,6 +49,6 @@ interface KeyboardApi {
      */
     fun getPrologueList(
         onSuccess: (resultObj: PrologueListResp) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 }

+ 2 - 2
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/api/UserApi.kt

@@ -9,7 +9,7 @@ interface UserApi {
      */
     fun isLogin(
         onSuccess: (resultObj: Boolean) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 
     /**
@@ -17,6 +17,6 @@ interface UserApi {
      */
     fun isMember(
         onSuccess: (resultObj: Boolean) -> Unit,
-        onFail: (msg: String) -> Unit
+        onFail: (errorCode: Int, errorMsg: String) -> Unit
     )
 }

+ 0 - 19
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/model/base/CallResultList.kt

@@ -1,19 +0,0 @@
-package com.atmob.keyboard_android.util.bridge.model.base
-
-import androidx.annotation.Keep
-import java.io.Serializable
-
-/**
- * 调用Flutter方法,列表型,通用结构
- */
-@Keep
-data class CallResultList<T>(
-    /**
-     * 响应码
-     */
-    val code: Int,
-    /**
-     * 响应数据
-     */
-    val data: List<T>
-) : Serializable

+ 5 - 5
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/util/FlutterMethodCaller.kt

@@ -48,7 +48,7 @@ class FlutterMethodCaller {
         modelClazz: Class<T>,
         isReturnJson: Boolean = true,
         onSuccess: ((resultObj: T) -> Unit)? = null,
-        onFail: ((msg: String) -> Unit)? = null
+        onFail: ((errorCode: Int, errorMsg: String) -> Unit)? = null
     ) {
         mMethodChannel.invokeMethod(methodName, args, object : MethodChannel.Result {
             override fun success(result: Any?) {
@@ -62,7 +62,7 @@ class FlutterMethodCaller {
                         )
                         if (result.code != 0) {
                             runOnUIThread {
-                                onFail?.invoke(result.message)
+                                onFail?.invoke(result.code, result.message)
                             }
                             return
                         }
@@ -75,7 +75,7 @@ class FlutterMethodCaller {
                         val errorMsg = e.message ?: "call error"
                         LogUtil.d("方法名:${methodName},调用成功,但解析json失败,原因:${errorMsg},json内容:${resultJson}")
                         runOnUIThread {
-                            onFail?.invoke(errorMsg)
+                            onFail?.invoke(-1, errorMsg)
                         }
                     }
                 } else {
@@ -90,14 +90,14 @@ class FlutterMethodCaller {
                 val errorMsg = errorMessage ?: "call error"
                 LogUtil.d("方法名:${methodName},调用失败,原因:${errorMsg}")
                 runOnUIThread {
-                    onFail?.invoke(errorMsg)
+                    onFail?.invoke(errorCode.toInt(), errorMsg)
                 }
             }
 
             override fun notImplemented() {
                 LogUtil.d("方法名:${methodName},调用失败,Flutter未实现该方法")
                 runOnUIThread {
-                    onFail?.invoke("method not implemented")
+                    onFail?.invoke(-1, "method not implemented")
                 }
             }
         })

+ 45 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/error/ErrorHandler.kt

@@ -0,0 +1,45 @@
+package com.atmob.keyboard_android.util.error
+
+import com.atmob.keyboard_android.component.ComponentMediator
+import com.atmob.keyboard_android.component.root.IKeyboardRootComponent
+import com.atmob.keyboard_android.enums.ServerErrorCode
+import com.atmob.keyboard_android.util.UserInfoHelper
+import com.blankj.utilcode.util.ToastUtils
+
+/**
+ * 错误处理类
+ */
+class ErrorHandler private constructor() {
+    companion object {
+        /**
+         * 处理错误
+         *
+         * @param errorCode 错误码
+         * @param errorMessage 错误消息
+         */
+        fun handleError(errorCode: Int, errorMessage: String?, needToast: Boolean = true) {
+            val keyboardRootComponent =
+                ComponentMediator.findComponent(IKeyboardRootComponent::class.java)
+
+            // 需要VIP
+            if (ServerErrorCode.NEED_VIP.code == errorCode) {
+                UserInfoHelper.isLogin { hasLogin ->
+                    // 已登录,但没有VIP,跳去VIP页
+                    if (hasLogin) {
+                        keyboardRootComponent?.switchVipPage()
+                    } else {
+                        // 未登录,跳去登录页
+                        keyboardRootComponent?.switchLoginPage()
+                    }
+                }
+            } else if (ServerErrorCode.NO_LOGIN.code == errorCode) {
+                // 未登录
+                keyboardRootComponent?.switchLoginPage()
+            }
+
+            if (needToast) {
+                ToastUtils.showShort(errorMessage)
+            }
+        }
+    }
+}

+ 1 - 1
plugins/keyboard_android/android/src/main/res/values/string.xml

@@ -3,7 +3,7 @@
     <string name="keyboard_app_name">追爱小键盘</string>
     <string name="login_tip">请登录后使用</string>
     <string name="go_login">去登录</string>
-    <string name="vip_tip">您的免费提问次数已用完\n可订阅会员解锁无线提问</string>
+    <string name="vip_tip">您的免费提问次数已用完\n可订阅会员解锁无提问</string>
     <string name="go_vip">¥0.1/天解锁</string>
     <string name="setting_custom_person">定制人设</string>
     <string name="setting_market">人设市场</string>