diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_management.xml b/app/src/main/res/layout/activity_well_management.xml index 5ab1b29..6f61fc4 100644 --- a/app/src/main/res/layout/activity_well_management.xml +++ b/app/src/main/res/layout/activity_well_management.xml @@ -112,7 +112,7 @@ android:scrollbars="vertical"> diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_management.xml b/app/src/main/res/layout/activity_well_management.xml index 5ab1b29..6f61fc4 100644 --- a/app/src/main/res/layout/activity_well_management.xml +++ b/app/src/main/res/layout/activity_well_management.xml @@ -112,7 +112,7 @@ android:scrollbars="vertical"> diff --git a/app/src/main/res/layout/item_well_recycleview.xml b/app/src/main/res/layout/item_well_recycleview.xml new file mode 100644 index 0000000..20b5126 --- /dev/null +++ b/app/src/main/res/layout/item_well_recycleview.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_management.xml b/app/src/main/res/layout/activity_well_management.xml index 5ab1b29..6f61fc4 100644 --- a/app/src/main/res/layout/activity_well_management.xml +++ b/app/src/main/res/layout/activity_well_management.xml @@ -112,7 +112,7 @@ android:scrollbars="vertical"> diff --git a/app/src/main/res/layout/item_well_recycleview.xml b/app/src/main/res/layout/item_well_recycleview.xml new file mode 100644 index 0000000..20b5126 --- /dev/null +++ b/app/src/main/res/layout/item_well_recycleview.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/ybf.png b/app/src/main/res/mipmap-xxhdpi/ybf.png new file mode 100644 index 0000000..f1754d2 --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ybf.png Binary files differ diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_management.xml b/app/src/main/res/layout/activity_well_management.xml index 5ab1b29..6f61fc4 100644 --- a/app/src/main/res/layout/activity_well_management.xml +++ b/app/src/main/res/layout/activity_well_management.xml @@ -112,7 +112,7 @@ android:scrollbars="vertical"> diff --git a/app/src/main/res/layout/item_well_recycleview.xml b/app/src/main/res/layout/item_well_recycleview.xml new file mode 100644 index 0000000..20b5126 --- /dev/null +++ b/app/src/main/res/layout/item_well_recycleview.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/ybf.png b/app/src/main/res/mipmap-xxhdpi/ybf.png new file mode 100644 index 0000000..f1754d2 --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ybf.png Binary files differ diff --git a/app/src/main/res/mipmap-xxhdpi/ycf.png b/app/src/main/res/mipmap-xxhdpi/ycf.png new file mode 100644 index 0000000..728f8cf --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ycf.png Binary files differ diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt new file mode 100644 index 0000000..6f7029b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/WellListAdapter.kt @@ -0,0 +1,69 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellListModel +import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton + +class WellListAdapter( + context: Context, private val dataRows: MutableList +) : RecyclerView.Adapter() { + + private var layoutInflater: LayoutInflater = LayoutInflater.from(context) + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val view: View = + layoutInflater.inflate(R.layout.item_well_recycleview, parent, false) + return ItemViewHolder(view) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.wellCode + holder.wellTypeView.text = rowsBean.wellTypeName + holder.wellLocationView.text = rowsBean.position + if (rowsBean.bfztName == "布防") { + holder.wellStateView.setImageResource(R.mipmap.ybf) + } else { + holder.wellStateView.setImageResource(R.mipmap.ycf) + } + //绑定事件 + if (listener != null) { + holder.itemView.setOnClickListener { + listener!!.onClicked(position) + } + holder.navigationButton.setOnClickListener { + listener!!.onItemButtonClicked(position) + } + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellTypeView: TextView = view.findViewById(R.id.wellTypeView) + var wellLocationView: TextView = view.findViewById(R.id.wellLocationView) + var navigationButton: QMUIRoundButton = view.findViewById(R.id.navigationButton) + var wellStateView: ImageView = view.findViewById(R.id.wellStateView) + } + + private var listener: OnItemClickListener? = null + + interface OnItemClickListener { + fun onClicked(position: Int) + + fun onItemButtonClicked(position: Int) + } + + fun setOnItemClickListener(onClickListener: OnItemClickListener?) { + this.listener = onClickListener + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt new file mode 100644 index 0000000..efecac5 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellListModel.kt @@ -0,0 +1,86 @@ +package com.casic.app.smartwell.model + +class WellListModel { + /** + * code : 200 + * data : {"rows":[{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}],"total":10} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * rows : [{"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":13,"id":"4453","latBaidu":"38.11992780253818","latGaode":"38.114227973091","lngBaidu":"116.23674002174215","lngGaode":"116.230148925782","notes":"","photos":"2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg;","position":"test001位置","qu":"110107","responsibleDept":"1138317710804635650","responsibleDeptName":"A小组","ts":"","valid":"1","wellCode":"test001","wellFlag1":"","wellFlag2":"","wellFlag3":"","wellName":"测试井1","wellType":"4","wellTypeName":"热力井"}] + * total : 10 + */ + val total = 0 + val rows: MutableList? = null + + class RowsBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : 13 + * id : 4453 + * latBaidu : 38.11992780253818 + * latGaode : 38.114227973091 + * lngBaidu : 116.23674002174215 + * lngGaode : 116.230148925782 + * notes : + * photos : 2020-07/49a84681b3ba4d589750b051e3a884c6.png;2020-07/0b2739cff482488fb0bb479f1b8d8dae.jpeg; + * position : test001位置 + * qu : 110107 + * responsibleDept : 1138317710804635650 + * responsibleDeptName : A小组 + * ts : + * valid : 1 + * wellCode : test001 + * wellFlag1 : + * wellFlag2 : + * wellFlag3 : + * wellName : 测试井1 + * wellType : 4 + * wellTypeName : 热力井 + */ + var area: String? = null + var bfzt: String? = null + var bfztName: String? = null + var coordinateX: String? = null + var coordinateY: String? = null + var deep: Any? = null + var deptName: String? = null + var deptid: String? = null + var deviceCount = 0 + var id: String? = null + var latBaidu: String? = null + var latGaode: String? = null + var lngBaidu: String? = null + var lngGaode: String? = null + var notes: String? = null + var photos: String? = null + var position: String? = null + var qu: String? = null + var responsibleDept: String? = null + var responsibleDeptName: String? = null + var ts: String? = null + var valid: String? = null + var wellCode: String? = null + var wellFlag1: String? = null + var wellFlag2: String? = null + var wellFlag3: String? = null + var wellName: String? = null + var wellType: String? = null + var wellTypeName: String? = null + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt index f8f0c73..b224cd5 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/Constant.kt @@ -11,6 +11,7 @@ ) const val PERMISSIONS_CODE = 999 + const val PAGE_LIMIT = 20 const val ACCOUNT = "account" const val PASSWORD = "password" diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 02ab7b6..5d1d930 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -32,6 +32,20 @@ suspend fun obtainWellType(@Header("token") token: String): WellTypeModel /** + * 获取获取闸井列表 + */ + @GET("/well/list") + suspend fun obtainWellList( + @Header("token") token: String, + @Query("keywords") keywords: String?, + @Query("wellType") wellType: String?, + @Query("deptid") deptid: String?, + @Query("isAlarm") isAlarm: String?, + @Query("limit") limit: Int, + @Query("offset") offset: Int + ): WellListModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index 194ea92..6aba522 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -2,6 +2,7 @@ import com.casic.app.smartwell.model.* import com.casic.app.smartwell.utils.AuthenticationHelper +import com.casic.app.smartwell.utils.Constant object RetrofitServiceManager { @@ -31,6 +32,23 @@ } /** + * 获取获取闸井列表 + */ + suspend fun obtainWellList( + keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int + ): WellListModel { + return api.obtainWellList( + AuthenticationHelper.token!!, + keywords, + wellType, + deptid, + isAlarm, + Constant.PAGE_LIMIT, + page + ) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt index 6b22a8a..f3a1863 100644 --- a/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt +++ b/app/src/main/java/com/casic/app/smartwell/view/WellManagementActivity.kt @@ -1,22 +1,44 @@ package com.casic.app.smartwell.view +import android.annotation.SuppressLint +import android.os.Handler +import android.os.Looper +import android.os.Message +import android.util.Log import android.view.View import android.view.animation.LinearInterpolator import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.WellListAdapter import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.model.WellTypeModel +import com.casic.app.smartwell.vm.WellListViewModel import com.casic.app.smartwell.vm.WellTypeViewModel import com.casic.app.smartwell.widgets.EasyPopupWindow +import com.google.gson.Gson import kotlinx.android.synthetic.main.activity_well_management.* import kotlinx.android.synthetic.main.include_base_title.* +import java.lang.ref.WeakReference class WellManagementActivity : BaseActivity() { private lateinit var wellTypeViewModel: WellTypeViewModel + private lateinit var wellListViewModel: WellListViewModel private lateinit var easyPopupWindow: EasyPopupWindow + private lateinit var weakReferenceHandler: WeakReferenceHandler + private lateinit var wellListAdapter: WellListAdapter private var items: MutableList = ArrayList() + private var wellTypeModel = WellTypeModel.DataBean() + private var dataBeans: MutableList = ArrayList() + private var keywords = "" + private var wellType = "" + private var pageIndex = 1 + private var isRefresh = false + private var isLoadMore = false override fun initLayoutView(): Int = R.layout.activity_well_management @@ -37,9 +59,9 @@ val bean: WellTypeModel.DataBean if (index == 0) { bean = WellTypeModel.DataBean() - bean.id = "0" + bean.id = "" bean.name = "全\u3000部" - bean.value = "0" + bean.value = "" } else { bean = dataBean } @@ -48,6 +70,35 @@ easyPopupWindow.setupPopupData(items) } }) + wellListViewModel = ViewModelProvider(this).get(WellListViewModel::class.java) + weakReferenceHandler = WeakReferenceHandler(this) + obtainWellList(keywords, wellType, pageIndex) + //数据监听 + wellListViewModel.listModel.observe(this, { + if (it.code == 200) { + val dataRows = it.data?.rows + when { + isRefresh -> { + dataBeans.clear() + dataBeans = dataRows!! + refreshLayout.finishRefresh() + isRefresh = false + } + isLoadMore -> { + if (dataRows?.size == 0) { + "到底了,别拉了".show(this) + } + dataBeans.addAll(dataRows!!) + refreshLayout.finishLoadMore() + isLoadMore = false + } + else -> { + dataBeans = dataRows!! + } + } + weakReferenceHandler.sendEmptyMessage(2022032501) + } + }) } override fun initEvent() { @@ -62,9 +113,80 @@ EasyPopupWindow.OnPopupWindowClickListener { override fun onPopupClick(position: Int) { rotateAnimation.rotation(0f) - wellTypeView.text = items[position].name + wellTypeModel = items[position] + wellTypeView.text = wellTypeModel.name } }) } + + searchTextView.setOnClickListener { + keywords = searchInputView.text.toString().trim() + wellType = wellTypeModel.value.toString() + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + + refreshLayout.setOnRefreshListener { + isRefresh = true + //刷新之后页码重置 + pageIndex = 1 + obtainWellList(keywords, wellType, pageIndex) + } + refreshLayout.setOnLoadMoreListener { + isLoadMore = true + pageIndex++ + obtainWellList(keywords, wellType, pageIndex) + } + } + + private fun obtainWellList( + keywords: String?, wellType: String?, pageIndex: Int + ) { + wellListViewModel.obtainWellList( + keywords = keywords, + wellType = wellType, + deptid = "", + isAlarm = "", + page = pageIndex + ) + } + + private class WeakReferenceHandler(activity: WellManagementActivity) : + Handler(Looper.getMainLooper()) { + private val kTag = "WeakReferenceHandler" + private val reference: WeakReference = WeakReference(activity) + + @SuppressLint("NotifyDataSetChanged") + override fun handleMessage(msg: Message) { + super.handleMessage(msg) + val activity = reference.get()!! + if (msg.what == 2022032501) { + if (activity.isRefresh || activity.isLoadMore) { + activity.wellListAdapter.notifyDataSetChanged() + } else { //首次加载数据 + if (activity.dataBeans.size == 0) { + activity.emptyView!!.show("抱歉,无法查询到相关记录", null) + } else { + activity.emptyView!!.hide() + activity.wellListAdapter = WellListAdapter(activity, activity.dataBeans) + activity.wellListView!!.layoutManager = LinearLayoutManager(activity) + activity.wellListView!!.adapter = activity.wellListAdapter + activity.wellListAdapter.setOnItemClickListener(object : + WellListAdapter.OnItemClickListener { + override fun onClicked(position: Int) { + Log.d( + kTag, + "onClicked: ${Gson().toJson(activity.dataBeans[position])}" + ) + } + + override fun onItemButtonClicked(position: Int) { + Log.d(kTag, "onItemButtonClicked: ") + } + }) + } + } + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt new file mode 100644 index 0000000..4157cb9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -0,0 +1,28 @@ +package com.casic.app.smartwell.vm + +import android.util.Log +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellListModel +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellListViewModel : BaseViewModel() { + private val kTag = "WellListViewModel" + + val listModel = MutableLiveData() + + fun obtainWellList( + keywords: String?, + wellType: String?, + deptid: String?, + isAlarm: String?, + page: Int + ) = launch({ + listModel.value = RetrofitServiceManager.obtainWellList( + keywords, wellType, deptid, isAlarm, page + ) + }, { + Log.d(kTag, "obtainWellList: ${it.printStackTrace()}") + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_horizontal.xml b/app/src/main/res/drawable/dash_line_horizontal.xml new file mode 100644 index 0000000..3b9b146 --- /dev/null +++ b/app/src/main/res/drawable/dash_line_horizontal.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/dash_line_vertical.xml b/app/src/main/res/drawable/dash_line_vertical.xml new file mode 100644 index 0000000..1892dff --- /dev/null +++ b/app/src/main/res/drawable/dash_line_vertical.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_management.xml b/app/src/main/res/layout/activity_well_management.xml index 5ab1b29..6f61fc4 100644 --- a/app/src/main/res/layout/activity_well_management.xml +++ b/app/src/main/res/layout/activity_well_management.xml @@ -112,7 +112,7 @@ android:scrollbars="vertical"> diff --git a/app/src/main/res/layout/item_well_recycleview.xml b/app/src/main/res/layout/item_well_recycleview.xml new file mode 100644 index 0000000..20b5126 --- /dev/null +++ b/app/src/main/res/layout/item_well_recycleview.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/ybf.png b/app/src/main/res/mipmap-xxhdpi/ybf.png new file mode 100644 index 0000000..f1754d2 --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ybf.png Binary files differ diff --git a/app/src/main/res/mipmap-xxhdpi/ycf.png b/app/src/main/res/mipmap-xxhdpi/ycf.png new file mode 100644 index 0000000..728f8cf --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/ycf.png Binary files differ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c8cdd4b..0d5bbcb 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -21,8 +21,9 @@ @color/white @dimen/titleFontSize @color/mainThemeColor + @color/mainThemeColor 0dp - 5dp + @dimen/dp_5