Skip to content

Commit 93a2a18

Browse files
committed
增加一键粘贴参数功能
1 parent 98e14b1 commit 93a2a18

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

app/src/main/java/com/example/ivdemo/popup/DeviceSettingDialog.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.example.ivdemo.popup
22

3+
import android.content.ClipboardManager
34
import android.content.Context
45
import android.text.Editable
56
import android.text.TextWatcher
67
import android.view.View
78
import android.widget.RadioButton
89
import android.widget.Toast
10+
import androidx.core.content.ContextCompat
911
import androidx.fragment.app.FragmentManager
1012
import com.tencent.iot.twcall.databinding.PopupDeviceSettingLayoutBinding
13+
import com.tencent.iotvideo.link.entity.UserEntity
1114
import com.tencent.iotvideo.link.util.DeviceSetting
1215
import com.tencent.iotvideo.link.util.updateOperate
1316

@@ -16,6 +19,9 @@ class DeviceSettingDialog(private val context: Context) :
1619

1720
private val deviceSetting by lazy { DeviceSetting.getInstance(context) }
1821
private var ipcType: Int = 2
22+
private var wxAppId: String? = null
23+
private var modelId: String? = null
24+
private var openId: String? = null
1925
private val textWatcher = object : TextWatcher {
2026
override fun beforeTextChanged(
2127
s: CharSequence?,
@@ -57,6 +63,23 @@ class DeviceSettingDialog(private val context: Context) :
5763
rgSelectWay.setOnCheckedChangeListener { group, checkedId ->
5864
ipcType = group.findViewById<RadioButton>(checkedId).tag.toString().toInt()
5965
}
66+
btnPaste.setOnClickListener {
67+
val clipboard =
68+
ContextCompat.getSystemService(context, ClipboardManager::class.java);
69+
if (clipboard != null && clipboard.hasPrimaryClip()) {
70+
clipboard.primaryClip?.getItemAt(0)?.text.toString().split("\n")
71+
.forEachIndexed { index, s ->
72+
when (index) {
73+
0 -> binding.etLoginProductId.setText(s)
74+
1 -> binding.etLoginDeviceName.setText(s)
75+
2 -> binding.etLoginDeviceKey.setText(s)
76+
3 -> wxAppId = s
77+
4 -> modelId = s
78+
5 -> openId = s
79+
}
80+
}
81+
}
82+
}
6083

6184
btnConfirm.setOnClickListener(View.OnClickListener {
6285
if (!checkDeviceInfo()) {
@@ -83,6 +106,15 @@ class DeviceSettingDialog(private val context: Context) :
83106
deviceSetting.productId = etLoginProductId.text.toString()
84107
deviceSetting.deviceName = etLoginDeviceName.text.toString()
85108
deviceSetting.deviceKey = etLoginDeviceKey.text.toString()
109+
wxAppId?.let {
110+
deviceSetting.appId = it
111+
}
112+
modelId?.let {
113+
deviceSetting.modelId = it
114+
}
115+
openId?.let {
116+
deviceSetting.addOnlyEntity(UserEntity(openId, false))
117+
}
86118
}
87119
}
88120

app/src/main/res/layout/popup_device_setting_layout.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@
8888
<!-- android:inputType="textMultiLine"-->
8989
<!-- android:lines="6"-->
9090
<!-- android:textSize="15sp" />-->
91+
<LinearLayout
92+
android:layout_width="match_parent"
93+
android:layout_height="wrap_content">
94+
<Button
95+
android:id="@+id/btn_paste"
96+
android:layout_width="66dp"
97+
android:layout_height="32dp"
98+
android:layout_marginTop="8dp"
99+
android:background="@drawable/background_blue_cell_btn"
100+
android:text="粘贴"
101+
android:textColor="@color/blue_0052D9"
102+
android:textStyle="bold"/>
103+
104+
<TextView
105+
android:layout_width="wrap_content"
106+
android:layout_height="wrap_content"
107+
android:layout_marginStart="6dp"
108+
android:text="(注:按以下顺序与换行进行分割,ProductId/DeviceName/DeviceKey/AppId/ModelId/OpenId)"
109+
android:textSize="8sp" />
110+
</LinearLayout>
91111

92112
<LinearLayout
93113
android:layout_width="match_parent"

0 commit comments

Comments
 (0)