Преглед на файлове

[feat]键盘插件,对接Flutter的保存键盘API

hezihao преди 8 месеца
родител
ревизия
23b210ce63

+ 2 - 1
lib/plugins/keyboard_method_handler.dart

@@ -45,9 +45,10 @@ class KeyboardMethodHandler {
   }
 
 
-  void _handleSelectedKeyboard(MethodCall call) {
+  Future<String> _handleSelectedKeyboard(MethodCall call) async {
     final String keyboardId = call.arguments['keyboardId'];
     KVUtil.putString(keyboardSelect, keyboardId);
+    return "{}";
   }
 
   Future<String> _handleGetCharacterList(MethodCall call) async {

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

@@ -55,12 +55,12 @@ class KeyboardSelectComponent @JvmOverloads constructor(
         }
         vSaveBtn.click {
             val selectKeyboard =
-                mListItems.filterIsInstance<KeyboardSelectModel>().find { it.isChoose }
+                mListItems.filterIsInstance<KeyboardSelectModel>().find { it.isSelect }
             if (selectKeyboard == null) {
                 return@click
             }
             // 保存,用户选择的键盘
-            chooseKeyboard(selectKeyboard, onSuccess = {
+            selectedKeyboard(selectKeyboard, onSuccess = {
                 // 关闭选择器
                 hide()
             }, onFail = {
@@ -79,12 +79,12 @@ class KeyboardSelectComponent @JvmOverloads constructor(
                     // 先全部取消选中,再选中当前设置的键盘
                     mListItems.forEachIndexed { index, item ->
                         if (item is KeyboardSelectModel) {
-                            item.isChoose = false
+                            item.isSelect = false
                         }
                     }
                     val targetPosition = mListItems.indexOf(item)
                     val targetItem = mListItems[targetPosition] as KeyboardSelectModel
-                    targetItem.isChoose = true
+                    targetItem.isSelect = true
                     notifyDataSetChanged()
                 })
             }
@@ -168,12 +168,12 @@ class KeyboardSelectComponent @JvmOverloads constructor(
     /**
      * 选择键盘
      */
-    private fun chooseKeyboard(
+    private fun selectedKeyboard(
         selectModel: KeyboardSelectModel,
         onSuccess: () -> Unit,
         onFail: (msg: String) -> Unit
     ) {
-        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.chooseKeyboard(
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.selectedKeyboard(
             selectModel,
             onSuccess = {
                 onSuccess.invoke()

+ 1 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/item/KeyboardSelectViewBinder.kt

@@ -45,7 +45,7 @@ class KeyboardSelectViewBinder(
         holder.vName.text = item.name
 
         // 选中
-        if (item.isChoose) {
+        if (item.isSelect) {
             holder.itemContainer.setBackgroundResource(R.drawable.bg_keyboard_selected)
             holder.vName.apply {
                 setTextColor(context.resources.getColor(R.color.text_color_white))

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

@@ -12,5 +12,5 @@ enum class FlutterMethod(val methodName: String) {
     /**
      * 选择键盘
      */
-    CHOOSE_KEY_BOARD("chooseKeyboard")
+    SELECTED_KEY_BOARD("selectedKeyboard")
 }

+ 2 - 2
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/model/KeyboardSelectModel.kt

@@ -35,7 +35,7 @@ data class KeyboardSelectModel(
      */
     val imageUrl: String,
     /**
-     * 是否选中
+     * 是否选中(Flutter端本地添加的字段,不是服务端返回的)
      */
-    var isChoose: Boolean = false
+    var isSelect: Boolean = false,
 ) : Serializable

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

@@ -2,7 +2,6 @@ package com.atmob.keyboard_android.mvvm.repository
 
 import com.atmob.keyboard_android.util.bridge.FlutterBridgeManager
 import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
-import com.atmob.keyboard_android.util.bridge.model.req.ChooseKeyboardReq
 import com.atmob.keyboard_android.util.bridge.model.resp.KeyboardListResp
 
 /**
@@ -22,13 +21,13 @@ class KeyboardRepository {
     /**
      * 选择键盘
      */
-    fun chooseKeyboard(
+    fun selectedKeyboard(
         keyboardId: String,
         onSuccess: (resultObj: EmptyResp) -> Unit,
         onFail: (msg: String) -> Unit
     ) {
-        FlutterBridgeManager.chooseKeyboard(
-            req = ChooseKeyboardReq(keyboardId),
+        FlutterBridgeManager.selectedKeyboard(
+            keyboardId,
             onSuccess,
             onFail
         )

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

@@ -172,12 +172,12 @@ class KeyboardViewModel : ViewModel() {
      *
      * @param selectModel 键盘选择信息
      */
-    fun chooseKeyboard(
+    fun selectedKeyboard(
         selectModel: KeyboardSelectModel,
         onSuccess: (resultObj: EmptyResp) -> Unit,
         onFail: (msg: String) -> Unit
     ) {
-        mKeyboardRepository.chooseKeyboard(selectModel.id, onSuccess = {
+        mKeyboardRepository.selectedKeyboard(selectModel.id, onSuccess = {
             // 更新键盘类型
             _keyboardType.value = selectModel.name
             onSuccess.invoke(it)

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

@@ -3,7 +3,6 @@ package com.atmob.keyboard_android.util.bridge
 import com.atmob.keyboard_android.constant.PluginConfig
 import com.atmob.keyboard_android.enums.FlutterMethod
 import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
-import com.atmob.keyboard_android.util.bridge.model.req.ChooseKeyboardReq
 import com.atmob.keyboard_android.util.bridge.model.resp.KeyboardListResp
 import com.atmob.keyboard_android.util.bridge.util.FlutterMethodCaller
 import com.atmob.keyboard_android.util.bridge.util.NativeMethodRegistry
@@ -36,6 +35,19 @@ object FlutterBridgeManager : IBridgeApi {
         return false
     }
 
+    override fun isVip(): Boolean {
+        return false
+    }
+
+    override fun jump2CustomCharacterPage() {
+    }
+
+    override fun jump2CharacterMarketPage() {
+    }
+
+    override fun jump2VipStore() {
+    }
+
     override fun getKeyboardList(
         onSuccess: (resultObj: KeyboardListResp) -> Unit,
         onFail: (msg: String) -> Unit
@@ -48,13 +60,15 @@ object FlutterBridgeManager : IBridgeApi {
         )
     }
 
-    override fun chooseKeyboard(
-        req: ChooseKeyboardReq,
+    override fun selectedKeyboard(
+        keyboardId: String,
         onSuccess: (EmptyResp) -> Unit,
         onFail: (String) -> Unit
     ) {
         mFlutterMethodCaller.callMethod<EmptyResp>(
-            FlutterMethod.CHOOSE_KEY_BOARD.methodName,
+            FlutterMethod.SELECTED_KEY_BOARD.methodName,
+            // 传递参数
+            args = mapOf("keyboardId" to keyboardId),
             modelClazz = EmptyResp::class.java,
             onSuccess = onSuccess,
             onFail = onFail

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

@@ -1,7 +1,6 @@
 package com.atmob.keyboard_android.util.bridge
 
 import com.atmob.keyboard_android.util.bridge.model.base.EmptyResp
-import com.atmob.keyboard_android.util.bridge.model.req.ChooseKeyboardReq
 import com.atmob.keyboard_android.util.bridge.model.resp.KeyboardListResp
 
 /**
@@ -14,6 +13,26 @@ interface IBridgeApi {
     fun isLogin(): Boolean
 
     /**
+     * 用户是否为VIP
+     */
+    fun isVip(): Boolean
+
+    /**
+     * 跳转到定制人设页
+     */
+    fun jump2CustomCharacterPage()
+
+    /**
+     * 跳转到人设市场页
+     */
+    fun jump2CharacterMarketPage()
+
+    /**
+     * 跳转到VIP商店
+     */
+    fun jump2VipStore()
+
+    /**
      * 获取键盘列表
      */
     fun getKeyboardList(
@@ -24,8 +43,8 @@ interface IBridgeApi {
     /**
      * 选择键盘
      */
-    fun chooseKeyboard(
-        req: ChooseKeyboardReq,
+    fun selectedKeyboard(
+        keyboardId: String,
         onSuccess: (resultObj: EmptyResp) -> Unit,
         onFail: (msg: String) -> Unit
     )

+ 0 - 13
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/model/req/ChooseKeyboardReq.kt

@@ -1,13 +0,0 @@
-package com.atmob.keyboard_android.util.bridge.model.req
-
-import java.io.Serializable
-
-/**
- * 选择键盘请求
- */
-data class ChooseKeyboardReq(
-    /**
-     * 键盘Id
-     */
-    val keyboardId: String,
-) : Serializable

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

@@ -35,17 +35,24 @@ class FlutterMethodCaller {
      * 调用Flutter方法
      */
     fun <T> callMethod(
-        methodName: String, args: Any? = null,
+        methodName: String,
+        args: Any? = null,
         modelClazz: Class<T>,
         onSuccess: ((resultObj: T) -> Unit)? = null,
         onFail: ((msg: String) -> Unit)? = null
     ) {
         mMethodChannel.invokeMethod(methodName, args, object : MethodChannel.Result {
             override fun success(result: Any?) {
-                val resultJson = result.toString()
-                val resultObj = JsonUtil.parseJsonByClass<T>(resultJson, modelClazz)
-                runOnUIThread {
-                    onSuccess?.invoke(resultObj)
+                try {
+                    val resultJson = result.toString()
+                    val resultObj = JsonUtil.parseJsonByClass<T>(resultJson, modelClazz)
+                    runOnUIThread {
+                        onSuccess?.invoke(resultObj)
+                    }
+                } catch (e: Throwable) {
+                    runOnUIThread {
+                        onFail?.invoke(e.message ?: "call error")
+                    }
                 }
             }