Skip to content

Commit fc02beb

Browse files
committed
UI 代码格式修改
1 parent fdcd1a1 commit fc02beb

File tree

4 files changed

+94
-55
lines changed

4 files changed

+94
-55
lines changed

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/VideoDeviceFragment.kt

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,33 @@ import com.tencent.iot.explorer.link.demo.R
1717
import com.tencent.iot.explorer.link.demo.core.fragment.BaseFragment
1818
import com.tencent.iot.explorer.link.demo.video.nvr.VideoNvrActivity
1919
import com.tencent.iot.explorer.link.demo.video.playback.VideoPlaybackActivity
20-
import com.tencent.iot.explorer.link.demo.video.preview.*
20+
import com.tencent.iot.explorer.link.demo.video.preview.DevUrl2Preview
21+
import com.tencent.iot.explorer.link.demo.video.preview.VideoPreviewActivity
22+
import com.tencent.iot.explorer.link.demo.video.preview.VideoPreviewMJPEGActivity
23+
import com.tencent.iot.explorer.link.demo.video.preview.VideoPushStreamActivity
2124
import com.tencent.iot.explorer.link.demo.video.utils.ListOptionsDialog
22-
import com.tencent.iot.explorer.link.demo.video.utils.MultipleChannelChooseDialog
2325
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
2426
import com.tencent.iot.video.link.callback.VideoCallback
2527
import com.tencent.iot.video.link.consts.VideoConst
2628
import com.tencent.iot.video.link.consts.VideoRequestCode
2729
import com.tencent.iot.video.link.service.VideoBaseService
28-
import kotlinx.android.synthetic.main.fragment_video_device.*
29-
import kotlinx.coroutines.*
30+
import kotlinx.android.synthetic.main.fragment_video_device.gv_devs
31+
import kotlinx.android.synthetic.main.fragment_video_device.radio_complete
32+
import kotlinx.android.synthetic.main.fragment_video_device.radio_edit
33+
import kotlinx.android.synthetic.main.fragment_video_device.rg_edit_dev
34+
import kotlinx.android.synthetic.main.fragment_video_device.smart_refresh_layout
35+
import kotlinx.android.synthetic.main.fragment_video_device.tv_tip_txt
36+
import kotlinx.coroutines.CoroutineScope
37+
import kotlinx.coroutines.Dispatchers
38+
import kotlinx.coroutines.MainScope
39+
import kotlinx.coroutines.cancel
40+
import kotlinx.coroutines.launch
3041

