Bladeren bron

[feat]键盘插件,修改getCurrentKeyboardId为getCurrentKeyboardInfo

hezihao 8 maanden geleden
bovenliggende
commit
bc9b86bfb5

+ 2 - 2
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/enums/FlutterMethod.kt

@@ -25,9 +25,9 @@ enum class FlutterMethod(val methodName: String) {
     SELECTED_KEY_BOARD("selectedKeyboard"),
 
     /**
-     * 获取当前键盘Id
+     * 获取当前键盘信息
      */
-    GET_CURRENT_KEYBOARD_ID("getCurrentKeyboardId"),
+    GET_CURRENT_KEYBOARD_INFO("getCurrentKeyboardInfo"),
 
     /**
      * 获取人设列表

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

@@ -63,7 +63,7 @@ class KeyboardRepository {
         onSuccess: (resultObj: CurrentKeyboardIdResp) -> Unit,
         onFail: (msg: String) -> Unit
     ) {
-        FlutterBridgeManager.getCurrentKeyboardId(onSuccess, onFail)
+        FlutterBridgeManager.getCurrentKeyboardInfo(onSuccess, onFail)
     }
 
     /**

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

@@ -220,7 +220,7 @@ class KeyboardViewModel : ViewModel() {
         onFail: (String) -> Unit
     ) {
         mKeyboardRepository.getCurrentKeyboardId(onSuccess = {
-            val keyboardId = it.keyboardId ?: ""
+            val keyboardId = it.id ?: ""
             mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
         }, onFail)
     }

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

@@ -107,12 +107,12 @@ object FlutterBridgeManager : IBridgeApi {
         )
     }
 
-    override fun getCurrentKeyboardId(
+    override fun getCurrentKeyboardInfo(
         onSuccess: (CurrentKeyboardIdResp) -> Unit,
         onFail: (String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<CurrentKeyboardIdResp>(
-            FlutterMethod.GET_CURRENT_KEYBOARD_ID.methodName,
+            FlutterMethod.GET_CURRENT_KEYBOARD_INFO.methodName,
             modelClazz = CurrentKeyboardIdResp::class.java,
             onSuccess = onSuccess,
             onFail = onFail

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

@@ -28,9 +28,9 @@ interface KeyboardApi {
     )
 
     /**
-     * 获取当前键盘Id
+     * 获取当前键盘信息
      */
-    fun getCurrentKeyboardId(
+    fun getCurrentKeyboardInfo(
         onSuccess: (CurrentKeyboardIdResp) -> Unit,
         onFail: (msg: String) -> Unit
     )

+ 25 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/model/resp/CurrentKeyboardIdResp.kt

@@ -9,5 +9,29 @@ data class CurrentKeyboardIdResp(
     /**
      * 键盘Id
      */
-    val keyboardId: String? = null
+    val id: String? = null,
+    /**
+     * 键盘类型,system:系统键盘、custom:定制键盘
+     */
+    val type: String,
+    /**
+     * 键盘名称
+     */
+    val name: String,
+    /**
+     * 性别
+     */
+    val gender: Int,
+    /**
+     * 生日
+     */
+    val birthday: String,
+    /**
+     * 亲密度
+     */
+    val intimacy: Int,
+    /**
+     * 键盘图标Url
+     */
+    val imageUrl: String,
 ) : Serializable

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

@@ -4,6 +4,7 @@ import android.os.Handler
 import android.os.Looper
 import com.atmob.keyboard_android.constant.PluginConfig
 import com.atmob.keyboard_android.util.JsonUtil
+import com.atmob.keyboard_android.util.LogUtil
 import io.flutter.embedding.engine.FlutterEngine
 import io.flutter.plugin.common.MethodChannel
 
@@ -51,15 +52,17 @@ class FlutterMethodCaller {
         mMethodChannel.invokeMethod(methodName, args, object : MethodChannel.Result {
             override fun success(result: Any?) {
                 if (isReturnJson) {
+                    val resultJson = result.toString()
                     try {
-                        val resultJson = result.toString()
                         val resultObj = JsonUtil.parseJsonByClass<T>(resultJson, modelClazz)
                         runOnUIThread {
                             onSuccess?.invoke(resultObj)
                         }
                     } catch (e: Throwable) {
+                        val errorMsg = e.message ?: "call error"
+                        LogUtil.d("方法名:${methodName},调用成功,但解析json失败,原因:${errorMsg},json内容:${resultJson}")
                         runOnUIThread {
-                            onFail?.invoke(e.message ?: "call error")
+                            onFail?.invoke(errorMsg)
                         }
                     }
                 } else {
@@ -71,12 +74,15 @@ class FlutterMethodCaller {
             }
 
             override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
+                val errorMsg = errorMessage ?: "call error"
+                LogUtil.d("方法名:${methodName},调用失败,原因:${errorMsg}")
                 runOnUIThread {
-                    onFail?.invoke(errorMessage ?: "call error")
+                    onFail?.invoke(errorMsg)
                 }
             }
 
             override fun notImplemented() {
+                LogUtil.d("方法名:${methodName},调用失败,Flutter未实现该方法")
                 runOnUIThread {
                     onFail?.invoke("method not implemented")
                 }