diff --git a/app/src/main/java/com/rehome/zhdcoa/adapter/DeviceOverviewListAdapter.kt b/app/src/main/java/com/rehome/zhdcoa/adapter/DeviceOverviewListAdapter.kt new file mode 100644 index 0000000..e1e239d --- /dev/null +++ b/app/src/main/java/com/rehome/zhdcoa/adapter/DeviceOverviewListAdapter.kt @@ -0,0 +1,122 @@ +package com.rehome.zhdcoa.adapter + + +import android.annotation.SuppressLint +import android.content.Context +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Color +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.Drawable +import android.text.TextUtils +import android.util.Log +import android.view.LayoutInflater +import android.view.ViewGroup +import com.rehome.zhdcoa.Contans +import com.rehome.zhdcoa.Listener.OnItemClickListener +import com.rehome.zhdcoa.R +import com.rehome.zhdcoa.base.BaseViewBindingAdapter +import com.rehome.zhdcoa.bean.DeviceManagerListResultBean +import com.rehome.zhdcoa.databinding.AdapterDeviceOverviewListBinding +import com.rehome.zhdcoa.utils.NohttpUtils +import com.yolanda.nohttp.NoHttp +import com.yolanda.nohttp.rest.CacheMode +import com.yolanda.nohttp.rest.OnResponseListener +import com.yolanda.nohttp.rest.RequestQueue +import com.yolanda.nohttp.rest.Response +import javax.net.ssl.HostnameVerifier + +class DeviceOverviewListAdapter( + var context: Context, + var data: MutableList, + var onItemClickListenerDetail: OnItemClickListener +) : BaseViewBindingAdapter(context) { + override fun getCount(): Int { + return data.count() + } + + override fun getItem(position: Int): Any { + return data[position] + } + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + + override fun getBinding(inflater: LayoutInflater, parent: ViewGroup?) = + AdapterDeviceOverviewListBinding.inflate(inflater, parent, false) + + @SuppressLint("SetTextI18n", "DefaultLocale") + override fun handleData(position: Int, binding: AdapterDeviceOverviewListBinding) { + val itemBean: DeviceManagerListResultBean.DeviceManagerItem = data[position] + if (!TextUtils.isEmpty(itemBean.fileName)) { + val mediaUrl = Contans.IP + Contans.getImgDeviceOnlineBaseUrl+itemBean.fileName + val request = NoHttp.createImageRequest(mediaUrl) + request.cacheMode = CacheMode.NONE_CACHE_REQUEST_NETWORK + + if (!TextUtils.isEmpty(mediaUrl)) { + Log.i("app", "fullPath is:$mediaUrl") + if (!TextUtils.isEmpty(request.url())) { + val url = request.url() + if (url.startsWith("https://219.131.195.3:7100") || url.startsWith("https://219.131.195.3:7011") || url.startsWith( + "https://219.131.195.3:7081" + ) || url.startsWith("https://219.131.195.3:7082") + ) { + val socketFactory = NohttpUtils.getSSLSocketFactory(context) + if (socketFactory != null) { + request.sslSocketFactory = socketFactory + request.hostnameVerifier = HostnameVerifier { s, sslSession -> true } + } + } + } + val queue: RequestQueue = NoHttp.newRequestQueue(1) + queue.add(6, request, object : OnResponseListener { + override fun onStart(what: Int) { + } + + override fun onFailed(what: Int, response: Response?) { + val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.icon_device_place) + val drawable: Drawable = BitmapDrawable(context.resources, bitmap) + binding.ivDevicePhoto.setImageDrawable(drawable) + } + + override fun onSucceed(what: Int, response: Response?) { + val bitmap = response?.get() + if(bitmap!=null){ + val drawable: Drawable = BitmapDrawable(context.resources, bitmap) + binding.ivDevicePhoto.setImageDrawable(drawable) + } + } + + override fun onFinish(what: Int) { + } + }) + } + }else{ + val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.icon_device_place) + val drawable: Drawable = BitmapDrawable(context.resources, bitmap) + binding.ivDevicePhoto.setImageDrawable(drawable) + } + + binding.tvMc.text = itemBean.name + if(!TextUtils.isEmpty(itemBean.areaFullName)){ + binding.tvArea.text = itemBean.areaFullName + } + binding.tvSbzt.text = itemBean.description + if(itemBean.online){ + binding.tvZxzt.text = "在线" + binding.tvZxzt.setTextColor(Color.parseColor("#67C23A"))//0099ff + }else{ + binding.tvZxzt.text = "离线" + binding.tvZxzt.setTextColor(Color.parseColor("#ff0000")) + } + binding.tvZtsysc.text = itemBean.continuedTime + binding.tvAzsj.text = itemBean.installTime + binding.tvYczsc.text = itemBean.runningTime + binding.tvSjgxsj.text = itemBean.warningTime + binding.llCwcz.setOnClickListener { + onItemClickListenerDetail.onItemClick(position, binding.llCwcz) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceManagerListActivity.kt b/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceManagerListActivity.kt index 28e9c81..012fcd5 100644 --- a/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceManagerListActivity.kt +++ b/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceManagerListActivity.kt @@ -135,11 +135,6 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding0){ deviceManagerListFilter.clear() @@ -168,7 +163,7 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding0){ @@ -180,7 +175,7 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding - if (token != null && token == "") { - showToast("设备状态智能监测及分析平台登录失败") - } else { - //登录成功 - //获取区域 - getDeviceAreaListNoProgress() - } - } - } catch (e: Exception) { - e.printStackTrace() - } - } - private fun getDeviceManagerListData() { val request = NoHttp.createStringRequest( @@ -272,19 +240,6 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding { override fun onSucceed(what: Int, response: Response?) { @@ -390,103 +345,6 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding { - - override fun onSucceed(what: Int, response: Response?) { - val result = response?.get() - showLog("----------------") - showLog(result) - - val bean = GsonUtils.GsonToBean( - result, - DeviceManagerListResultBean::class.java - ) - - showLog(GsonUtils.GsonString(bean)) - if (bean != null && bean.code == 20000 && bean.isSuccess && bean.data != null&& bean.data.size>0) { - deviceManagerList.clear() - deviceManagerListFilter.clear() - deviceManagerList.addAll(bean.data) - - if(areaNodeList.size>0){ - for (item in deviceManagerList) { - if(!TextUtils.isEmpty(item.areaId)){ - for (itemAreaNode in areaNodeList) { - if(item.areaId==itemAreaNode.nodeKey){ - item.areaFullName=itemAreaNode.areaFullName - item.areaFullPath=itemAreaNode.areaFullPath - } - } - } - showLog(GsonUtils.GsonString(item)) - } - if(binding.rb1.isChecked){ - for (item in deviceManagerList) { - if(item.online){ - deviceManagerListFilter.add(item) - } - } - } - if(binding.rb2.isChecked){ - for (item in deviceManagerList) { - if(!item.online){ - deviceManagerListFilter.add(item) - } - } - } - if(!TextUtils.isEmpty(binding.etKey.text.toString().trim())){ - if(deviceManagerListFilter.size>0){ - val deviceManagerListFilterKeyFilter: MutableList = mutableListOf() - for (item in deviceManagerListFilter) { - if(!TextUtils.isEmpty(item.name)&&item.name.contains(binding.etKey.text.toString().trim())){ - deviceManagerListFilterKeyFilter.add(item) - } - } - deviceManagerListFilter.clear() - deviceManagerListFilter.addAll(deviceManagerListFilterKeyFilter) - } - } - } - - deviceManagerListAdapter.notifyDataSetChanged() - binding.tvNodata.visibility = View.GONE - binding.lv.visibility=View.VISIBLE - - }else{ - deviceManagerList.clear() - deviceManagerListFilter.clear() - deviceManagerListAdapter.notifyDataSetChanged() - binding.tvNodata.visibility = View.VISIBLE - binding.lv.visibility=View.GONE - } - } - - override fun onFailed(what: Int, response: Response?) { - - } - }) - } - private fun getDeviceAreaList() { //DeviceOnlineStatusAreaBean @@ -537,57 +395,6 @@ class DeviceManagerListActivity : BaseActivityOaToolbarViewBinding { - - override fun onSucceed(what: Int, response: Response?) { - val result = response?.get() - showLog("----------------") - showLog(result) - - - val bean = GsonUtils.GsonToBean( - result, - DeviceOnlineStatusAreaBean::class.java - ) - - showLog(GsonUtils.GsonString(bean)) - if (bean != null && bean.code == 20000 && bean.isSuccess && bean.data != null && bean.data.size>0) { - areaList.clear() - areaNodeList.clear() - areaList.addAll(bean.data) - //更新区域 - for (itemArea in areaList) { - if (itemArea.nodeList != null && itemArea.nodeList.size > 0) { - for (itemNodeList in itemArea.nodeList) { - if (!TextUtils.isEmpty(itemNodeList.cname)) { - itemNodeList.areaFullPath=itemArea.cname+"/"+itemNodeList.cname - itemNodeList.areaFullName=itemArea.cname+">"+itemNodeList.cname - areaNodeList.add(itemNodeList) - } - } - } - } - showLog(GsonUtils.GsonString(areaList)) - SPUtils.put(context, Contans.DeviceOnlineStatusAreaBean,result) - //获取设备管理列表 - getDeviceManagerListDataNoProgress() - } - } - - override fun onFailed(what: Int, response: Response?) { - - } - }) - } - //创建一个ActivityResultLauncher,选择区域 private fun createActivityResultLauncher(): ActivityResultLauncher { //kotlin写法 diff --git a/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceOverviewListActivity.kt b/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceOverviewListActivity.kt index d06932c..ec5e0bc 100644 --- a/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceOverviewListActivity.kt +++ b/app/src/main/java/com/rehome/zhdcoa/ui/activity/DeviceOverviewListActivity.kt @@ -1,25 +1,349 @@ package com.rehome.zhdcoa.ui.activity +import android.content.Intent import android.os.Bundle +import android.text.TextUtils +import android.view.View +import android.widget.RadioGroup import androidx.activity.enableEdgeToEdge +import androidx.activity.result.ActivityResultLauncher +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import com.google.gson.GsonBuilder +import com.rehome.zhdcoa.Contans +import com.rehome.zhdcoa.Listener.OnItemClickListener import com.rehome.zhdcoa.R +import com.rehome.zhdcoa.adapter.DeviceManagerListAdapter +import com.rehome.zhdcoa.adapter.DeviceOverviewListAdapter import com.rehome.zhdcoa.base.BaseActivityOaToolbarViewBinding +import com.rehome.zhdcoa.bean.DeviceManagerListResultBean +import com.rehome.zhdcoa.bean.DeviceOnlineStatusAreaBean import com.rehome.zhdcoa.databinding.ActivityDeviceOverviewListBinding +import com.rehome.zhdcoa.utils.AuthenticationLoginAIUtils +import com.rehome.zhdcoa.utils.GsonUtils +import com.rehome.zhdcoa.utils.HttpListener +import com.rehome.zhdcoa.utils.NohttpUtils +import com.rehome.zhdcoa.utils.RSAAndroid +import com.rehome.zhdcoa.utils.SPUtils +import com.rehome.zhdcoa.weiget.LoadListView import com.rehome.zhdcoa.weiget.OAToolbar +import com.yolanda.nohttp.NoHttp +import com.yolanda.nohttp.RequestMethod +import com.yolanda.nohttp.rest.Response + +class DeviceOverviewListActivity : + BaseActivityOaToolbarViewBinding() { + + private var deviceManagerList: MutableList = + mutableListOf()//设备管理列表 + private var deviceManagerListFilter: MutableList = + mutableListOf()//设备管理列表 + private var areaList: MutableList = + mutableListOf()//在线设备区域列表 + private var areaNodeList: MutableList = + mutableListOf()//在线设备区域列表 + + private lateinit var deviceOverviewListAdapter: DeviceOverviewListAdapter + + private lateinit var launcherResult: ActivityResultLauncher + + private var nodeKey: String? = null + private var cname: String? = null + -class DeviceOverviewListActivity : BaseActivityOaToolbarViewBinding() { override fun getViewBinding() = ActivityDeviceOverviewListBinding.inflate(layoutInflater) override fun getToolbar() = binding.toolbarView.toolbar override fun initView() { + initToolbar("设备总览", "", { + + }) + launcherResult = createActivityResultLauncher() + + binding.etArea.setOnClickListener { + if (areaList.size > 0) { + val intent = Intent(context, DeviceAreaTreeActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) + launcherResult.launch(intent) + } + } + + binding.lv.emptyView = binding.tvNodata + + val gson = GsonBuilder() + .setPrettyPrinting() + .serializeNulls() + .create() + + deviceOverviewListAdapter = + DeviceOverviewListAdapter(context, deviceManagerListFilter, object : OnItemClickListener { + override fun onItemClick(position: Int, v: View?) { + val item: DeviceManagerListResultBean.DeviceManagerItem = + deviceManagerListFilter[position] + showLog(GsonUtils.GsonString(item)) + val intent = Intent(context, DeviceMonitoringDetailActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP) + intent.putExtra("deviceName", item.name) + intent.putExtra("deviceId", item.code) + intent.putExtra("areaFullName", item.areaFullName) + startActivity(intent) + } + }) + binding.lv.adapter = deviceOverviewListAdapter + + binding.tvNodata.visibility = View.VISIBLE + binding.lv.visibility = View.GONE + binding.lv.setInterface(LoadListView.ILoadListener { + binding.lv.loadComplete() + }) + binding.rg.setOnCheckedChangeListener(object : RadioGroup.OnCheckedChangeListener { + override fun onCheckedChanged(group: RadioGroup, checkedId: Int) { + filterChange() + } + }) } override fun initData() { + authenticationLoginDeviceAlarmInfoRsa() + } + + private fun filterChange() { + if (deviceManagerList.size > 0) { + deviceManagerListFilter.clear() + if (binding.rb1.isChecked) { + for (item in deviceManagerList) { + if (item.online != null && item.online) { + deviceManagerListFilter.add(item) + } + } + } + if (binding.rb2.isChecked) { + for (item in deviceManagerList) { + if (item.online != null && !item.online) { + deviceManagerListFilter.add(item) + } + } + } + + if (!TextUtils.isEmpty(binding.etArea.text.toString().trim())) { + if (deviceManagerListFilter.size > 0) { + val deviceManagerListFilterKeyFilter: MutableList = + mutableListOf() + for (item in deviceManagerListFilter) { + if (!TextUtils.isEmpty(item.areaFullName) && item.areaFullName.contains( + binding.etArea.text.toString().trim() + ) + ) { + deviceManagerListFilterKeyFilter.add(item) + } + } + deviceManagerListFilter.clear() + deviceManagerListFilter.addAll(deviceManagerListFilterKeyFilter) + } + } + + showLog("deviceManagerListFilter size:" + deviceManagerListFilter.size.toString()) + showLog("deviceManagerList size:" + deviceManagerList.size.toString()) + deviceOverviewListAdapter.notifyDataSetChanged() + binding.tvNodata.visibility = View.GONE + binding.lv.visibility = View.VISIBLE + } else { + deviceManagerListFilter.clear() + deviceOverviewListAdapter.notifyDataSetChanged() + binding.tvNodata.visibility = View.VISIBLE + binding.lv.visibility = View.GONE + } + } + + private fun authenticationLoginDeviceAlarmInfoRsa() { + try { + //AI三维登录接口 + val userName = Contans.SP.DeviceAlermInfoAccount + val strPrivateEncode = RSAAndroid.encryptByPrivateKeyForSpiltStr( + Contans.SP.DeviceAlermInfoPwd, + RSAAndroid.privateRsaKeyLocal + ) + val strPublicDecode = RSAAndroid.decryptByPublicKeyForSpiltStr( + Contans.SP.DeviceAlermInfoPwd, + RSAAndroid.publicRsaKeyLocal + ) + AuthenticationLoginAIUtils.authenticationDeviceAlermInfoRsaShowProgress( + this, userName, strPublicDecode + ) { _, token -> + if (token != null && token == "") { + showToast("设备状态智能监测及分析平台登录失败") + } else { + //登录成功 + //获取区域 + getDeviceAreaList() + } + } + } catch (e: Exception) { + e.printStackTrace() + } + } + + private fun getDeviceManagerListData() { + + val request = NoHttp.createStringRequest( + Contans.IP + Contans.DeviceManagerListUrl, + RequestMethod.GET + ) + + NohttpUtils.getInstance().add(this, 0, request, object : HttpListener { + + override fun onSucceed(what: Int, response: Response?) { + val result = response?.get() + showLog("----------------") + showLog(result) + + val bean = GsonUtils.GsonToBean( + result, + DeviceManagerListResultBean::class.java + ) + + showLog(GsonUtils.GsonString(bean)) + if (bean != null && bean.code == 20000 && bean.isSuccess && bean.data != null && bean.data.size > 0) { + deviceManagerList.clear() + deviceManagerListFilter.clear() + deviceManagerList.addAll(bean.data) + + if (areaNodeList.size > 0) { + for (item in deviceManagerList) { + if (!TextUtils.isEmpty(item.areaId)) { + for (itemAreaNode in areaNodeList) { + if (item.areaId == itemAreaNode.nodeKey) { + item.areaFullName = itemAreaNode.areaFullName + item.areaFullPath = itemAreaNode.areaFullPath + } + } + } + showLog(GsonUtils.GsonString(item)) + } + if (binding.rb1.isChecked) { + for (item in deviceManagerList) { + if (item.online != null && item.online) { + deviceManagerListFilter.add(item) + } + } + } + if (binding.rb2.isChecked) { + for (item in deviceManagerList) { + if (item.online != null && !item.online) { + deviceManagerListFilter.add(item) + } + } + } + if (!TextUtils.isEmpty(binding.etArea.text.toString().trim())) { + if (deviceManagerListFilter.size > 0) { + val deviceManagerListFilterKeyFilter: MutableList = + mutableListOf() + for (item in deviceManagerListFilter) { + if (!TextUtils.isEmpty(item.areaFullName) && item.areaFullName.contains( + binding.etArea.text.toString().trim() + ) + ) { + deviceManagerListFilterKeyFilter.add(item) + } + } + deviceManagerListFilter.clear() + deviceManagerListFilter.addAll(deviceManagerListFilterKeyFilter) + } + } + } + + deviceOverviewListAdapter.notifyDataSetChanged() + binding.tvNodata.visibility = View.GONE + binding.lv.visibility = View.VISIBLE + } else { + deviceManagerList.clear() + deviceManagerListFilter.clear() + deviceOverviewListAdapter.notifyDataSetChanged() + binding.tvNodata.visibility = View.VISIBLE + binding.lv.visibility = View.GONE + } + } + + override fun onFailed(what: Int, response: Response?) { + + } + }) + } + + + + private fun getDeviceAreaList() { + + //DeviceOnlineStatusAreaBean + val request = NoHttp.createStringRequest( + Contans.IP + Contans.DeviceOnlineStatusAreaBeanUrl, + RequestMethod.GET + ) + NohttpUtils.getInstance().add(this, 0, request, object : HttpListener { + + override fun onSucceed(what: Int, response: Response?) { + val result = response?.get() + showLog("----------------") + showLog(result) + + + val bean = GsonUtils.GsonToBean( + result, + DeviceOnlineStatusAreaBean::class.java + ) + + showLog(GsonUtils.GsonString(bean)) + if (bean != null && bean.code == 20000 && bean.isSuccess && bean.data != null && bean.data.size > 0) { + areaList.clear() + areaNodeList.clear() + areaList.addAll(bean.data) + //更新区域 + for (itemArea in areaList) { + if (itemArea.nodeList != null && itemArea.nodeList.size > 0) { + for (itemNodeList in itemArea.nodeList) { + if (!TextUtils.isEmpty(itemNodeList.cname)) { + itemNodeList.areaFullPath = + itemArea.cname + "/" + itemNodeList.cname + itemNodeList.areaFullName = + itemArea.cname + ">" + itemNodeList.cname + areaNodeList.add(itemNodeList) + } + } + } + } + showLog(GsonUtils.GsonString(areaList)) + SPUtils.put(context, Contans.DeviceOnlineStatusAreaBean, result) + //获取设备管理列表 + getDeviceManagerListData() + } + } + + override fun onFailed(what: Int, response: Response?) { + + } + }) + } + //创建一个ActivityResultLauncher,选择区域 + private fun createActivityResultLauncher(): ActivityResultLauncher { + //kotlin写法 + return registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + val data = it.data + val resultCode = it.resultCode + if (resultCode == RESULT_OK) { + if (data != null) { + nodeKey = data.getStringExtra("nodeKey") + cname = data.getStringExtra("cname") + if (cname != null && nodeKey != null) { + binding.etArea.setText(cname) + filterChange() + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_device_overview_list.xml b/app/src/main/res/layout/activity_device_overview_list.xml index 7714f0f..f4f0a1a 100644 --- a/app/src/main/res/layout/activity_device_overview_list.xml +++ b/app/src/main/res/layout/activity_device_overview_list.xml @@ -24,39 +24,30 @@ android:layout_gravity="center" android:orientation="horizontal"> - + + android:layout_height="76px" + android:layout_marginEnd="2dp" + android:layout_gravity="center_vertical"> + + - - - - - - - - - - - -