Skip to content

File tree

11 files changed

+177
-3
lines changed

11 files changed

+177
-3
lines changed

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/consts/RequestCode.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object RequestCode {
6868
const val get_bind_device_token = 3012
6969
const val check_device_bind_token_state = 3013
7070
const val trtc_call_device = 3015
71-
71+
const val all_device = 3016
7272
/*************设备接口结束**************/
7373

7474
/*************云端定时接口开始**************/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.tencent.iot.explorer.link.core.auth.entity
2+
3+
class VirtualBindDevice {
4+
5+
var userId = ""
6+
var productId = ""
7+
var deviceName = ""
8+
var deviceId = ""
9+
var platformId = ""
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.tencent.iot.explorer.link.core.auth.entity
2+
3+
class VirtualBindDeviceList {
4+
var requestId = ""
5+
var totalCount = 0
6+
var virtualBindDeviceList: MutableList<VirtualBindDevice> = ArrayList()
7+
}

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/impl/DeviceImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,9 @@ interface DeviceImpl {
140140
*/
141141
fun trtcCallDevice(deviceId: String, callback: MyCallback)
142142

143-
}
143+
/**
144+
* 获取所有设备
145+
*/
146+
fun allDevices(token: String, platformId: String, offset: Int, limit: Int, callback: MyCallback)
147+
148+
}

sdk/explorer-link-android/src/main/java/com/tencent/iot/explorer/link/core/auth/service/DeviceService.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ internal class DeviceService : BaseService(), DeviceImpl {
147147
})
148148
}
149149

150+
/**
151+
* 获取所有设备
152+
*/
153+
override fun allDevices(token: String, platformId: String, offset: Int, limit: Int, callback: MyCallback) {
154+
val param = tokenParams("AppGetVirtualBindDeviceList")
155+
param["BindPlatformId"] = platformId
156+
param["Offset"] = offset
157+
param["Limit"] = limit
158+
param["AccessToken"] = token
159+
tokenPost(param, callback, RequestCode.all_device)
160+
}
161+
150162
/**
151163
* 获取设备在线状态
152164
*/

sdkdemo/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<activity android:name=".core.activity.QrcodeConfigNetActivity" />
5252
<activity android:name=".core.activity.ApConfigNetActivity" />
5353
<activity android:name=".core.activity.WiredConfigNetActivity" />
54+
<activity android:name=".core.activity.ShowAllDeviceActivity" />
5455
<activity android:name=".video.VideoOptionsActivity" />
5556
<activity android:name=".video.VideoInputAuthorizeActivity" />
5657
<activity android:name=".video.VideoMainActivity" />
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.tencent.iot.explorer.link.demo.core.activity
2+
3+
import android.text.TextUtils
4+
import android.widget.Toast
5+
import com.alibaba.fastjson.JSON
6+
import com.tencent.iot.explorer.link.core.auth.IoTAuth
7+
import com.tencent.iot.explorer.link.core.auth.callback.MyCallback
8+
import com.tencent.iot.explorer.link.core.auth.entity.VirtualBindDeviceList
9+
import com.tencent.iot.explorer.link.core.auth.response.BaseResponse
10+
import com.tencent.iot.explorer.link.demo.BaseActivity
11+
import com.tencent.iot.explorer.link.demo.R
12+
import com.tencent.iot.explorer.link.demo.common.log.L
13+
import kotlinx.android.synthetic.main.activity_show_all_device.*
14+
import kotlinx.android.synthetic.main.menu_back_layout.*
15+
16+
class ShowAllDeviceActivity : BaseActivity(), MyCallback {
17+
override fun getContentView(): Int {
18+
return R.layout.activity_show_all_device
19+
}
20+
21+
override fun initView() {
22+
tv_title.text = getString(R.string.show_all_device)
23+
}
24+
25+
override fun setListener() {
26+
iv_back.setOnClickListener { finish() }
27+
btn_search.setOnClickListener {
28+
tv_all_devices.text = ""
29+
var token = IoTAuth.user.Token
30+
var platformId = ev_platformId_2_search.text.toString()
31+
if (!TextUtils.isEmpty(ev_token_2_search.text.toString())) {
32+
token = ev_token_2_search.text.toString()
33+
}
34+
35+
IoTAuth.deviceImpl.allDevices(token, platformId, 0, 99, this)
36+
}
37+
}
38+
39+
override fun fail(msg: String?, reqCode: Int) {
40+
L.e(msg ?: "")
41+
}
42+
43+
override fun success(response: BaseResponse, reqCode: Int) {
44+
45+
runOnUiThread {
46+
if (response.code == 0) {
47+
var virtualBindDeviceList = JSON.parseObject(response.data.toString(), VirtualBindDeviceList::class.java)
48+
virtualBindDeviceList?.let {
49+
if (it.totalCount <= 0) {
50+
Toast.makeText(this@ShowAllDeviceActivity, R.string.no_devices, Toast.LENGTH_SHORT).show()
51+
return@let
52+
}
53+
var content2Show = ""
54+
55+
if (it.virtualBindDeviceList.size <= 0) return@let
56+
for (item in it.virtualBindDeviceList) {
57+
content2Show += item.deviceName + "\n"
58+
}
59+
tv_all_devices.text = content2Show
60+
}
61+
} else {
62+
Toast.makeText(this@ShowAllDeviceActivity, response?.msg, Toast.LENGTH_SHORT).show()
63+
}
64+
}
65+
}
66+
}

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/core/fragment/DeviceFragment.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.tencent.iot.explorer.link.demo.core.fragment
22

