Procházet zdrojové kódy

[feat]键盘插件,Ai键盘,按键列表,上下滚动,不用左右翻页

hezihao před 7 měsíci
rodič
revize
72551c6168

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

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
 import android.content.Context
 import android.util.AttributeSet
 import android.view.View
+import androidx.recyclerview.widget.GridLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.atmob.keyboard_android.R
 import com.atmob.keyboard_android.component.base.BaseUIComponent
@@ -128,29 +129,39 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
                     FlutterBridgeManager.jump2CharacterMarketPage()
                 })
             }
-            // 水平分页布局管理器
-            layoutManager = PagerGridLayoutManager(
-                Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
-                Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
-                PagerGridLayoutManager.HORIZONTAL
-            ).apply {
-                // 设置滚动监听
-                setPageListener(object : PageListener {
-                    override fun onPageSizeChanged(pageSize: Int) {
-                        // 当总页数确定时的回调
-                    }
+            if (Constants.AI_KEYBOARD_KEY_LIST_PAGE_ENABLE) {
+                // 分页布局管理器
+                layoutManager = PagerGridLayoutManager(
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    PagerGridLayoutManager.HORIZONTAL
+                ).apply {
+                    // 设置滚动监听
+                    setPageListener(object : PageListener {
+                        override fun onPageSizeChanged(pageSize: Int) {
+                            // 当总页数确定时的回调
+                        }
 
-                    override fun onPageSelect(pageIndex: Int) {
-                        // 当页面被选中时的回调(从 0 开始)
-                    }
-                })
-            }
-            // 设置滚动辅助工具
-            val pageSnapHelper = PagerGridSnapHelper().apply {
-                // 设置滚动阀值
-                setFlingThreshold(minFlingVelocity)
+                        override fun onPageSelect(pageIndex: Int) {
+                            // 当页面被选中时的回调(从 0 开始)
+                        }
+                    })
+                }
+                // 设置滚动辅助工具
+                val pageSnapHelper = PagerGridSnapHelper().apply {
+                    // 设置滚动阀值
+                    setFlingThreshold(minFlingVelocity)
+                }
+                pageSnapHelper.attachToRecyclerView(this)
+            } else {
+                // 不分页,只网格
+                layoutManager = GridLayoutManager(
+                    context,
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    GridLayoutManager.VERTICAL,
+                    false
+                )
             }
-            pageSnapHelper.attachToRecyclerView(this)
             // 设置适配器
             adapter = mKeyListAdapter
             // 添加分割线

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

@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
 import android.content.Context
 import android.util.AttributeSet
 import android.view.View
+import androidx.recyclerview.widget.GridLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.atmob.keyboard_android.R
 import com.atmob.keyboard_android.component.base.BaseUIComponent
@@ -189,29 +190,39 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
                     }
                 })
             }
-            // 水平分页布局管理器
-            layoutManager = PagerGridLayoutManager(
-                Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
-                Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
-                PagerGridLayoutManager.HORIZONTAL
-            ).apply {
-                // 设置滚动监听
-                setPageListener(object : PageListener {
-                    override fun onPageSizeChanged(pageSize: Int) {
-                        // 当总页数确定时的回调
-                    }
+            if (Constants.AI_KEYBOARD_KEY_LIST_PAGE_ENABLE) {
+                // 分页布局管理器
+                layoutManager = PagerGridLayoutManager(
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    PagerGridLayoutManager.HORIZONTAL
+                ).apply {
+                    // 设置滚动监听
+                    setPageListener(object : PageListener {
+                        override fun onPageSizeChanged(pageSize: Int) {
+                            // 当总页数确定时的回调
+                        }
 
-                    override fun onPageSelect(pageIndex: Int) {
-                        // 当页面被选中时的回调(从 0 开始)
-                    }
-                })
-            }
-            // 设置滚动辅助工具
-            val pageSnapHelper = PagerGridSnapHelper().apply {
-                // 设置滚动阀值
-                setFlingThreshold(minFlingVelocity)
+                        override fun onPageSelect(pageIndex: Int) {
+                            // 当页面被选中时的回调(从 0 开始)
+                        }
+                    })
+                }
+                // 设置滚动辅助工具
+                val pageSnapHelper = PagerGridSnapHelper().apply {
+                    // 设置滚动阀值
+                    setFlingThreshold(minFlingVelocity)
+                }
+                pageSnapHelper.attachToRecyclerView(this)
+            } else {
+                // 不分页,只网格
+                layoutManager = GridLayoutManager(
+                    context,
+                    Constants.AI_KEYBOARD_KEY_LIST_SPAN_COUNT,
+                    GridLayoutManager.VERTICAL,
+                    false
+                )
             }
-            pageSnapHelper.attachToRecyclerView(this)
             // 设置适配器
             adapter = mKeyListAdapter
             // 添加分割线

+ 5 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/constant/Constants.kt

@@ -16,6 +16,11 @@ interface Constants {
         const val AI_KEYBOARD_KEY_LIST_SPAN_COUNT: Int = 3
 
         /**
+         * Ai键盘,按键列表,是否开启翻页
+         */
+        const val AI_KEYBOARD_KEY_LIST_PAGE_ENABLE: Boolean = false
+
+        /**
          * 组件动画,是否开启
          */
         const val COMPONENT_ANIMATOR_ENABLE = false