@@ -17,22 +17,33 @@ import com.tencent.iot.explorer.link.demo.R
1717import com.tencent.iot.explorer.link.demo.core.fragment.BaseFragment
1818import com.tencent.iot.explorer.link.demo.video.nvr.VideoNvrActivity
1919import 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
2124import com.tencent.iot.explorer.link.demo.video.utils.ListOptionsDialog
22- import com.tencent.iot.explorer.link.demo.video.utils.MultipleChannelChooseDialog
2325import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
2426import com.tencent.iot.video.link.callback.VideoCallback
2527import com.tencent.iot.video.link.consts.VideoConst
2628import com.tencent.iot.video.link.consts.VideoRequestCode
2729import 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
3142class 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 }
0 commit comments