@@ -2,11 +2,11 @@ package com.tencent.iot.explorer.link.demo.video
22
33import android.content.ClipboardManager
44import android.content.Intent
5- import android.os.Bundle
65import android.text.InputType
76import android.view.View
87import android.widget.RadioButton
98import androidx.core.content.ContextCompat
9+ import androidx.core.view.isVisible
1010import com.tencent.iot.explorer.link.core.utils.SharePreferenceUtil
1111import com.tencent.iot.explorer.link.demo.R
1212import com.tencent.iot.explorer.link.demo.VideoBaseActivity
@@ -16,12 +16,14 @@ import com.tencent.iot.video.link.consts.VideoConst
1616import kotlinx.coroutines.CoroutineScope
1717import kotlinx.coroutines.MainScope
1818
19- class VideoTestInputActivity : VideoBaseActivity <ActivityVideoTestInputBinding >(), CoroutineScope by MainScope() {
19+ class VideoTestInputActivity : VideoBaseActivity <ActivityVideoTestInputBinding >(),
20+ CoroutineScope by MainScope () {
2021
2122 private var isStartCross = false
2223 private var protocol = " auto"
2324
24- override fun getViewBinding (): ActivityVideoTestInputBinding = ActivityVideoTestInputBinding .inflate(layoutInflater)
25+ override fun getViewBinding (): ActivityVideoTestInputBinding =
26+ ActivityVideoTestInputBinding .inflate(layoutInflater)
2527
2628 override fun initView () {
2729 with (binding) {
@@ -40,10 +42,22 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
4042 VideoConst .VIDEO_CONFIG ,
4143 VideoConst .MULTI_VIDEO_P2P_INFO
4244 )
45+ val appKey = SharePreferenceUtil .getString(
46+ this @VideoTestInputActivity,
47+ VideoConst .VIDEO_CONFIG ,
48+ VideoConst .VIDEO_APP_KEY
49+ )
50+ val appSecret = SharePreferenceUtil .getString(
51+ this @VideoTestInputActivity,
52+ VideoConst .VIDEO_CONFIG ,
53+ VideoConst .VIDEO_APP_SECRET
54+ )
4355 vTitle.tvTitle.setText(R .string.iot_test_demo_name)
44- productIdLayout.tvTip.setText(R .string.product_id)
45- deviceNameLayout.tvTip.setText(R .string.device_name)
46- p2pInfoLayout.tvTip.setText(R .string.p2p_info)
56+ productIdLayout.tvTip.setText(R .string.product_id_text)
57+ deviceNameLayout.tvTip.setText(R .string.device_name_text)
58+ p2pInfoLayout.tvTip.setText(R .string.p2p_info_text)
59+ appKeyLayout.tvTip.setText(R .string.app_key_text)
60+ appSecretLayout.tvTip.setText(R .string.app_secret)
4761 if (productId.isNotEmpty()) {
4862 productIdLayout.evContent.setText(productId)
4963 }
@@ -59,6 +73,16 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
5973 }
6074 p2pInfoLayout.evContent.setHint(R .string.hint_p2p_info)
6175 p2pInfoLayout.evContent.inputType = InputType .TYPE_CLASS_TEXT
76+ if (appKey.isNotEmpty()) {
77+ appKeyLayout.evContent.setText(appKey)
78+ }
79+ appKeyLayout.evContent.setHint(R .string.hint_app_key)
80+ appKeyLayout.evContent.inputType = InputType .TYPE_CLASS_TEXT
81+ if (appSecret.isNotEmpty()) {
82+ appSecretLayout.evContent.setText(appSecret)
83+ }
84+ appSecretLayout.evContent.setHint(R .string.hint_app_secret)
85+ appSecretLayout.evContent.inputType = InputType .TYPE_CLASS_TEXT
6286 }
6387 }
6488
@@ -67,20 +91,43 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
6791 vTitle.ivBack.setOnClickListener { finish() }
6892 btnLogin.setOnClickListener(loginClickedListener)
6993 btnPaste.setOnClickListener {
70- val clipboard = ContextCompat .getSystemService(this @VideoTestInputActivity, ClipboardManager ::class .java);
94+ val clipboard = ContextCompat .getSystemService(
95+ this @VideoTestInputActivity,
96+ ClipboardManager ::class .java
97+ )
7198 if (clipboard != null && clipboard.hasPrimaryClip()) {
7299 clipboard.primaryClip?.getItemAt(0 )?.text.toString().split(" \n " )
73100 .forEachIndexed { index, s ->
74101 when (index) {
75102 0 -> productIdLayout.evContent.setText(s)
76103 1 -> deviceNameLayout.evContent.setText(s)
77104 2 -> p2pInfoLayout.evContent.setText(s)
105+ 3 -> appKeyLayout.evContent.setText(s)
106+ 4 -> appSecretLayout.evContent.setText(s)
107+ }
108+ }
109+ }
110+ }
111+ btnAppPaste.setOnClickListener {
112+ val clipboard = ContextCompat .getSystemService(
113+ this @VideoTestInputActivity,
114+ ClipboardManager ::class .java
115+ )
116+ if (clipboard != null && clipboard.hasPrimaryClip()) {
117+ clipboard.primaryClip?.getItemAt(0 )?.text.toString().split(" \n " )
118+ .forEachIndexed { index, s ->
119+ when (index) {
120+ 0 -> appKeyLayout.evContent.setText(s)
121+ 1 -> appSecretLayout.evContent.setText(s)
78122 }
79123 }
80124 }
81125 }
82126 swtCross.setOnCheckedChangeListener { _, checked ->
83127 isStartCross = checked
128+ btnAppPaste.isVisible = checked
129+ appKeyLayout.root.isVisible = checked
130+ appSecretLayout.root.isVisible = checked
84131 }
85132 rgProtocol.setOnCheckedChangeListener { group, checkedId ->
86133 protocol = group.findViewById<RadioButton >(checkedId).tag.toString()
@@ -115,6 +162,30 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
115162 show(getString(R .string.hint_p2p_info))
116163 return
117164 }
165+ if (isStartCross) {
166+ if (appKeyLayout.evContent.text.isNullOrEmpty()) {
167+ show(getString(R .string.hint_app_key))
168+ return
169+ }
170+ SharePreferenceUtil .saveString(
171+ this @VideoTestInputActivity,
172+ VideoConst .VIDEO_CONFIG ,
173+ VideoConst .VIDEO_APP_KEY ,
174+ appKeyLayout.evContent.text.toString()
175+ )
176+ if (appSecretLayout.evContent.text.isNullOrEmpty()) {
177+ show(getString(R .string.hint_app_secret))
178+ return
179+ }
180+ if (appSecretLayout.evContent.text.isNotEmpty()) {
181+ SharePreferenceUtil .saveString(
182+ this @VideoTestInputActivity,
183+ VideoConst .VIDEO_CONFIG ,
184+ VideoConst .VIDEO_APP_SECRET ,
185+ appSecretLayout.evContent.text.toString()
186+ )
187+ }
188+ }
118189 SharePreferenceUtil .saveString(
119190 this @VideoTestInputActivity,
120191 VideoConst .VIDEO_CONFIG ,
@@ -125,6 +196,8 @@ class VideoTestInputActivity : VideoBaseActivity<ActivityVideoTestInputBinding>(
125196 intent.putExtra(" productId" , productIdLayout.evContent.text.toString())
126197 intent.putExtra(" deviceName" , deviceNameLayout.evContent.text.toString())
127198 intent.putExtra(" p2pInfo" , p2pInfoLayout.evContent.text.toString())
199+ intent.putExtra(" appKey" , appKeyLayout.evContent.text.toString())
200+ intent.putExtra(" appSecret" , appSecretLayout.evContent.text.toString())
128201 intent.putExtra(" isStartCross" , isStartCross)
129202 intent.putExtra(" protocol" , protocol)
130203 startActivity(intent)
0 commit comments