Browse Source

[feat]键盘插件,实现粘贴条UI

hezihao 8 months ago
parent
commit
a2bc61dc0d

+ 19 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/AiKeyboardComponent.kt

@@ -6,6 +6,7 @@ import android.view.View
 import com.atmob.keyboard_android.R
 import com.atmob.keyboard_android.component.adapter.AiKeyboardPagerAdapter
 import com.atmob.keyboard_android.component.base.BaseUIComponent
+import com.atmob.keyboard_android.ext.setGone
 import com.atmob.keyboard_android.widget.NoSwipeViewPager
 import com.atmob.keyboard_android.widget.indicator.TabPagerTitleView
 import com.blankj.utilcode.util.ConvertUtils
@@ -24,6 +25,7 @@ import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.Li
 class AiKeyboardComponent @JvmOverloads constructor(
     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
 ) : BaseUIComponent(context, attrs, defStyleAttr) {
+    private lateinit var vTabBarLayout: View
     private lateinit var vMagicIndicator: MagicIndicator
     private lateinit var vViewPager: NoSwipeViewPager
 
@@ -37,11 +39,23 @@ class AiKeyboardComponent @JvmOverloads constructor(
     }
 
     override fun findView(view: View) {
+        vTabBarLayout = view.findViewById(R.id.tar_bar_layout)
         vMagicIndicator = view.findViewById(R.id.magic_indicator)
         vViewPager = view.findViewById(R.id.view_pager)
     }
 
     override fun bindView(view: View) {
+        setupTabBar()
+        setupViewPager()
+    }
+
+    /**
+     * 配置Tab栏
+     */
+    private fun setupTabBar() {
+        // TODO: 隐藏Tab栏,用于测试
+        vTabBarLayout.setGone()
+
         mTabList = listOf(
             "发起聊天",
             "邀约话术",
@@ -106,11 +120,15 @@ class AiKeyboardComponent @JvmOverloads constructor(
                 }
             })
         })
+    }
 
+    /**
+     * 配置ViewPager
+     */
+    private fun setupViewPager() {
         // 配置ViewPager
         vViewPager.setSwipeEnabled(false)
         vViewPager.adapter = AiKeyboardPagerAdapter(mTabList)
-
         // 绑定ViewPager和MagicIndicator
         ViewPagerHelper.bind(vMagicIndicator, vViewPager)
     }

+ 31 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/PasteBarComponent.kt

