diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 2a451ec..19687d2 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -276,6 +276,19 @@ ): String /** + * 闸井布防撤防 + * + * @param wellId 井ID + */ + @FormUrlEncoded + @POST("/well/bfcf") + suspend fun obtainOperationResult( + @Header("token") token: String, + @Field("wellId") wellId: String, + @Field("bfzt") bfzt: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 2a451ec..19687d2 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -276,6 +276,19 @@ ): String /** + * 闸井布防撤防 + * + * @param wellId 井ID + */ + @FormUrlEncoded + @POST("/well/bfcf") + suspend fun obtainOperationResult( + @Header("token") token: String, + @Field("wellId") wellId: String, + @Field("bfzt") bfzt: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index 47a00ed..efd6b11 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -265,13 +265,13 @@ return api.obtainDeviceDataByWell(AuthenticationHelper.token!!, id) } -// /** -// * 闸井布防撤防 -// */ -// suspend fun obtainOperationResult(wellId: String, bfzt: String): String { -// return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) -// } -// + /** + * 闸井布防撤防 + */ + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { + return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 2a451ec..19687d2 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -276,6 +276,19 @@ ): String /** + * 闸井布防撤防 + * + * @param wellId 井ID + */ + @FormUrlEncoded + @POST("/well/bfcf") + suspend fun obtainOperationResult( + @Header("token") token: String, + @Field("wellId") wellId: String, + @Field("bfzt") bfzt: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index 47a00ed..efd6b11 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -265,13 +265,13 @@ return api.obtainDeviceDataByWell(AuthenticationHelper.token!!, id) } -// /** -// * 闸井布防撤防 -// */ -// suspend fun obtainOperationResult(wellId: String, bfzt: String): String { -// return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) -// } -// + /** + * 闸井布防撤防 + */ + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { + return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt index a1388ad..1cd5616 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt @@ -18,9 +18,12 @@ import com.casic.app.smartwell.sanxi.extensions.toJson import com.casic.app.smartwell.sanxi.model.OwnerShipModel import com.casic.app.smartwell.sanxi.model.WellListPageModel +import com.casic.app.smartwell.sanxi.utils.DialogHelper +import com.casic.app.smartwell.sanxi.utils.LoadState import com.casic.app.smartwell.sanxi.utils.WeakReferenceHandler import com.casic.app.smartwell.sanxi.vm.AuthenticateViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet import kotlinx.android.synthetic.main.activity_well_manage.* import kotlinx.android.synthetic.main.include_empty_view.* @@ -41,6 +44,7 @@ private var pageIndex = 1 private var isRefresh = false private var isLoadMore = false + private var clickedPosition = 0 override fun initLayoutView(): Int = R.layout.activity_well_manage @@ -141,6 +145,35 @@ }.build().show() } }) + + //撤防布防状态监听 + wellViewModel.commonResultModel.observe(this, { + if (it.code == 200) { + val rowsBean = dataBeans[clickedPosition] + if (rowsBean.bfztName == "布防") { + rowsBean.bfzt = "1" + rowsBean.bfztName = "撤防" + } else { + rowsBean.bfzt = "0" + rowsBean.bfztName = "布防" + } + } + }) + + wellViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "处理中,请稍后") + } + is LoadState.Success -> { + DialogHelper.dismissLoadingDialog() + wellListAdapter.notifyItemChanged(clickedPosition) + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { @@ -222,7 +255,40 @@ } override fun onOperationClicked(position: Int) { + //标记被点击的item位置 + clickedPosition = position + val detailModel = dataBeans[position] + val wellId = detailModel.id.toString() + if (wellId.isBlank()) { + "井ID异常,无法查看详情".show() + return + } + val bfzt = if (detailModel.bfztName == "布防") { + "0" + } else { + "1" + } + val tips = if (detailModel.bfztName == "布防") { + "撤防" + } else { + "布防" + } + AlertControlDialog.Builder() + .setContext(this@WellManageActivity) + .setTitle("操作提示") + .setMessage("确定将该井${tips}吗") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + wellViewModel.obtainOperationResult(wellId, bfzt) + } + override fun onCancelClick() { + + } + }).build().show() } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 2a451ec..19687d2 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -276,6 +276,19 @@ ): String /** + * 闸井布防撤防 + * + * @param wellId 井ID + */ + @FormUrlEncoded + @POST("/well/bfcf") + suspend fun obtainOperationResult( + @Header("token") token: String, + @Field("wellId") wellId: String, + @Field("bfzt") bfzt: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index 47a00ed..efd6b11 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -265,13 +265,13 @@ return api.obtainDeviceDataByWell(AuthenticationHelper.token!!, id) } -// /** -// * 闸井布防撤防 -// */ -// suspend fun obtainOperationResult(wellId: String, bfzt: String): String { -// return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) -// } -// + /** + * 闸井布防撤防 + */ + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { + return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt index a1388ad..1cd5616 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt @@ -18,9 +18,12 @@ import com.casic.app.smartwell.sanxi.extensions.toJson import com.casic.app.smartwell.sanxi.model.OwnerShipModel import com.casic.app.smartwell.sanxi.model.WellListPageModel +import com.casic.app.smartwell.sanxi.utils.DialogHelper +import com.casic.app.smartwell.sanxi.utils.LoadState import com.casic.app.smartwell.sanxi.utils.WeakReferenceHandler import com.casic.app.smartwell.sanxi.vm.AuthenticateViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet import kotlinx.android.synthetic.main.activity_well_manage.* import kotlinx.android.synthetic.main.include_empty_view.* @@ -41,6 +44,7 @@ private var pageIndex = 1 private var isRefresh = false private var isLoadMore = false + private var clickedPosition = 0 override fun initLayoutView(): Int = R.layout.activity_well_manage @@ -141,6 +145,35 @@ }.build().show() } }) + + //撤防布防状态监听 + wellViewModel.commonResultModel.observe(this, { + if (it.code == 200) { + val rowsBean = dataBeans[clickedPosition] + if (rowsBean.bfztName == "布防") { + rowsBean.bfzt = "1" + rowsBean.bfztName = "撤防" + } else { + rowsBean.bfzt = "0" + rowsBean.bfztName = "布防" + } + } + }) + + wellViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "处理中,请稍后") + } + is LoadState.Success -> { + DialogHelper.dismissLoadingDialog() + wellListAdapter.notifyItemChanged(clickedPosition) + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { @@ -222,7 +255,40 @@ } override fun onOperationClicked(position: Int) { + //标记被点击的item位置 + clickedPosition = position + val detailModel = dataBeans[position] + val wellId = detailModel.id.toString() + if (wellId.isBlank()) { + "井ID异常,无法查看详情".show() + return + } + val bfzt = if (detailModel.bfztName == "布防") { + "0" + } else { + "1" + } + val tips = if (detailModel.bfztName == "布防") { + "撤防" + } else { + "布防" + } + AlertControlDialog.Builder() + .setContext(this@WellManageActivity) + .setTitle("操作提示") + .setMessage("确定将该井${tips}吗") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + wellViewModel.obtainOperationResult(wellId, bfzt) + } + override fun onCancelClick() { + + } + }).build().show() } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 515cb14..696dbf0 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -23,6 +23,7 @@ val wellListPageModel = MutableLiveData() val wellTypeModel = MutableLiveData() val deviceDataModel = MutableLiveData() + val commonResultModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -132,4 +133,23 @@ }, { it.printStackTrace() }) + + fun obtainOperationResult(id: String, state: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show() + commonResultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show() + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt index 1fbbad2..211eb99 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/adapter/WellListAdapter.kt @@ -1,17 +1,20 @@ package com.casic.app.smartwell.sanxi.adapter import android.content.Context +import android.content.res.ColorStateList import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.casic.app.smartwell.sanxi.R +import com.casic.app.smartwell.sanxi.extensions.convertColor import com.casic.app.smartwell.sanxi.model.WellListPageModel import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton class WellListAdapter( - context: Context, private val dataRows: MutableList + private val context: Context, + private val dataRows: MutableList ) : RecyclerView.Adapter() { private var layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -29,13 +32,13 @@ override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { //绑定数据 val rowsBean = dataRows[position] - val wellType = rowsBean.wellTypeName.toString() - if (wellType == "其他") { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_gray) + + holder.wellStateView.text = String.format("已${rowsBean.bfztName}") + if (rowsBean.bfztName == "撤防") { + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_orange) } else { - holder.wellTypeView.setBackgroundResource(R.drawable.bg_text_tag_cyan) + holder.wellStateView.setBackgroundResource(R.drawable.bg_text_tag_cyan) } - holder.wellTypeView.text = wellType holder.wellCodeView.text = rowsBean.wellCode val deep = if (rowsBean.deep.isBlank()) { 0 @@ -43,9 +46,23 @@ rowsBean.deep } holder.wellDepthView.text = String.format("${deep}m") + holder.wellTypeView.text = String.format("井类型:${rowsBean.wellTypeName}") holder.ownerShipView.text = String.format("权属单位:${rowsBean.deptName}") holder.wellLocationView.text = String.format("详细地址:${rowsBean.position}") holder.wellDeviceView.text = String.format("井下设备数:${rowsBean.deviceCount}") + if (rowsBean.bfztName == "撤防") { + holder.operationButton.text = "布防" + holder.operationButton.setTextColor(R.color.greenTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.greenTextColor.convertColor(context)) + ) + } else { + holder.operationButton.text = "撤防" + holder.operationButton.setTextColor(R.color.redTextColor.convertColor(context)) + holder.operationButton.setStrokeColors( + ColorStateList.valueOf(R.color.redTextColor.convertColor(context)) + ) + } //绑定事件 if (listener != null) { holder.itemView.setOnClickListener { @@ -64,9 +81,10 @@ } inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { - var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) var wellDepthView: TextView = view.findViewById(R.id.wellDepthView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) var ownerShipView: TextView = view.findViewById(R.id.ownerShipView) var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) var wellDeviceView: TextView = view.findViewById(R.id.wellDeviceView) diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 2a451ec..19687d2 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -276,6 +276,19 @@ ): String /** + * 闸井布防撤防 + * + * @param wellId 井ID + */ + @FormUrlEncoded + @POST("/well/bfcf") + suspend fun obtainOperationResult( + @Header("token") token: String, + @Field("wellId") wellId: String, + @Field("bfzt") bfzt: String + ): String + + /** * 获取工单详情 * * @param id 工单id diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index 47a00ed..efd6b11 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -265,13 +265,13 @@ return api.obtainDeviceDataByWell(AuthenticationHelper.token!!, id) } -// /** -// * 闸井布防撤防 -// */ -// suspend fun obtainOperationResult(wellId: String, bfzt: String): String { -// return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) -// } -// + /** + * 闸井布防撤防 + */ + suspend fun obtainOperationResult(wellId: String, bfzt: String): String { + return api.obtainOperationResult(AuthenticationHelper.token!!, wellId, bfzt) + } + // /** // * 获取工单详情 // */ diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt index a1388ad..1cd5616 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/view/WellManageActivity.kt @@ -18,9 +18,12 @@ import com.casic.app.smartwell.sanxi.extensions.toJson import com.casic.app.smartwell.sanxi.model.OwnerShipModel import com.casic.app.smartwell.sanxi.model.WellListPageModel +import com.casic.app.smartwell.sanxi.utils.DialogHelper +import com.casic.app.smartwell.sanxi.utils.LoadState import com.casic.app.smartwell.sanxi.utils.WeakReferenceHandler import com.casic.app.smartwell.sanxi.vm.AuthenticateViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.pengxh.app.multilib.widget.dialog.AlertControlDialog import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet import kotlinx.android.synthetic.main.activity_well_manage.* import kotlinx.android.synthetic.main.include_empty_view.* @@ -41,6 +44,7 @@ private var pageIndex = 1 private var isRefresh = false private var isLoadMore = false + private var clickedPosition = 0 override fun initLayoutView(): Int = R.layout.activity_well_manage @@ -141,6 +145,35 @@ }.build().show() } }) + + //撤防布防状态监听 + wellViewModel.commonResultModel.observe(this, { + if (it.code == 200) { + val rowsBean = dataBeans[clickedPosition] + if (rowsBean.bfztName == "布防") { + rowsBean.bfzt = "1" + rowsBean.bfztName = "撤防" + } else { + rowsBean.bfzt = "0" + rowsBean.bfztName = "布防" + } + } + }) + + wellViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "处理中,请稍后") + } + is LoadState.Success -> { + DialogHelper.dismissLoadingDialog() + wellListAdapter.notifyItemChanged(clickedPosition) + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) } override fun onDrawerSlide(drawerView: View, slideOffset: Float) { @@ -222,7 +255,40 @@ } override fun onOperationClicked(position: Int) { + //标记被点击的item位置 + clickedPosition = position + val detailModel = dataBeans[position] + val wellId = detailModel.id.toString() + if (wellId.isBlank()) { + "井ID异常,无法查看详情".show() + return + } + val bfzt = if (detailModel.bfztName == "布防") { + "0" + } else { + "1" + } + val tips = if (detailModel.bfztName == "布防") { + "撤防" + } else { + "布防" + } + AlertControlDialog.Builder() + .setContext(this@WellManageActivity) + .setTitle("操作提示") + .setMessage("确定将该井${tips}吗") + .setNegativeButton("取消") + .setPositiveButton("确定") + .setOnDialogButtonClickListener(object : + AlertControlDialog.OnDialogButtonClickListener { + override fun onConfirmClick() { + wellViewModel.obtainOperationResult(wellId, bfzt) + } + override fun onCancelClick() { + + } + }).build().show() } }) } diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 515cb14..696dbf0 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -23,6 +23,7 @@ val wellListPageModel = MutableLiveData() val wellTypeModel = MutableLiveData() val deviceDataModel = MutableLiveData() + val commonResultModel = MutableLiveData() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -132,4 +133,23 @@ }, { it.printStackTrace() }) + + fun obtainOperationResult(id: String, state: String) = launch({ + loadState.value = LoadState.Loading + val response = RetrofitServiceManager.obtainOperationResult(id, state) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + loadState.value = LoadState.Success + "操作成功".show() + commonResultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + loadState.value = LoadState.Fail + response.toErrorMessage().show() + } + }, { + loadState.value = LoadState.Fail + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/layout/item_well_manage_recycleview.xml b/app/src/main/res/layout/item_well_manage_recycleview.xml index bb3521e..303ffa5 100644 --- a/app/src/main/res/layout/item_well_manage_recycleview.xml +++ b/app/src/main/res/layout/item_well_manage_recycleview.xml @@ -16,14 +16,14 @@ android:orientation="horizontal"> @@ -46,10 +46,20 @@ + +