3+
import android.content.Intent
34
import android.util.Log
45
import android.view.View
56
import androidx.recyclerview.widget.LinearLayoutManager
@@ -22,6 +23,7 @@ import com.tencent.iot.explorer.link.demo.core.activity.ControlPanelActivity
2223
import com.tencent.iot.explorer.link.demo.core.adapter.OnItemListener
2324
import com.tencent.iot.explorer.link.demo.core.holder.BaseHolder
2425
import com.tencent.iot.explorer.link.demo.common.customView.MyDivider
26+
import com.tencent.iot.explorer.link.demo.core.activity.ShowAllDeviceActivity
2527
import kotlinx.android.synthetic.main.fragment_device.*
2628

2729
class DeviceFragment : BaseFragment(), MyCallback {
@@ -60,6 +62,9 @@ class DeviceFragment : BaseFragment(), MyCallback {
6062
}
6163

6264
private fun setListener() {
65+
tv_show_all_device.setOnClickListener {
66+
jumpActivity(ShowAllDeviceActivity::class.java)
67+
}
6368
tv_add_device.setOnClickListener {
6469
jumpActivity(AddDeviceActivity::class.java)
6570
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="@color/white">
7+
8+
<include layout="@layout/menu_back_layout"
9+
android:id="@+id/menu_all_device"/>
10+
11+
<androidx.constraintlayout.widget.ConstraintLayout
12+
android:layout_width="match_parent"
13+
android:layout_height="0dp"
14+
android:paddingLeft="15dp"
15+
android:paddingRight="15dp"
16+
android:paddingTop="15dp"
17+
app:layout_constraintBottom_toBottomOf="parent"
18+
app:layout_constraintTop_toBottomOf="@id/menu_all_device">
19+
20+
<EditText
21+
android:id="@+id/ev_token_2_search"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
app:layout_constraintTop_toTopOf="parent"
25+
android:hint="AccessToken"
26+
/>
27+
<EditText
28+
android:id="@+id/ev_platformId_2_search"
29+
android:layout_width="match_parent"
30+
android:layout_height="wrap_content"
31+
app:layout_constraintTop_toBottomOf="@id/ev_token_2_search"
32+
android:hint="platformId"
33+
/>
34+
35+
<Button
36+
android:layout_width="wrap_content"
37+
android:layout_height="wrap_content"
38+
android:id="@+id/btn_search"
39+
app:layout_constraintTop_toBottomOf="@id/ev_platformId_2_search"
40+
android:text="@string/show_all_device"
41+
app:layout_constraintStart_toStartOf="parent"/>
42+
43+
<TextView
44+
android:layout_width="match_parent"
45+
android:layout_height="0dp"
46+
android:id="@+id/tv_all_devices"
47+
app:layout_constraintTop_toBottomOf="@id/btn_search"
48+
app:layout_constraintBottom_toBottomOf="parent"
49+
/>
50+
51+
</androidx.constraintlayout.widget.ConstraintLayout>
52+
53+
54+
55+
</androidx.constraintlayout.widget.ConstraintLayout>

sdkdemo/src/main/res/layout/fragment_device.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
android:gravity="center"
2828
android:text="@string/add_device" />
2929

30+
<TextView
31+
android:id="@+id/tv_show_all_device"
32+
android:layout_alignParentStart="true"
33+
android:layout_marginStart="20dp"
34+
android:textSize="16sp"
35+
android:textColor="@color/black_333333"
36+
android:gravity="center"
37+
android:layout_width="wrap_content"
38+
android:layout_height="match_parent"
39+
android:text="@string/show_all_device" />
40+
/>
41+
3042
</RelativeLayout>
3143

3244
<androidx.recyclerview.widget.RecyclerView

0 commit comments

Comments
 (0)