@@ -0,0 +1,31 @@
+package com.atmob.keyboard_android.component
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.View
+import com.atmob.keyboard_android.R
+import com.atmob.keyboard_android.component.base.BaseUIComponent
+import com.atmob.keyboard_android.ext.click
+
+/**
+ * 粘贴内容栏
+ */
+class PasteBarComponent @JvmOverloads constructor(
+    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : BaseUIComponent(context, attrs, defStyleAttr) {
+    private lateinit var vClearBtn: View
+
+    override fun onInflateViewId(): Int {
+        return R.layout.component_paste_bar
+    }
+
+    override fun findView(view: View) {
+        vClearBtn = view.findViewById(R.id.clear_btn)
+    }
+
+    override fun bindView(view: View) {
+        vClearBtn.click {
+            // 清空输入框内容
+        }
+    }
+}

+ 7 - 0
plugins/keyboard_android/android/src/main/res/drawable/bg_paste_bar.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+
+    <solid android:color="@color/text_color_white" />
+    <corners android:radius="10dp" />
+</shape>

+ 1 - 0
plugins/keyboard_android/android/src/main/res/layout/component_ai_keyboard.xml

@@ -7,6 +7,7 @@
     tools:background="@mipmap/bg_keyboard">
 
     <FrameLayout
+        android:id="@+id/tar_bar_layout"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal"

+ 57 - 26
plugins/keyboard_android/android/src/main/res/layout/component_ai_keyboard_content.xml

@@ -3,40 +3,71 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="horizontal">
+    android:orientation="vertical">
 
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/key_list"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        android:layout_marginStart="10dp"
-        android:layout_weight="1"
-        tools:background="@android:color/holo_blue_dark"
-        tools:layout_height="150dp" />
+    <Space
+        android:layout_width="match_parent"
+        android:layout_height="10dp" />
 
     <LinearLayout
-        android:id="@+id/action_btn_layout"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginStart="6dp"
-        android:layout_marginEnd="10dp"
-        android:orientation="vertical">
+        android:layout_marginBottom="6dp"
+        android:orientation="horizontal">
 
-        <TextView
-            android:id="@+id/delete_btn"
-            style="@style/keyboard_action_btn"
-            android:text="@string/delete" />
+        <com.atmob.keyboard_android.component.PasteBarComponent
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_vertical"
+            android:layout_marginStart="10dp"
+            android:layout_weight="1"
+            tools:background="@android:color/holo_red_dark"
+            tools:layout_height="46dp" />
 
         <TextView
-            android:id="@+id/clear_btn"
-            style="@style/keyboard_action_btn"
+            android:id="@+id/paste_btn"
+            style="@style/keyboard_action_btn2"
+            android:layout_marginStart="10dp"
             android:layout_marginTop="6dp"
-            android:layout_marginBottom="6dp"
-            android:text="@string/clear" />
+            android:layout_marginEnd="10dp"
+            android:text="@string/paste" />
+    </LinearLayout>
 
-        <TextView
-            android:id="@+id/send_btn"
-            style="@style/keyboard_action_btn"
-            android:text="@string/send" />
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <androidx.recyclerview.widget.RecyclerView
+            android:id="@+id/key_list"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="10dp"
+            android:layout_weight="1"
+            tools:background="@android:color/holo_blue_dark"
+            tools:layout_height="150dp" />
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="6dp"
+            android:layout_marginEnd="10dp"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/delete_btn"
+                style="@style/keyboard_action_btn"
+                android:text="@string/delete" />
+
+            <TextView
+                android:id="@+id/clear_btn"
+                style="@style/keyboard_action_btn"
+                android:text="@string/clear" />
+
+            <TextView
+                android:id="@+id/send_btn"
+                style="@style/keyboard_action_btn"
+                android:text="@string/send" />
+        </LinearLayout>
     </LinearLayout>
 </LinearLayout>

+ 43 - 0
plugins/keyboard_android/android/src/main/res/layout/component_paste_bar.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/bg_paste_bar"
+    android:paddingTop="15dp"
+    android:paddingBottom="15dp">
+
+    <LinearLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:gravity="center_vertical"
+        android:orientation="horizontal">
+
+        <ImageView
+            android:id="@+id/tip_symbol"
+            android:layout_width="18dp"
+            android:layout_height="18dp"
+            android:layout_gravity="center_vertical"
+            android:layout_marginTop="1dp"
+            android:layout_marginEnd="4dp"
+            android:src="@mipmap/ic_paste" />
+
+        <androidx.appcompat.widget.AppCompatTextView
+            android:id="@+id/tip"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="@string/paste_tip"
+            android:textColor="@color/text_paste_tip"
+            android:textSize="14sp"
+            android:textStyle="bold" />
+    </LinearLayout>
+
+    <ImageView
+        android:id="@+id/clear_btn"
+        android:layout_width="16dp"
+        android:layout_height="16dp"
+        android:layout_alignParentEnd="true"
+        android:layout_centerVertical="true"
+        android:layout_marginEnd="10dp"
+        android:src="@mipmap/ic_clear_input" />
+</RelativeLayout>

BIN
plugins/keyboard_android/android/src/main/res/mipmap-xxxhdpi/ic_clear_input.png


BIN
plugins/keyboard_android/android/src/main/res/mipmap-xxxhdpi/ic_paste.png


+ 2 - 0
plugins/keyboard_android/android/src/main/res/values/colors.xml

@@ -26,4 +26,6 @@
     <color name="bg_quick_switch_normal">#FFFFFF</color>
     <!-- Tab指示器,选中时的背景颜色 -->
     <color name="bg_tab_indicator_selected">#DDCFFD</color>
+    <!-- 粘贴提示文字 -->
+    <color name="text_paste_tip">#996DFF</color>
 </resources>

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

@@ -12,7 +12,9 @@
     <string name="mode_open_remarks">开场白</string>
     <string name="common_keyboard">通用键盘</string>
     <string name="save">保存</string>
+    <string name="paste">粘贴</string>
     <string name="delete">删除</string>
     <string name="clear">清空</string>
     <string name="send">发送</string>
+    <string name="paste_tip">粘贴你想说的话,润色升华</string>
 </resources>

+ 8 - 0
plugins/keyboard_android/android/src/main/res/values/styles.xml

@@ -46,6 +46,7 @@
         <item name="android:textStyle">bold</item>
     </style>
 
+    <!-- 键盘上的普通操作按钮 -->
     <style name="keyboard_action_btn">
         <item name="android:layout_width">58dp</item>
         <item name="android:layout_height">46dp</item>
@@ -54,5 +55,12 @@
         <item name="android:textColor">@color/text_color_primary</item>
         <item name="android:textSize">12sp</item>
         <item name="android:textStyle">bold</item>
+        <item name="android:layout_marginBottom">6dp</item>
+    </style>
+
+    <!-- 键盘上的粘贴操作按钮 -->
+    <style name="keyboard_action_btn2" parent="keyboard_action_btn">
+        <item name="android:background">@mipmap/bg_action_btn_2</item>
+        <item name="android:textColor">@color/text_color_white</item>
     </style>
 </resources>