diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt index b34e86243..349ff9f9e 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/DeviceCategoryActivity.kt @@ -40,6 +40,8 @@ import com.tencent.iot.explorer.link.core.link.entity.TrtcDeviceInfo import com.tencent.iot.explorer.link.customview.recyclerview.CRecyclerView import com.tencent.iot.explorer.link.kitlink.consts.CommonField import com.tencent.iot.explorer.link.kitlink.consts.LoadViewTxtType +import com.tencent.iot.explorer.link.kitlink.entity.BindDevResponse +import com.tencent.iot.explorer.link.kitlink.entity.GatewaySubDevsResp import com.tencent.iot.explorer.link.kitlink.entity.ProdConfigDetailEntity import com.tencent.iot.explorer.link.kitlink.entity.ProductGlobal import com.tencent.iot.explorer.link.kitlink.response.ProductsConfigResponse @@ -158,6 +160,19 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI T.show(getString(R.string.add_sucess)) //添加成功 App.data.setRefreshLevel(2) finish() + + var resData = JSON.parseObject(response.data.toString(), BindDevResponse::class.java) + bindSubDev(resData) + } else { + T.show(response.msg) + } + } + + RequestCode.bind_gateway_sub_device -> { + if (response.isSuccess()) { + App.data.refresh = true + App.data.setRefreshLevel(2) + com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@DeviceCategoryActivity) } else { T.show(response.msg) } @@ -165,6 +180,36 @@ class DeviceCategoryActivity : PActivity(), MyCallback, CRecyclerView.RecyclerI } } + private fun bindSubDev(gatwayDev: BindDevResponse) { + if (gatwayDev != null && gatwayDev.Data != null && gatwayDev.Data!!.AppDeviceInfo != null) { + var dev = gatwayDev.Data!!.AppDeviceInfo + if (dev == null) return + + if (dev.DeviceType == "1") { + HttpRequest.instance.gatwaySubDevList(dev.ProductId, dev.DeviceName, object: MyCallback{ + override fun fail(msg: String?, reqCode: Int) { + T.show(msg?:"") + } + + override fun success(response: BaseResponse, reqCode: Int) { + if (response.isSuccess()) { + var gatewaySubDevsResp = JSON.parseObject(response.data.toString(), GatewaySubDevsResp::class.java) + if (gatewaySubDevsResp != null && gatewaySubDevsResp.DeviceList != null && gatewaySubDevsResp.DeviceList.size > 0) { + for (subDev in gatewaySubDevsResp.DeviceList) { + if (subDev.BindStatus == 0) { + HttpRequest.instance.bindGatwaySubDev(dev.ProductId, dev.DeviceName, subDev.ProductId, subDev.DeviceName, this@DeviceCategoryActivity) + } + } + } + } else { + T.show(response.msg) + } + } + }) + } + } + } + override fun doAction( viewHolder: CRecyclerView.CViewHolder<*>, clickView: View, diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/MainActivity.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/MainActivity.kt index c9584b76c..1c75cb200 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/MainActivity.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/activity/MainActivity.kt @@ -44,9 +44,12 @@ import com.tencent.iot.explorer.link.kitlink.popup.FamilyListPopup import com.tencent.iot.explorer.link.kitlink.util.DateUtils import com.tencent.iot.explorer.link.kitlink.util.HttpRequest import com.tencent.iot.explorer.link.core.auth.callback.MyCallback +import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity import com.tencent.iot.explorer.link.core.auth.util.JsonManager import com.tencent.iot.explorer.link.core.link.entity.DeviceInfo import com.tencent.iot.explorer.link.core.link.entity.TrtcDeviceInfo +import com.tencent.iot.explorer.link.kitlink.entity.BindDevResponse +import com.tencent.iot.explorer.link.kitlink.entity.GatewaySubDevsResp import com.tencent.iot.explorer.link.kitlink.entity.ProdConfigDetailEntity import com.tencent.iot.explorer.link.kitlink.entity.ProductGlobal import com.tencent.iot.explorer.link.kitlink.response.ProductsConfigResponse @@ -359,10 +362,53 @@ class MainActivity : PActivity(), MyCallback { App.data.refresh = true App.data.setRefreshLevel(2) com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@MainActivity) + + var resData = JSON.parseObject(response.data.toString(), BindDevResponse::class.java) + bindSubDev(resData) } else { T.show(response.msg) } } + + RequestCode.bind_gateway_sub_device -> { + if (response.isSuccess()) { + App.data.refresh = true + App.data.setRefreshLevel(2) + com.tencent.iot.explorer.link.kitlink.util.Utils.sendRefreshBroadcast(this@MainActivity) + } else { + T.show(response.msg) + } + } + } + } + + private fun bindSubDev(gatwayDev: BindDevResponse) { + if (gatwayDev != null && gatwayDev.Data != null && gatwayDev.Data!!.AppDeviceInfo != null) { + var dev = gatwayDev.Data!!.AppDeviceInfo + if (dev == null) return + + if (dev.DeviceType == "1") { + HttpRequest.instance.gatwaySubDevList(dev.ProductId, dev.DeviceName, object: MyCallback{ + override fun fail(msg: String?, reqCode: Int) { + T.show(msg?:"") + } + + override fun success(response: BaseResponse, reqCode: Int) { + if (response.isSuccess()) { + var gatewaySubDevsResp = JSON.parseObject(response.data.toString(), GatewaySubDevsResp::class.java) + if (gatewaySubDevsResp != null && gatewaySubDevsResp.DeviceList != null && gatewaySubDevsResp.DeviceList.size > 0) { + for (subDev in gatewaySubDevsResp.DeviceList) { + if (subDev.BindStatus == 0) { + HttpRequest.instance.bindGatwaySubDev(dev.ProductId, dev.DeviceName, subDev.ProductId, subDev.DeviceName, this@MainActivity) + } + } + } + } else { + T.show(response.msg) + } + } + }) + } } } diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/BindDevResponse.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/BindDevResponse.kt new file mode 100644 index 000000000..f429accaf --- /dev/null +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/BindDevResponse.kt @@ -0,0 +1,6 @@ +package com.tencent.iot.explorer.link.kitlink.entity + +class BindDevResponse { + var RequestId = "" + var Data: DeviceInfo? = null +} \ No newline at end of file diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/DeviceInfo.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/DeviceInfo.kt new file mode 100644 index 000000000..5606f0ef4 --- /dev/null +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/DeviceInfo.kt @@ -0,0 +1,7 @@ +package com.tencent.iot.explorer.link.kitlink.entity + +import com.tencent.iot.explorer.link.core.auth.entity.DeviceEntity + +class DeviceInfo { + var AppDeviceInfo: DeviceEntity? = null +} \ No newline at end of file diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/GatewaySubDevsResp.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/GatewaySubDevsResp.kt new file mode 100644 index 000000000..d78f35435 --- /dev/null +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/GatewaySubDevsResp.kt @@ -0,0 +1,7 @@ +package com.tencent.iot.explorer.link.kitlink.entity + +class GatewaySubDevsResp { + var RequestId = "" + var Total = 0 + var DeviceList = arrayListOf() +} \ No newline at end of file diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/SubDevice.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/SubDevice.kt new file mode 100644 index 000000000..a4a5bd331 --- /dev/null +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/entity/SubDevice.kt @@ -0,0 +1,11 @@ +package com.tencent.iot.explorer.link.kitlink.entity + +class SubDevice { + var ProductId = "" + var DeviceName = "" + var DeviceId = "" + var AliasName = "" + var IconUrl = "" + var IconUrlGrid = "" + var BindStatus = 0 +} \ No newline at end of file diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/fragment/HomeFragment.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/fragment/HomeFragment.kt index a67c88c6c..2a638f3d2 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/fragment/HomeFragment.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/fragment/HomeFragment.kt @@ -207,7 +207,6 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag presenter.model!!.run { showFamily() showRoomList() - showDeviceList(App.data.deviceList.size, roomId, deviceListEnd, shareDeviceListEnd) loadCurrentWeather() } } @@ -552,11 +551,13 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag // 显示设备列表 override fun showDeviceList(deviceSize: Int, roomId: String, deviceListEnd: Boolean, shareDeviceListEnd: Boolean) { - devList.clear() - shareDevList.clear() - if (deviceSize > 0) { + if (deviceListEnd) { + devList.clear() devList.addAll(presenter.getIModel(this).deviceList) - devList.removeAll(presenter.getIModel(this).shareDeviceList) + } + + if (shareDeviceListEnd) { + shareDevList.clear() shareDevList.addAll(presenter.getIModel(this).shareDeviceList) } @@ -586,13 +587,16 @@ class HomeFragment : BaseFragment(), HomeFragmentView, MyCallback, PayloadMessag override fun showDeviceOnline() { for (i in 0 until devList.size) { + if (i >= presenter.getIModel(this).deviceList.size) { + continue + } devList.get(i).online = presenter.getIModel(this).deviceList.get(i).online } for (i in 0 until shareDevList.size) { - if (i + devList.size >= presenter.getIModel(this).deviceList.size) { + if (i >= presenter.getIModel(this).shareDeviceList.size) { continue } - shareDevList.get(i).online = presenter.getIModel(this).deviceList.get(i + devList.size).online + shareDevList.get(i).online = presenter.getIModel(this).shareDeviceList.get(i).online } roomDevAdapter?.notifyDataSetChanged() roomShareDevAdapter?.notifyDataSetChanged() diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/HttpRequest.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/HttpRequest.kt index 6d37927c8..44e5cb9f1 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/HttpRequest.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/HttpRequest.kt @@ -897,7 +897,7 @@ class HttpRequest private constructor() { param["FamilyId"] = familyId param["RoomId"] = roomId param["Offset"] = offset - param["Limit"] = 20 + param["Limit"] = 999 tokenPost(param, callback, RequestCode.device_list) } @@ -1099,6 +1099,32 @@ class HttpRequest private constructor() { tokenPost(param, callback, RequestCode.check_device_bind_token_state) } + fun gatwaySubDevList(productId: String, davName: String, callback: MyCallback) { + val param = baseParams() + param["RequestId"] = UUID.randomUUID().toString() + param["Action"] = "AppGetGatewayBindDeviceList" + param["AccessToken"] = App.data.getToken() + param["RegionId"] = App.data.regionId + param["Limit"] = 100 + param["Offset"] = 0 + param["GatewayDeviceName"] = davName + param["GatewayProductId"] = productId + tokenPost(param, callback, RequestCode.gateway_sub_device_list) + } + + fun bindGatwaySubDev(productId: String, davName: String, subProductId: String, subDevName: String, callback: MyCallback) { + val param = baseParams() + param["RequestId"] = UUID.randomUUID().toString() + param["Action"] = "AppBindSubDeviceInFamily" + param["AccessToken"] = App.data.getToken() + param["RegionId"] = App.data.regionId + param["GatewayDeviceName"] = davName + param["GatewayProductId"] = productId + param["ProductId"] = subProductId + param["DeviceName"] = subDevName + tokenPost(param, callback, RequestCode.bind_gateway_sub_device) + } + /** * 手机请求加入房间 */ @@ -1227,7 +1253,7 @@ class HttpRequest private constructor() { fun shareDeviceList(offset: Int, callback: MyCallback) { val param = tokenParams("AppListUserShareDevices") param["Offset"] = offset - param["Limit"] = 50 + param["Limit"] = 999 tokenPost(param, callback, RequestCode.share_device_list) } diff --git a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/RequestCode.kt b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/RequestCode.kt index 32c24b8e7..17ef8821e 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/RequestCode.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/kitlink/util/RequestCode.kt @@ -82,6 +82,8 @@ object RequestCode { const val sig_bind_device = 3014 const val trtc_call_device = 3015 const val device_product_info = 3016 + const val gateway_sub_device_list = 3017 + const val bind_gateway_sub_device = 3018 /*************设备接口结束**************/ diff --git a/app/src/main/java/com/tencent/iot/explorer/link/mvp/model/HomeFragmentModel.kt b/app/src/main/java/com/tencent/iot/explorer/link/mvp/model/HomeFragmentModel.kt index bd96d9739..eb85ad335 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/mvp/model/HomeFragmentModel.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/mvp/model/HomeFragmentModel.kt @@ -49,8 +49,6 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( val shortCuts: MutableMap = ConcurrentHashMap() var roomId = "" - var deviceListEnd = false - var shareDeviceListEnd = false private var familyListEnd = false private var roomListEnd = false @@ -83,8 +81,6 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( fun refreshFamilyList() { familyListEnd = false roomListEnd = false - deviceListEnd = false - shareDeviceListEnd = false familyList.clear() loadFamilyList() } @@ -182,8 +178,6 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( fun refreshRoomList() { isTabFamily = true roomListEnd = false - deviceListEnd = false - shareDeviceListEnd = false roomList.clear() loadRoomList() } @@ -200,9 +194,10 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( * 请求获取设备列表 */ fun refreshDeviceList() { - deviceListEnd = false - shareDeviceListEnd = false - deviceList.clear() +// deviceList.clear() +// shareDeviceList.clear() +// view?.showDeviceList(0, roomId, false, true) +// view?.showDeviceList(0, roomId, true, false) loadDeviceList() } @@ -211,24 +206,18 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( */ fun loadDeviceList() { if (TextUtils.isEmpty(App.data.getCurrentFamily().FamilyId)) return - if (deviceListEnd) return - HttpRequest.instance.deviceList( - App.data.getCurrentFamily().FamilyId, - roomId, - deviceList.size, - this - ) + HttpRequest.instance.deviceList(App.data.getCurrentFamily().FamilyId, roomId, 0, this) } /** * 获取设备在线状态 */ - private fun getDeviceOnlineStatus(index: Int, size: Int) { + private fun getDeviceOnlineStatus(deviceList: ArrayList) { var productId = "" var productIds = arrayListOf() val deviceIds = arrayListOf() - for (i in index until size) { - App.data.deviceList[i].let { + for (i in 0 until deviceList.size) { + deviceList[i].let { if (TextUtils.isEmpty(productId)) { productId = it.ProductId } @@ -248,7 +237,7 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( if (response.isSuccess()) { response.parse(DeviceOnlineResponse::class.java)?.run { if (!DeviceStatuses.isNullOrEmpty()) { - for (i in index until size) { + for (i in 0 until deviceList.size) { deviceList[i].run { run check@{ DeviceStatuses!!.forEach { @@ -272,7 +261,7 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( // 获取设备产品配置的快捷入口 private fun excludeBleProduct(productIds: ArrayList) { - HttpRequest.instance.getProductsConfig(productIds, object:MyCallback { + HttpRequest.instance.getProductsConfig(productIds, object: MyCallback { override fun fail(msg: String?, reqCode: Int) { if (msg != null) L.e(msg) } @@ -290,6 +279,12 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( } } + for (dev in shareDeviceList) { + if (dev.ProductId == data.ProductId) { + dev.online = 1 + } + } + } } @@ -304,7 +299,6 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( * 获取共享的设备 */ private fun refreshShareDeviceList() { - shareDeviceList.clear() loadShareDeviceList() } @@ -312,9 +306,8 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( * 获取共享的设备 */ fun loadShareDeviceList() { - if (shareDeviceListEnd) return if (roomId != "") return - HttpRequest.instance.shareDeviceList(shareDeviceList.size, this) + HttpRequest.instance.shareDeviceList(0, this) } override fun fail(msg: String?, reqCode: Int) { @@ -385,26 +378,18 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( RequestCode.device_list -> { if (response.isSuccess()) { response.parse(DeviceListResponse::class.java)?.run { + deviceList.clear() deviceList.addAll(DeviceList) - if (Total >= 0) { - deviceTotal = Total - deviceListEnd = deviceList.size >= Total - } - view?.showDeviceList( - deviceList.size, - roomId, - deviceListEnd, - shareDeviceListEnd - ) - if (deviceListEnd && roomId == "") { - //到底时开始加载共享的设备列表,并且是在全部设备这个房间时 + view?.showDeviceList(deviceList.size, roomId, true, false) + //到底时开始加载共享的设备列表,并且是在全部设备这个房间时 + if (roomId == "") { refreshShareDeviceList() + } else { + shareDeviceList.clear() + view?.showDeviceList(shareDeviceList.size, roomId, false, true) } //在线状态 - getDeviceOnlineStatus( - deviceList.size - DeviceList.size, - deviceList.size - ) + getDeviceOnlineStatus(deviceList) val productIdList = ArrayList() for (device in deviceList) { @@ -425,12 +410,8 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( RequestCode.share_device_list -> { if (response.isSuccess()) { response.parse(ShareDeviceListResponse::class.java)?.run { - if (Total >= 0) { - shareDeviceTotal = Total - shareDeviceListEnd = shareDeviceList.size >= Total - } + shareDeviceList.clear() shareDeviceList.addAll(ShareDevices) - deviceList.addAll(ShareDevices) val deviceIdList = ArrayString() for (device in shareDeviceList) { @@ -445,17 +426,9 @@ class HomeFragmentModel(view: HomeFragmentView) : ParentModel( // TRTC: trtc设备注册websocket监听 IoTAuth.registerActivePush(deviceIdList, null) - view?.showDeviceList( - deviceList.size, - roomId, - deviceListEnd, - shareDeviceListEnd - ) + view?.showDeviceList(shareDeviceList.size, roomId, false, true) //在线状态 - getDeviceOnlineStatus( - deviceList.size - ShareDevices.size, - deviceList.size - ) + getDeviceOnlineStatus(shareDeviceList) } } } diff --git a/app/src/main/java/com/tencent/iot/explorer/link/mvp/presenter/HomeFragmentPresenter.kt b/app/src/main/java/com/tencent/iot/explorer/link/mvp/presenter/HomeFragmentPresenter.kt index b9b07543c..3706d9bf0 100644 --- a/app/src/main/java/com/tencent/iot/explorer/link/mvp/presenter/HomeFragmentPresenter.kt +++ b/app/src/main/java/com/tencent/iot/explorer/link/mvp/presenter/HomeFragmentPresenter.kt @@ -29,11 +29,7 @@ class HomeFragmentPresenter(view: HomeFragmentView) : */ fun loadDeviceList() { model?.run { - if (deviceListEnd){ - loadShareDeviceList() - }else{ - loadDeviceList() - } + loadDeviceList() } }