3142
class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemClicked,
3243
CoroutineScope by MainScope() {
33-
private var devs : MutableList<DevInfo> = ArrayList()
34-
private var adapter : DevsAdapter? = null
35-
private var videoProductInfo : VideoProductInfo? = null
44+
private var devs: MutableList<DevInfo> = ArrayList()
45+
private var adapter: DevsAdapter? = null
46+
private var videoProductInfo: VideoProductInfo? = null
3647

3748
override fun getContentView(): Int {
3849
return R.layout.fragment_video_device
@@ -41,7 +52,7 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
4152
override fun startHere(view: View) {
4253
setListener()
4354

44-
var devGridLayoutManager = GridLayoutManager(context, 2)
55+
val devGridLayoutManager = GridLayoutManager(context, 2)
4556
context?.let {
4657
adapter = DevsAdapter(it, devs)
4758
adapter?.let {
@@ -50,8 +61,8 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
5061
}
5162
adapter?.radioComplete = radio_complete
5263
adapter?.radioEdit = radio_edit
53-
gv_devs.setLayoutManager(devGridLayoutManager)
54-
gv_devs.setAdapter(adapter)
64+
gv_devs.layoutManager = devGridLayoutManager
65+
gv_devs.adapter = adapter
5566
loadAllVideoInfo()
5667
}
5768
adapter?.switchBtnStatus(false)
@@ -64,12 +75,8 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
6475

6576
private fun setListener() {
6677
radio_edit.setOnClickListener {
67-
var options = arrayListOf(getString(R.string.edit_devs_2_show))
68-
var dlg =
69-
ListOptionsDialog(
70-
context,
71-
options
72-
)
78+
val options = arrayListOf(getString(R.string.edit_devs_2_show))
79+
val dlg = ListOptionsDialog(context, options)
7380
dlg.show()
7481
dlg.setOnDismisListener {
7582
adapter?.switchBtnStatus(true)
@@ -101,10 +108,10 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
101108
}
102109

103110
adapter?.let {
104-
var allUrl = ArrayList<DevUrl2Preview>()
111+
val allUrl = ArrayList<DevUrl2Preview>()
105112
for (i in 0 until it.list.size) {
106113
if (it.checkedIds.contains(i)) {
107-
var dev = DevUrl2Preview()
114+
val dev = DevUrl2Preview()
108115
dev.devName = it.list.get(i).DeviceName
109116
dev.Status = it.list.get(i).Status
110117
allUrl.add(dev)
@@ -117,28 +124,45 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
117124

118125
override fun onItemClicked(pos: Int, dev: DevInfo) {
119126
if (videoProductInfo?.DeviceType == VideoProductInfo.DEV_TYPE_NVR) {
120-
var intent = Intent(context, VideoNvrActivity::class.java)
121-
var bundle = Bundle()
127+
val intent = Intent(context, VideoNvrActivity::class.java)
128+
val bundle = Bundle()
122129
bundle.putString(VideoConst.VIDEO_NVR_INFO, JSON.toJSONString(dev))
123130
intent.putExtra(VideoConst.VIDEO_NVR_INFO, bundle)
124131
startActivity(intent)
125132
return
126133
}
127134

128-
var options = arrayListOf(getString(R.string.preview), getString(R.string.playback), getString(R.string.preview_mjpeg), getString(R.string.video_without_property), getString(R.string.video_push_stream), getString(R.string.multiple_channel_choose))
129-
var dlg =
135+
val options = arrayListOf(
136+
getString(R.string.preview),
137+
getString(R.string.playback),
138+
getString(R.string.preview_mjpeg),
139+
getString(R.string.video_without_property),
140+
getString(R.string.video_push_stream),
141+
getString(R.string.multiple_channel_choose)
142+
)
143+
val dlg =
130144
ListOptionsDialog(
131145
context,
132146
options
133147
)
134148
dlg.show()
135149
dlg.setOnDismisListener { it ->
136-
when(it) {
137-
0 -> { VideoPreviewActivity.startPreviewActivity(context, dev) }
138-
1 -> { VideoPlaybackActivity.startPlaybackActivity(context, dev) }
139-
2 -> { VideoPreviewMJPEGActivity.startPreviewActivity(context, dev) }
150+
when (it) {
151+
0 -> {
152+
VideoPreviewActivity.startPreviewActivity(context, dev)
153+
}
154+
155+
1 -> {
156+
VideoPlaybackActivity.startPlaybackActivity(context, dev)
157+
}
158+
159+
2 -> {
160+
VideoPreviewMJPEGActivity.startPreviewActivity(context, dev)
161+
}
140162
// 3 -> { VideoWithoutPropertyActivity.startPreviewActivity(context, dev) }
141-
4 -> { VideoPushStreamActivity.startPreviewActivity(context, dev) }
163+
4 -> {
164+
VideoPushStreamActivity.startPreviewActivity(context, dev)
165+
}
142166
// 5 -> {
143167
// val multipleChannelChooseDialog = MultipleChannelChooseDialog(context)
144168
// multipleChannelChooseDialog.show()
@@ -158,6 +182,7 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
158182
}
159183
}
160184
}
185+
161186
override fun onItemMoreClicked(pos: Int, dev: DevInfo) {}
162187
override fun onItemCheckedClicked(pos: Int, checked: Boolean) {}
163188
override fun onItemCheckedLimited() {
@@ -176,7 +201,7 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
176201
}
177202

178203
override fun fail(msg: String?, reqCode: Int) {
179-
launch (Dispatchers.Main) {
204+
launch(Dispatchers.Main) {
180205
adapter?.notifyDataSetChanged()
181206
smart_refresh_layout?.finishRefresh()
182207
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
@@ -192,12 +217,12 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
192217
if (jsonResponset.containsKey("Devices")) {
193218
val dataArray: JSONArray = jsonResponset.getJSONArray("Devices")
194219
for (i in 0 until dataArray.size) {
195-
var dev = JSON.parseObject(dataArray.getString(i), DevInfo::class.java)
220+
val dev = JSON.parseObject(dataArray.getString(i), DevInfo::class.java)
196221
devs.add(dev)
197222
}
198223
}
199224

200-
launch (Dispatchers.Main) {
225+
launch(Dispatchers.Main) {
201226
adapter?.videoProductInfo = videoProductInfo
202227
adapter?.notifyDataSetChanged()
203228
if (adapter?.videoProductInfo?.DeviceType == VideoProductInfo.DEV_TYPE_IPC) {
@@ -222,7 +247,12 @@ class VideoDeviceFragment : BaseFragment(), VideoCallback, DevsAdapter.OnItemCli
222247
videoProductInfo?.let {
223248
App.data.accessInfo?.let {
224249
devs.clear()
225-
VideoBaseService(it.accessId, it.accessToken).describeDevices(it.productId, 99, 0, this)
250+
VideoBaseService(it.accessId, it.accessToken).describeDevices(
251+
it.productId,
252+
99,
253+
0,
254+
this
255+
)
226256
}
227257
}
228258
}

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/VideoInputAuthorizeActivity.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.android.synthetic.main.blue_title_layout.*
1818
import kotlinx.android.synthetic.main.input_item_layout.view.*
1919
import kotlinx.coroutines.*
2020

21-
class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by MainScope() {
21+
class VideoInputAuthorizeActivity : VideoBaseActivity(), CoroutineScope by MainScope() {
2222

2323
override fun getContentView(): Int {
2424
return R.layout.activity_video_input_authorize
@@ -37,20 +37,24 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
3737
access_token_layout.iv_more.visibility = View.GONE
3838
product_id_layout.iv_more.visibility = View.GONE
3939

40-
launch (Dispatchers.Main) {
41-
var jsonArrStr = SharePreferenceUtil.getString(this@VideoInputAuthorizeActivity, VideoConst.VIDEO_CONFIG, VideoConst.VIDEO_ACCESS_INFOS)
40+
launch(Dispatchers.Main) {
41+
val jsonArrStr = SharePreferenceUtil.getString(
42+
this@VideoInputAuthorizeActivity,
43+
VideoConst.VIDEO_CONFIG,
44+
VideoConst.VIDEO_ACCESS_INFOS
45+
)
4246
jsonArrStr?.let {
43-
var accessInfos = JSONArray.parseArray(jsonArrStr, AccessInfo::class.java)
47+
val accessInfos = JSONArray.parseArray(jsonArrStr, AccessInfo::class.java)
4448
accessInfos?.let {
4549
if (accessInfos.size > 0) {
46-
var accessInfo = accessInfos.get(accessInfos.size - 1)
50+
val accessInfo = accessInfos.get(accessInfos.size - 1)
4751
access_id_layout.ev_content.setText(accessInfo.accessId)
4852
access_token_layout.ev_content.setText(accessInfo.accessToken)
4953
product_id_layout.ev_content.setText(accessInfo.productId)
5054
access_id_layout.ev_content.setSelection(accessInfo.accessId.length)
5155
}
5256

53-
}?:let{
57+
} ?: let {
5458
access_id_layout.ev_content.setText(BuildConfig.TencentIotLinkVideoSDKDemoSecretId)
5559
access_token_layout.ev_content.setText(BuildConfig.TencentIotLinkVideoSDKDemoSecretKey)
5660
product_id_layout.ev_content.setText(BuildConfig.TencentIotLinkVideoSDKDemoProductId)
@@ -64,10 +68,7 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
6468
iv_back.setOnClickListener { finish() }
6569
btn_login.setOnClickListener(loginClickedListener)
6670
access_id_layout.setOnClickListener {
67-
var dlg =
68-
HistoryAccessInfoDialog(
69-
this@VideoInputAuthorizeActivity
70-
)
71+
val dlg = HistoryAccessInfoDialog(this@VideoInputAuthorizeActivity)
7172
dlg.show()
7273
dlg.setOnDismissListener(onDlgDismissListener)
7374
}
@@ -78,7 +79,7 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
7879
cancel()
7980
}
8081

81-
var loginClickedListener = object : View.OnClickListener {
82+
private var loginClickedListener = object : View.OnClickListener {
8283
override fun onClick(v: View?) {
8384
if (!btn_use_sdk.isChecked) {
8485
Toast.makeText(
@@ -113,17 +114,17 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
113114
return
114115
}
115116

116-
var accessInfo = AccessInfo()
117+
val accessInfo = AccessInfo()
117118
accessInfo.accessId = access_id_layout.ev_content.text.toString()
118119
accessInfo.accessToken = access_token_layout.ev_content.text.toString()
119120
accessInfo.productId = product_id_layout.ev_content.text.toString()
120121

121-
launch (Dispatchers.Main) {
122+
launch(Dispatchers.Main) {
122123
checkAccessInfo(accessInfo)
123124
}
124125

125-
var intent = Intent(this@VideoInputAuthorizeActivity, VideoMainActivity::class.java)
126-
var bundle = Bundle()
126+
val intent = Intent(this@VideoInputAuthorizeActivity, VideoMainActivity::class.java)
127+
val bundle = Bundle()
127128
bundle.putString(VideoConst.VIDEO_CONFIG, JSONObject.toJSONString(accessInfo))
128129
intent.putExtra(VideoConst.VIDEO_CONFIG, bundle)
129130
startActivity(intent)
@@ -132,14 +133,16 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
132133

133134
private fun checkAccessInfo(accessInfo: AccessInfo) {
134135

135-
var jsonArrStr = SharePreferenceUtil.getString(this@VideoInputAuthorizeActivity, VideoConst.VIDEO_CONFIG, VideoConst.VIDEO_ACCESS_INFOS)
136+
val jsonArrStr = SharePreferenceUtil.getString(
137+
this@VideoInputAuthorizeActivity,
138+
VideoConst.VIDEO_CONFIG,
139+
VideoConst.VIDEO_ACCESS_INFOS
140+
)
136141
var accessInfos: MutableList<AccessInfo> = ArrayList()
137142
jsonArrStr?.let {
138143
try {
139144
accessInfos = JSONArray.parseArray(it, AccessInfo::class.java)
140-
accessInfos?.let {
141-
if(it.contains(accessInfo)) it.remove(accessInfo)
142-
}
145+
accessInfos.let { info -> if (info.contains(accessInfo)) info.remove(accessInfo) }
143146
} catch (e: Exception) {
144147
e.printStackTrace()
145148
accessInfos = ArrayList()
@@ -148,10 +151,15 @@ class VideoInputAuthorizeActivity : VideoBaseActivity() , CoroutineScope by Main
148151

149152
// 保证最后一条是最新使用过的数据
150153
accessInfos.add(accessInfo)
151-
SharePreferenceUtil.saveString(this@VideoInputAuthorizeActivity, VideoConst.VIDEO_CONFIG, VideoConst.VIDEO_ACCESS_INFOS, JSONArray.toJSONString(accessInfos))
154+
SharePreferenceUtil.saveString(
155+
this@VideoInputAuthorizeActivity,
156+
VideoConst.VIDEO_CONFIG,
157+
VideoConst.VIDEO_ACCESS_INFOS,
158+
JSONArray.toJSONString(accessInfos)
159+
)
152160
}
153161

154-
var onDlgDismissListener = object : HistoryAccessInfoDialog.OnDismisListener {
162+
private var onDlgDismissListener = object : HistoryAccessInfoDialog.OnDismisListener {
155163
override fun onOkClicked(accessInfo: AccessInfo?) {
156164
accessInfo?.let {
157165
access_id_layout.ev_content.setText(accessInfo.accessId)

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/VideoMainActivity.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import com.alibaba.fastjson.JSONObject
66
import com.google.android.material.tabs.TabLayout
77
import com.tencent.iot.explorer.link.demo.App
88
import com.tencent.iot.explorer.link.demo.R
9-
import com.tencent.iot.explorer.link.demo.BaseActivity
109
import com.tencent.iot.explorer.link.demo.VideoBaseActivity
1110
import com.tencent.iot.video.link.consts.VideoConst
12-
import kotlinx.android.synthetic.main.activity_main.*
13-
import kotlinx.android.synthetic.main.title_layout.*
11+
import kotlinx.android.synthetic.main.activity_main.tb_bottom
12+
import kotlinx.android.synthetic.main.title_layout.tv_title
1413

1514
class VideoMainActivity : VideoBaseActivity() {
1615
private val fragments = arrayListOf<Fragment>()

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoTestActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import kotlinx.android.synthetic.main.dash_board_layout.tv_tcp_speed
5656
import kotlinx.android.synthetic.main.dash_board_layout.tv_v_cache
5757
import kotlinx.android.synthetic.main.dash_board_layout.tv_video_w_h
5858
import kotlinx.android.synthetic.main.title_layout.iv_back
59+
import kotlinx.android.synthetic.main.title_layout.tv_title
5960
import kotlinx.coroutines.CoroutineScope
6061
import kotlinx.coroutines.Dispatchers
6162
import kotlinx.coroutines.MainScope
@@ -114,6 +115,7 @@ class VideoTestActivity : VideoBaseActivity(), XP2PCallback, CoroutineScope by M
114115
deviceName = intent.getStringExtra("deviceName")?.toString() ?: ""
115116
xp2pInfo = intent.getStringExtra("p2pInfo")?.toString() ?: ""
116117
xP2PAppConfig.autoConfigFromDevice = intent.getBooleanExtra("isStartCross", false)
118+
tv_title.text = deviceName
117119
val protocol = intent.getStringExtra("protocol")?.toString() ?: "auto"
118120
if (protocol == "udp") {
119121
xP2PAppConfig.type = XP2PProtocolType.XP2P_PROTOCOL_UDP

0 commit comments

Comments
 (0)