diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml index c6d5dd7..9aa27ae 100644 --- a/app/src/main/res/layout/activity_device_detail.xml +++ b/app/src/main/res/layout/activity_device_detail.xml @@ -72,12 +72,8 @@ - - @@ -89,7 +85,7 @@ android:text="所属项目" /> @@ -106,68 +102,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/sp_12" + android:visibility="gone" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml index c6d5dd7..9aa27ae 100644 --- a/app/src/main/res/layout/activity_device_detail.xml +++ b/app/src/main/res/layout/activity_device_detail.xml @@ -72,12 +72,8 @@ - - @@ -89,7 +85,7 @@ android:text="所属项目" /> @@ -106,68 +102,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/sp_12" + android:visibility="gone" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/res/layout/activity_group_device.xml b/app/src/main/res/layout/activity_group_device.xml new file mode 100644 index 0000000..57f842d --- /dev/null +++ b/app/src/main/res/layout/activity_group_device.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml index c6d5dd7..9aa27ae 100644 --- a/app/src/main/res/layout/activity_device_detail.xml +++ b/app/src/main/res/layout/activity_device_detail.xml @@ -72,12 +72,8 @@ - - @@ -89,7 +85,7 @@ android:text="所属项目" /> @@ -106,68 +102,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/sp_12" + android:visibility="gone" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/res/layout/activity_group_device.xml b/app/src/main/res/layout/activity_group_device.xml new file mode 100644 index 0000000..57f842d --- /dev/null +++ b/app/src/main/res/layout/activity_group_device.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_overview.xml b/app/src/main/res/layout/fragment_overview.xml index bf7c723..ab9529d 100644 --- a/app/src/main/res/layout/fragment_overview.xml +++ b/app/src/main/res/layout/fragment_overview.xml @@ -37,31 +37,10 @@ - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/dp_10" /> \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml index c6d5dd7..9aa27ae 100644 --- a/app/src/main/res/layout/activity_device_detail.xml +++ b/app/src/main/res/layout/activity_device_detail.xml @@ -72,12 +72,8 @@ - - @@ -89,7 +85,7 @@ android:text="所属项目" /> @@ -106,68 +102,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/sp_12" + android:visibility="gone" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/res/layout/activity_group_device.xml b/app/src/main/res/layout/activity_group_device.xml new file mode 100644 index 0000000..57f842d --- /dev/null +++ b/app/src/main/res/layout/activity_group_device.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_overview.xml b/app/src/main/res/layout/fragment_overview.xml index bf7c723..ab9529d 100644 --- a/app/src/main/res/layout/fragment_overview.xml +++ b/app/src/main/res/layout/fragment_overview.xml @@ -37,31 +37,10 @@ - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/dp_10" /> \ No newline at end of file diff --git a/app/src/main/res/layout/include_data_excel.xml b/app/src/main/res/layout/include_data_excel.xml new file mode 100644 index 0000000..04f2cd4 --- /dev/null +++ b/app/src/main/res/layout/include_data_excel.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 05d1d6e..3d8ef3b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,13 +46,14 @@ + - - - + + + + context: Context, private val dataRows: MutableList ) : RecyclerView.Adapter() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) - private var isExpand = false override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { return ItemViewHolder( @@ -31,17 +31,14 @@ override fun onBindViewHolder(holder: DeviceListAdapter.ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - holder.deviceStateView.text = rowsBean.onlineStateName - if (rowsBean.onlineState == "1") { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_green_radius_5) - } else { - holder.deviceStateView.setBackgroundResource(R.drawable.bg_solid_text_gray_radius_5) - } + holder.batteryView.setBackgroundResource(rowsBean.cell.toBatteryImage()) holder.deviceCodeView.text = rowsBean.devcode - holder.wellCodeView.text = String.format("井编号:${rowsBean.wellCode}") - holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") - holder.deviceLocationView.text = String.format("设备位置:${rowsBean.position}") - holder.installDateView.text = String.format("安装日期:${rowsBean.installDate}") + holder.wellNameView.text = String.format("设备名:${rowsBean.deviceName}") + holder.snrDataView.text = rowsBean.snr + holder.pciDataView.text = rowsBean.pci + holder.rsrpDataView.text = rowsBean.rsrp + holder.strengthDataView.text = rowsBean.strength + holder.installDateView.text = String.format("更新时间:${rowsBean.uptime}") if (listener != null) { @@ -51,39 +48,19 @@ holder.dataHistoryButton.setOnClickListener { listener!!.onHistoryClicked(position) } - holder.wellDetailButton.setOnClickListener { - listener!!.onWellDetailClicked(position) - } - - holder.expandableImageView.setOnClickListener { - if (!isExpand) { - //展开列表动画 - holder.expandableImageView.arrowAnimation(180f) - isExpand = true - //子列表绑定数据 -// expandableViewAdapter.setExpandableData(createExpandableList(rowsBean)) - } else { - //关闭列表动画 - holder.expandableImageView.arrowAnimation(0f) - isExpand = false - //子列表清空数据 -// expandableViewAdapter.clearAll() - } - } } } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var deviceStateView: TextView = view.findViewById(R.id.deviceStateView) + var batteryView: ImageView = view.findViewById(R.id.batteryView) var deviceCodeView: TextView = view.findViewById(R.id.deviceCodeView) - var expandableImageView: ImageView = view.findViewById(R.id.expandableImageView) - var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) - var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) - var deviceLocationView: TextView = view.findViewById(R.id.deviceLocationView) + var wellNameView: TextView = view.findViewById(R.id.wellNameView) + var snrDataView: TextView = view.findViewById(R.id.snrDataView) + var pciDataView: TextView = view.findViewById(R.id.pciDataView) + var rsrpDataView: TextView = view.findViewById(R.id.rsrpDataView) + var strengthDataView: TextView = view.findViewById(R.id.strengthDataView) var installDateView: TextView = view.findViewById(R.id.installDateView) var dataHistoryButton: QMUIRoundButton = view.findViewById(R.id.dataHistoryButton) - var wellDetailButton: QMUIRoundButton = view.findViewById(R.id.wellDetailButton) - var expandableChartView: LineChart = view.findViewById(R.id.expandableChartView) } private var listener: OnItemClickListener? = null @@ -92,8 +69,6 @@ fun onClicked(position: Int) fun onHistoryClicked(position: Int) - - fun onWellDetailClicked(position: Int) } fun setOnItemClickListener(onClickListener: OnItemClickListener?) { diff --git a/app/src/main/java/com/casic/smarttube/extensions/String.kt b/app/src/main/java/com/casic/smarttube/extensions/String.kt index 6b31524..a6b2d58 100644 --- a/app/src/main/java/com/casic/smarttube/extensions/String.kt +++ b/app/src/main/java/com/casic/smarttube/extensions/String.kt @@ -1,5 +1,6 @@ package com.casic.smarttube.extensions +import com.casic.smarttube.R import com.casic.smarttube.model.ErrorMessageModel import com.casic.smarttube.utils.LocaleConstant import com.google.gson.Gson @@ -42,4 +43,23 @@ LocaleConstant.DEFAULT_SERVER_CONFIG, LocaleConstant.SERVER_BASE_URL ) as String return "$defaultValue/static/${this.replace("\\", "/")}" +} + +//电量转图片 +fun String.toBatteryImage(): Int { + if (this.isBlank()) { + return R.drawable.ic_battery_0 + } + try { + when (this.toInt()) { + in 0..10 -> return R.drawable.ic_battery_0 + in 11..30 -> return R.drawable.ic_battery_1 + in 31..60 -> return R.drawable.ic_battery_2 + in 61..90 -> return R.drawable.ic_battery_3 + in 91..100 -> return R.drawable.ic_battery_4 + } + } catch (e: ClassCastException) { + e.printStackTrace() + } + return R.drawable.ic_battery_0 } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt index d80e8ed..2682834 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/OverviewFragment.kt @@ -1,33 +1,22 @@ package com.casic.smarttube.fragment -import android.os.Handler import androidx.lifecycle.ViewModelProvider import androidx.recyclerview.widget.LinearLayoutManager import com.casic.smarttube.R -import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.adapter.GroupListAdapter import com.casic.smarttube.extensions.showEmptyPage -import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.view.AlarmManagementActivity -import com.casic.smarttube.view.DeviceDetailActivity -import com.casic.smarttube.view.HistoryDataActivity -import com.casic.smarttube.view.WellDetailActivity -import com.casic.smarttube.vm.DeviceViewModel +import com.casic.smarttube.view.GroupDeviceActivity +import com.casic.smarttube.vm.ProjectGroupViewModel import com.pengxh.kt.lite.base.KotlinBaseFragment import com.pengxh.kt.lite.extensions.navigatePageTo -import com.pengxh.kt.lite.extensions.show -import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.android.synthetic.main.fragment_overview.* import kotlinx.android.synthetic.main.include_empty_view.* class OverviewFragment : KotlinBaseFragment() { - private lateinit var weakReferenceHandler: WeakReferenceHandler - private lateinit var deviceViewModel: DeviceViewModel - private lateinit var deviceAdapter: DeviceListAdapter - private var dataBeans: MutableList = ArrayList() - private var pageIndex = 1 - private var isRefresh = false - private var isLoadMore = false + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var groupListAdapter: GroupListAdapter override fun initLayoutView(): Int = R.layout.fragment_overview @@ -38,92 +27,35 @@ } override fun initData() { - weakReferenceHandler = WeakReferenceHandler(callback) - deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) } override fun onResume() { - //默认加载第一页 - obtainDeviceList() + groupViewModel.obtainProGroupList() super.onResume() } override fun initEvent() { - overviewLayout.setOnRefreshListener { - isRefresh = true - //刷新之后页码重置 - pageIndex = 1 - obtainDeviceList() - } - overviewLayout.setOnLoadMoreListener { - isLoadMore = true - pageIndex++ - obtainDeviceList() - } - -// deviceViewModel.deviceListModel.observe(this, { -// if (it.code == 200) { -// val dataRows = it.data?.rows -// when { -// isRefresh -> { -// dataBeans.clear() -// dataBeans = dataRows!! -// overviewLayout.finishRefresh() -// isRefresh = false -// } -// isLoadMore -> { -// if (dataRows?.size == 0) { -// "到底了,别拉了".show(requireContext()) -// } -// dataBeans.addAll(dataRows!!) -// overviewLayout.finishLoadMore() -// isLoadMore = false -// } -// else -> { -// dataBeans = dataRows!! -// } -// } -// weakReferenceHandler.sendEmptyMessage(2022062401) -// } -// }) - } - - private fun obtainDeviceList() { - deviceViewModel.obtainDeviceListByType("", "", "", pageIndex) - } - - private val callback = Handler.Callback { - if (it.what == 2022062401) { - if (isRefresh || isLoadMore) { - deviceAdapter.notifyDataSetChanged() - } else { - if (dataBeans.size == 0) { + groupViewModel.groupModel.observe(this, { + if (it.code == 200) { + if (it.data.size == 0) { emptyView!!.showEmptyPage("这里什么都没有") { - pageIndex = 1 - obtainDeviceList() + groupViewModel.obtainProGroupList() } } else { emptyView!!.hide() - deviceAdapter = DeviceListAdapter(requireContext(), dataBeans) - recyclerView!!.layoutManager = LinearLayoutManager(requireContext()) - recyclerView!!.adapter = deviceAdapter - deviceAdapter.setOnItemClickListener(object : - DeviceListAdapter.OnItemClickListener { + groupListAdapter = GroupListAdapter(requireContext(), it.data) + groupRecyclerView!!.layoutManager = LinearLayoutManager(requireContext()) + groupRecyclerView!!.adapter = groupListAdapter + groupListAdapter.setOnItemClickListener(object : + GroupListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onHistoryClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].devcode) - } - - override fun onWellDetailClicked(position: Int) { - requireContext().navigatePageTo(dataBeans[position].wellId) + // 根据groupId查询组下设备 + requireContext().navigatePageTo(it.data[position].groupId) } }) } } - } - true + }) } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java index ddbcfcf..ad0ea56 100644 --- a/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/AlarmListModel.java @@ -79,7 +79,7 @@ private String alarmValue; private String devcode; private String statusName; - private int alarmLevel; + private String alarmLevel; private String tel; private String id; private String wellId; @@ -222,11 +222,11 @@ this.statusName = statusName; } - public int getAlarmLevel() { + public String getAlarmLevel() { return alarmLevel; } - public void setAlarmLevel(int alarmLevel) { + public void setAlarmLevel(String alarmLevel) { this.alarmLevel = alarmLevel; } diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java new file mode 100644 index 0000000..acfe225 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/DeviceDetailModel.java @@ -0,0 +1,171 @@ +package com.casic.smarttube.model; + +public class DeviceDetailModel { + + + private int code; + private DataBean data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataBean getData() { + return data; + } + + public void setData(DataBean data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataBean { + private String wellCode; + private String groupId; + private String rsrp; + private String cell; + private String stregnth; + private String deviceName; + private String uptime; + private String devcode; + private String lngGaode; + private String latGaode; + private String snr; + private String pci; + private String id; + private String onlineState; + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getRsrp() { + return rsrp; + } + + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } + + public String getCell() { + return cell; + } + + public void setCell(String cell) { + this.cell = cell; + } + + public String getStregnth() { + return stregnth; + } + + public void setStregnth(String stregnth) { + this.stregnth = stregnth; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getSnr() { + return snr; + } + + public void setSnr(String snr) { + this.snr = snr; + } + + public String getPci() { + return pci; + } + + public void setPci(String pci) { + this.pci = pci; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getOnlineState() { + return onlineState; + } + + public void setOnlineState(String onlineState) { + this.onlineState = onlineState; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java index b34eb55..2137d0c 100644 --- a/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java +++ b/app/src/main/java/com/casic/smarttube/model/DeviceListModel.java @@ -5,9 +5,9 @@ public class DeviceListModel { private int code; - private DataBean data; + private List data; private String message; - private boolean success; + private String success; public int getCode() { return code; @@ -17,11 +17,11 @@ this.code = code; } - public DataBean getData() { + public List getData() { return data; } - public void setData(DataBean data) { + public void setData(List data) { this.data = data; } @@ -33,242 +33,104 @@ this.message = message; } - public boolean isSuccess() { + public String getSuccess() { return success; } - public void setSuccess(boolean success) { + public void setSuccess(String success) { this.success = success; } public static class DataBean { - private List rows; - private int total; + private String devcode; + private String strength; + private String snr; + private String pci; + private String rsrp; + private String cell; + private String deviceName; + private String uptime; + private String tubeId; + private String deviceCode; - public List getRows() { - return rows; + public String getDevcode() { + return devcode; } - public void setRows(List rows) { - this.rows = rows; + public void setDevcode(String devcode) { + this.devcode = devcode; } - public int getTotal() { - return total; + public String getStrength() { + return strength; } - public void setTotal(int total) { - this.total = total; + public void setStrength(String strength) { + this.strength = strength; } - public static class RowsBean { - private String bfzt; - private String bfztName; - private String communication; - private String concenCode; - private String concenId; - private String deptName; - private String deptid; - private String devcode; - private String deviceName; - private String deviceType; - private String deviceTypeName; - private String id; - private String installDate; - private String modelId; - private String modelName; - private String onlineState; - private String onlineStateName; - private String position; - private String ts; - private String valid; - private String watchType; - private String wellCode; - private String wellId; + public String getSnr() { + return snr; + } - public String getBfzt() { - return bfzt; - } + public void setSnr(String snr) { + this.snr = snr; + } - public void setBfzt(String bfzt) { - this.bfzt = bfzt; - } + public String getPci() { + return pci; + } - public String getBfztName() { - return bfztName; - } + public void setPci(String pci) { + this.pci = pci; + } - public void setBfztName(String bfztName) { - this.bfztName = bfztName; - } + public String getRsrp() { + return rsrp; + } - public String getCommunication() { - return communication; - } + public void setRsrp(String rsrp) { + this.rsrp = rsrp; + } - public void setCommunication(String communication) { - this.communication = communication; - } + public String getCell() { + return cell; + } - public String getConcenCode() { - return concenCode; - } + public void setCell(String cell) { + this.cell = cell; + } - public void setConcenCode(String concenCode) { - this.concenCode = concenCode; - } + public String getDeviceName() { + return deviceName; + } - public String getConcenId() { - return concenId; - } + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } - public void setConcenId(String concenId) { - this.concenId = concenId; - } + public String getUptime() { + return uptime; + } - public String getDeptName() { - return deptName; - } + public void setUptime(String uptime) { + this.uptime = uptime; + } - public void setDeptName(String deptName) { - this.deptName = deptName; - } + public String getTubeId() { + return tubeId; + } - public String getDeptid() { - return deptid; - } + public void setTubeId(String tubeId) { + this.tubeId = tubeId; + } - public void setDeptid(String deptid) { - this.deptid = deptid; - } + public String getDeviceCode() { + return deviceCode; + } - public String getDevcode() { - return devcode; - } - - public void setDevcode(String devcode) { - this.devcode = devcode; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceTypeName() { - return deviceTypeName; - } - - public void setDeviceTypeName(String deviceTypeName) { - this.deviceTypeName = deviceTypeName; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getInstallDate() { - return installDate; - } - - public void setInstallDate(String installDate) { - this.installDate = installDate; - } - - public String getModelId() { - return modelId; - } - - public void setModelId(String modelId) { - this.modelId = modelId; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getOnlineState() { - return onlineState; - } - - public void setOnlineState(String onlineState) { - this.onlineState = onlineState; - } - - public String getOnlineStateName() { - return onlineStateName; - } - - public void setOnlineStateName(String onlineStateName) { - this.onlineStateName = onlineStateName; - } - - public String getPosition() { - return position; - } - - public void setPosition(String position) { - this.position = position; - } - - public String getTs() { - return ts; - } - - public void setTs(String ts) { - this.ts = ts; - } - - public String getValid() { - return valid; - } - - public void setValid(String valid) { - this.valid = valid; - } - - public String getWatchType() { - return watchType; - } - - public void setWatchType(String watchType) { - this.watchType = watchType; - } - - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - - public String getWellId() { - return wellId; - } - - public void setWellId(String wellId) { - this.wellId = wellId; - } + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode; } } } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..2affba5 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -41,8 +41,8 @@ * ============================================================================================= * */ const val USER_DETAIL_MODEL = "userDetailModel" -// const val SERVER_BASE_URL = "http://192.168.43.19:11643" - const val SERVER_BASE_URL = "http://111.198.10.15:11304" + const val SERVER_BASE_URL = "http://192.168.43.19:11643" +// const val SERVER_BASE_URL = "http://111.198.10.15:11304" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index a60b113..bd223b1 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -67,7 +67,7 @@ /** * 更新APK版本 */ - @GET("/app/checkVersion") + @POST("/app/checkVersion") suspend fun obtainVersionResult(@Header("token") token: String): String /** @@ -79,35 +79,42 @@ /** * 项目列表 */ - @GET("/tube/group/list") + @GET("/tube/groups/list") suspend fun obtainProGroupList(@Header("token") token: String): String /** * 根据项目ID查询该项目下的设备列表 */ - @GET("/tube/group/Info") + @GET("/tube/groupdevice/list") suspend fun obtainDeviceListByGroup( @Header("token") token: String, @Query("wellGroupId") wellGroupId: String ): String /** - * 获取管盯分页列表 + * 获取设备分页列表 * */ - @GET("/device/list") - suspend fun obtainDeviceListByType( + @GET("/tube/groupdevice/listpage") + suspend fun obtainDeviceListByPage( @Header("token") token: String, - @Query("deptid") deptid: String?, - @Query("keywords") keywords: String?, - @Query("deviceType") deviceType: String?, - @Query("isOnline") isOnline: String?, - @Query("sort") sort: String?, - @Query("order") order: String?, + @Query("wellGroupId") wellGroupId: String?, + @Query("order") order: Int, @Query("offset") offset: Int, @Query("limit") limit: Int ): String /** + * 获取设备详情 + * + * @param tubeId 管盯ID + */ + @GET("/tube/detail/{tubeId}") + suspend fun obtainDeviceDetail( + @Header("token") token: String, + @Path("tubeId") tubeId: String + ): String + + /** * 获取闸井详情 * * @param id 窨井ID diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index ab52385..8bc44d8 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -83,18 +83,22 @@ } /** - * 根据设备类型获取设备分页列表 + * 获取设备分页列表 */ - suspend fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ): String { - return api.obtainDeviceListByType( - AuthenticationHelper.token!!, deptid, keywords, "12", isOnline, - "id", "asc", page, LocaleConstant.PAGE_LIMIT + suspend fun obtainDeviceListByPage(groupId: String, order: Int, page: Int): String { + return api.obtainDeviceListByPage( + AuthenticationHelper.token!!, groupId, order, page, LocaleConstant.PAGE_LIMIT ) } /** + * 获取设备详情 + */ + suspend fun obtainDeviceDetail(tubeId: String): String { + return api.obtainDeviceDetail(AuthenticationHelper.token!!, tubeId) + } + + /** * 获取闸井详情 */ suspend fun obtainWellDetail(id: String): String { diff --git a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt index c7efb37..a15b96c 100644 --- a/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt +++ b/app/src/main/java/com/casic/smarttube/view/DeviceDetailActivity.kt @@ -1,21 +1,29 @@ package com.casic.smarttube.view import androidx.lifecycle.ViewModelProvider +import com.amap.api.services.core.LatLonPoint +import com.amap.api.services.geocoder.GeocodeResult +import com.amap.api.services.geocoder.GeocodeSearch +import com.amap.api.services.geocoder.RegeocodeQuery +import com.amap.api.services.geocoder.RegeocodeResult import com.casic.smarttube.R +import com.casic.smarttube.utils.DialogHelper import com.casic.smarttube.vm.DeviceViewModel import com.gyf.immersionbar.ImmersionBar import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.utils.Constant import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_device_detail.* import kotlinx.android.synthetic.main.include_base_title.* class DeviceDetailActivity : KotlinBaseActivity() { private lateinit var deviceViewModel: DeviceViewModel - private lateinit var devCode: String + private val geocoderSearch by lazy { GeocodeSearch(this) } - override fun initLayoutView(): Int =R.layout.activity_device_detail + override fun initLayoutView(): Int = R.layout.activity_device_detail override fun setupTopBarLayout() { ImmersionBar.with(this).statusBarDarkFont(false).init() @@ -25,8 +33,57 @@ } override fun initData() { - devCode = intent.getStringExtra(Constant.INTENT_PARAM)!! + val tubeId = intent.getStringExtra(Constant.INTENT_PARAM)!! deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + + deviceViewModel.obtainDeviceDetail(tubeId) + deviceViewModel.deviceDetailModel.observe(this, { + if (it.code == 200) { + val device = it.data + deviceCodeView.text = device.devcode + deviceNameView.text = device.deviceName + projectGroupView.text = String.format("项目${device.groupId}") + if (device.latGaode.isBlank() || device.lngGaode.isBlank()) { + locationView.text = "经纬度异常,无法查看具体位置" + } else { + val queryParam = RegeocodeQuery( + LatLonPoint(device.latGaode.toDouble(), device.lngGaode.toDouble()), + 200f, + GeocodeSearch.AMAP + ) + geocoderSearch.getFromLocationAsyn(queryParam) + geocoderSearch.setOnGeocodeSearchListener(object : + GeocodeSearch.OnGeocodeSearchListener { + override fun onRegeocodeSearched(result: RegeocodeResult?, rCode: Int) { + if (rCode == 1000) { + locationView.text = result?.regeocodeAddress?.formatAddress + } + } + + override fun onGeocodeSearched(result: GeocodeResult?, rCode: Int) { + + } + }) + } + + densityView.text = device.stregnth + lastDataView.text = device.uptime + deviceStateView.text = if (device.onlineState == "0") { + "离线" + } else { + "在线" + } + deviceRsrpView.text = device.rsrp + deviceBatteryView.text = device.cell + } + }) + + deviceViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) } override fun initEvent() { diff --git a/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt new file mode 100644 index 0000000..83458ab --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/view/GroupDeviceActivity.kt @@ -0,0 +1,145 @@ +package com.casic.smarttube.view + +import android.os.Handler +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.smarttube.R +import com.casic.smarttube.adapter.DeviceListAdapter +import com.casic.smarttube.extensions.showEmptyPage +import com.casic.smarttube.model.DeviceListModel +import com.casic.smarttube.utils.DialogHelper +import com.casic.smarttube.vm.ProjectGroupViewModel +import com.gyf.immersionbar.ImmersionBar +import com.pengxh.kt.lite.base.KotlinBaseActivity +import com.pengxh.kt.lite.extensions.convertColor +import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show +import com.pengxh.kt.lite.utils.Constant +import com.pengxh.kt.lite.utils.ImmerseStatusBarUtil +import com.pengxh.kt.lite.utils.WeakReferenceHandler +import com.pengxh.kt.lite.vm.LoadState +import kotlinx.android.synthetic.main.activity_alarm_management.leftBackView +import kotlinx.android.synthetic.main.activity_alarm_management.titleView +import kotlinx.android.synthetic.main.activity_group_device.* +import kotlinx.android.synthetic.main.include_empty_view.* + +class GroupDeviceActivity : KotlinBaseActivity() { + + private lateinit var groupId: String + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var groupViewModel: ProjectGroupViewModel + private lateinit var deviceAdapter: DeviceListAdapter + private var dataBeans: MutableList = ArrayList() + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false + private var order = 0 + + override fun initLayoutView(): Int = R.layout.activity_group_device + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + ImmerseStatusBarUtil.setColor(this, R.color.mainThemeColor.convertColor(this)) + leftBackView.setOnClickListener { finish() } + titleView.text = "设备列表" + rightOptionView.setOnClickListener { + order = if (order == 0) { + 1 + } else { + 0 + } + pageIndex = 1 + obtainDeviceListByPage() + } + } + + override fun initData() { + groupId = intent.getStringExtra(Constant.INTENT_PARAM)!! + + weakReferenceHandler = WeakReferenceHandler(callback) + groupViewModel = ViewModelProvider(this).get(ProjectGroupViewModel::class.java) + obtainDeviceListByPage() + } + + override fun initEvent() { + groupDeviceLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainDeviceListByPage() + } + groupDeviceLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainDeviceListByPage() + } + + groupViewModel.deviceListModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + groupDeviceLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + groupDeviceLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022070601) + } + }) + + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(this, "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) + } + + private fun obtainDeviceListByPage() { + groupViewModel.obtainDeviceListByPage(groupId, order, pageIndex) + } + + private val callback = Handler.Callback { + if (it.what == 2022070601) { + if (isRefresh || isLoadMore) { + deviceAdapter.notifyDataSetChanged() + } else { + if (dataBeans.size == 0) { + emptyView!!.showEmptyPage("这里什么都没有") { + pageIndex = 1 + obtainDeviceListByPage() + } + } else { + emptyView!!.hide() + deviceAdapter = DeviceListAdapter(this, dataBeans) + groupDeviceView!!.layoutManager = LinearLayoutManager(this) + groupDeviceView!!.adapter = deviceAdapter + deviceAdapter.setOnItemClickListener(object : + DeviceListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + navigatePageTo(dataBeans[position].tubeId) + } + + override fun onHistoryClicked(position: Int) { + navigatePageTo(dataBeans[position].devcode) + } + }) + } + } + } + true + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 5b2f97f..1541eb4 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.MapDeviceModel @@ -13,11 +14,13 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class DeviceViewModel : BaseViewModel() { private val gson = Gson() val mapDeviceModel = MutableLiveData() + val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ @@ -34,17 +37,17 @@ it.printStackTrace() }) - fun obtainDeviceListByType( - deptid: String, keywords: String, isOnline: String, page: Int - ) = launch({ - val response = - RetrofitServiceManager.obtainDeviceListByType(deptid, keywords, isOnline, page) + fun obtainDeviceDetail(tubeId: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceDetail(tubeId) val responseCode = response.separateResponseCode() if (responseCode == 200) { -// deviceListModel.value = gson.fromJson( -// response, object : TypeToken() {}.type -// ) + loadState.value = LoadState.Success + deviceDetailModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index 770a7cd..a0c6996 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -4,6 +4,7 @@ import com.casic.smarttube.base.BaseApplication import com.casic.smarttube.extensions.separateResponseCode import com.casic.smarttube.extensions.toErrorMessage +import com.casic.smarttube.model.DeviceListModel import com.casic.smarttube.model.GroupDeviceModel import com.casic.smarttube.model.ProjectGroupModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager @@ -12,12 +13,14 @@ import com.pengxh.kt.lite.extensions.launch import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.vm.BaseViewModel +import com.pengxh.kt.lite.vm.LoadState class ProjectGroupViewModel : BaseViewModel() { private val gson = Gson() val groupModel = MutableLiveData() val groupDeviceModel = MutableLiveData() + val deviceListModel = MutableLiveData() fun obtainProGroupList() = launch({ val response = RetrofitServiceManager.obtainProGroupList() @@ -46,4 +49,21 @@ }, { it.printStackTrace() }) + + fun obtainDeviceListByPage(groupId: String, order: Int, page: Int) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainDeviceListByPage(groupId, order, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + deviceListModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/drawable/bg_stroke_layout_gray.xml b/app/src/main/res/drawable/bg_stroke_layout_gray.xml new file mode 100644 index 0000000..3a982cf --- /dev/null +++ b/app/src/main/res/drawable/bg_stroke_layout_gray.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_battery_0.xml b/app/src/main/res/drawable/ic_battery_0.xml new file mode 100644 index 0000000..38425b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_0.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_1.xml b/app/src/main/res/drawable/ic_battery_1.xml new file mode 100644 index 0000000..93a6ce2 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_1.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_2.xml b/app/src/main/res/drawable/ic_battery_2.xml new file mode 100644 index 0000000..a09a07f --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_2.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_battery_3.xml b/app/src/main/res/drawable/ic_battery_3.xml new file mode 100644 index 0000000..21e3d58 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_3.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_battery_4.xml b/app/src/main/res/drawable/ic_battery_4.xml new file mode 100644 index 0000000..21fa5b9 --- /dev/null +++ b/app/src/main/res/drawable/ic_battery_4.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_order.xml b/app/src/main/res/drawable/ic_order.xml new file mode 100644 index 0000000..c9c2488 --- /dev/null +++ b/app/src/main/res/drawable/ic_order.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_device_detail.xml b/app/src/main/res/layout/activity_device_detail.xml index c6d5dd7..9aa27ae 100644 --- a/app/src/main/res/layout/activity_device_detail.xml +++ b/app/src/main/res/layout/activity_device_detail.xml @@ -72,12 +72,8 @@ - - @@ -89,7 +85,7 @@ android:text="所属项目" /> @@ -106,68 +102,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/sp_12" + android:visibility="gone" /> + + + + + + + + + - - - - - - - - - diff --git a/app/src/main/res/layout/activity_group_device.xml b/app/src/main/res/layout/activity_group_device.xml new file mode 100644 index 0000000..57f842d --- /dev/null +++ b/app/src/main/res/layout/activity_group_device.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_overview.xml b/app/src/main/res/layout/fragment_overview.xml index bf7c723..ab9529d 100644 --- a/app/src/main/res/layout/fragment_overview.xml +++ b/app/src/main/res/layout/fragment_overview.xml @@ -37,31 +37,10 @@ - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_marginTop="@dimen/dp_10" /> \ No newline at end of file diff --git a/app/src/main/res/layout/include_data_excel.xml b/app/src/main/res/layout/include_data_excel.xml new file mode 100644 index 0000000..04f2cd4 --- /dev/null +++ b/app/src/main/res/layout/include_data_excel.xml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_device_rv.xml b/app/src/main/res/layout/item_device_rv.xml index 9a2eff8..c63b3bd 100644 --- a/app/src/main/res/layout/item_device_rv.xml +++ b/app/src/main/res/layout/item_device_rv.xml @@ -16,62 +16,35 @@ + android:layout_height="wrap_content" + android:gravity="center_vertical"> - + android:layout_height="wrap_content" /> - - - - - + - - - - \ No newline at end of file