diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: String? = null + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @GET("/user/info") diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/load_image_error.png b/app/src/main/res/mipmap-xxhdpi/load_image_error.png new file mode 100644 index 0000000..357cbde --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/load_image_error.png Binary files differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/load_image_error.png b/app/src/main/res/mipmap-xxhdpi/load_image_error.png new file mode 100644 index 0000000..357cbde --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/load_image_error.png Binary files differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6c93418..386e258 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #333333 #F7F7F7 #CCCCCC + #13AD00 #54FFFFFF #54000000 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/load_image_error.png b/app/src/main/res/mipmap-xxhdpi/load_image_error.png new file mode 100644 index 0000000..357cbde --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/load_image_error.png Binary files differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6c93418..386e258 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #333333 #F7F7F7 #CCCCCC + #13AD00 #54FFFFFF #54000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ec61d7..c64485e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ 智能闸井 中国航天科工集团 + 未知 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/load_image_error.png b/app/src/main/res/mipmap-xxhdpi/load_image_error.png new file mode 100644 index 0000000..357cbde --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/load_image_error.png Binary files differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6c93418..386e258 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #333333 #F7F7F7 #CCCCCC + #13AD00 #54FFFFFF #54000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ec61d7..c64485e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ 智能闸井 中国航天科工集团 + 未知 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0d5bbcb..ea18cd4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -82,4 +82,14 @@ @anim/popup_hide + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d46f832..4711cb5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,10 +38,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/assets/svg/load_error.svg b/app/src/main/assets/svg/load_error.svg new file mode 100644 index 0000000..d3714c7 --- /dev/null +++ b/app/src/main/assets/svg/load_error.svg @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt new file mode 100644 index 0000000..cba0198 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/ImageRecyclerViewAdapter.kt @@ -0,0 +1,64 @@ +package com.casic.app.smartwell.adapter + +import android.content.Context +import android.view.Gravity +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.LinearLayout +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.RequestOptions +import com.casic.app.smartwell.R +import com.pengxh.app.multilib.utils.SizeUtil +import com.qmuiteam.qmui.util.QMUIDisplayHelper + + +/** + * 不可删减九宫格 + * */ +class ImageRecyclerViewAdapter(private val context: Context, imageData: ArrayList) : + RecyclerView.Adapter() { + + private val imageUrls: ArrayList = imageData + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val imageView = ImageView(context) + val layoutWidth: Int = + SizeUtil.getScreenWidth(context) - SizeUtil.dp2px(context, 20f) + val margins: Int = QMUIDisplayHelper.dp2px(context, 3) + val itemSize = (layoutWidth - 6 * margins) / 3 + val params = LinearLayout.LayoutParams(itemSize, itemSize) + params.setMargins(margins, margins, margins, margins) + params.gravity = Gravity.CENTER + imageView.scaleType = ImageView.ScaleType.CENTER_CROP + imageView.layoutParams = params + return ItemViewHolder(imageView) + } + + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + val options = RequestOptions() + .placeholder(R.mipmap.ic_launcher)//图片加载出来前,显示的图片 + .error(R.mipmap.load_image_error)//图片加载失败后,显示的图片 + Glide.with(context).load(imageUrls[position]).apply(options).into(holder.imageView) + holder.imageView.setOnClickListener { // 点击操作,查看大图 + itemClickListener!!.onItemClick(position) + } + } + + override fun getItemCount(): Int = imageUrls.size + + private var itemClickListener: OnItemClickListener? = null + + fun setOnItemClickListener(onItemClickListener: OnItemClickListener?) { + itemClickListener = onItemClickListener + } + + interface OnItemClickListener { + fun onItemClick(position: Int) + } + + inner class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView as ImageView + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt new file mode 100644 index 0000000..a60a2ca --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/adapter/SensorListAdapter.kt @@ -0,0 +1,55 @@ +package com.casic.app.smartwell.adapter + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.casic.app.smartwell.R +import com.casic.app.smartwell.model.WellMonitorModel + +class SensorListAdapter( + 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_sensor_recycleview, parent, false) + return ItemViewHolder(view) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { + //绑定数据 + val rowsBean = dataRows[position] + holder.wellCodeView.text = rowsBean.devcode + holder.wellStateView.text = rowsBean.onlineStateName + val value = rowsBean.data.toString() + if (value == "") { + holder.watchDataView.text = "${rowsBean.watchType}:未知" + } else { + holder.watchDataView.text = "${rowsBean.watchType}:$value" + } + holder.installDateView.text = "安装时间:${rowsBean.installDate}" + val time = rowsBean.logtime.toString() + if (time == "") { + holder.logTimeView.text = "最新数据上报时间:未知" + } else { + holder.logTimeView.text = "最新数据上报时间:$time" + } + } + + override fun getItemCount(): Int = dataRows.size + + inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) { + var wellCodeView: TextView = view.findViewById(R.id.wellCodeView) + var wellStateView: TextView = view.findViewById(R.id.wellStateView) + var watchDataView: TextView = view.findViewById(R.id.watchDataView) + var installDateView: TextView = view.findViewById(R.id.installDateView) + var logTimeView: TextView = view.findViewById(R.id.logTimeView) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt index 0b64d35..de1c6c1 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/Context.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.net.ConnectivityManager import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant /** * 判断是否有网络连接 @@ -24,4 +25,21 @@ fun Context.navigatePageTo(clazz: Class) { startActivity(Intent(this, clazz)) +} + +fun Context.navigatePageTo(clazz: Class, value: String) { + val intent = Intent(this, clazz) + intent.putExtra(Constant.INTENT_PARAM, value) + startActivity(intent) +} + +fun Context.navigatePageTo( + clazz: Class, + index: Int, + imageList: ArrayList? +) { + val intent = Intent(this, clazz) + intent.putExtra("index", index) + intent.putStringArrayListExtra("images", imageList) + startActivity(intent) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt index 6600533..7309344 100644 --- a/app/src/main/java/com/casic/app/smartwell/extensions/String.kt +++ b/app/src/main/java/com/casic/app/smartwell/extensions/String.kt @@ -6,6 +6,8 @@ import android.widget.TextView import android.widget.Toast import com.casic.app.smartwell.R +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.SaveKeyValues import com.qmuiteam.qmui.util.QMUIDisplayHelper /** @@ -43,4 +45,14 @@ } } return isDigit && isLetter +} + +//拼接图片地址 +fun String.combineImagePath(): String { + if (this.isEmpty()) return this + val defaultValue = SaveKeyValues.getValue( + Constant.DEFAULT_SERVER_CONFIG, + "http://111.198.10.15:11304" + ) as String + return "$defaultValue/static/${this.replace("\\", "/")}" } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt new file mode 100644 index 0000000..2369fe9 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellDetailModel.kt @@ -0,0 +1,77 @@ +package com.casic.app.smartwell.model + +class WellDetailModel { + /** + * code : 200 + * data : {"area":"110107006","bfzt":"1","bfztName":"布防","coordinateX":"116.224311","coordinateY":"38.113531","deep":4,"deptName":"燃气集团总公司","deptid":"24","deviceCount":"","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":"热力井"} + * message : 请求成功 + * success : true + */ + var code = 0 + var data: DataBean? = null + var message: String? = null + var isSuccess = false + + class DataBean { + /** + * area : 110107006 + * bfzt : 1 + * bfztName : 布防 + * coordinateX : 116.224311 + * coordinateY : 38.113531 + * deep : 4 + * deptName : 燃气集团总公司 + * deptid : 24 + * deviceCount : + * 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: String? = null + 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/model/WellMonitorModel.kt b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt new file mode 100644 index 0000000..8f3343b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/model/WellMonitorModel.kt @@ -0,0 +1,39 @@ +package com.casic.app.smartwell.model + +class WellMonitorModel { + /** + * code : 200 + * data : [{"data":"无数据","devcode":"412021160186","deviceId":"1503929575557599233","installDate":"2022-03-01","logtime":"","onlineState":"0","onlineStateName":"离线","type":"1","value":"无数据","watchType":"井盖状态"}] + * message : 请求成功 + * success : true + */ + var code = 0 + var message: String? = null + var isSuccess = false + var data: MutableList? = null + + class DataBean { + /** + * data : 无数据 + * devcode : 412021160186 + * deviceId : 1503929575557599233 + * installDate : 2022-03-01 + * logtime : + * onlineState : 0 + * onlineStateName : 离线 + * type : 1 + * value : 无数据 + * watchType : 井盖状态 + */ + var data: String? = null + var devcode: String? = null + var deviceId: String? = null + var installDate: String? = null + var logtime: String? = null + var onlineState: String? = null + var onlineStateName: String? = null + var type: String? = null + var value: String? = null + var watchType: 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 b224cd5..1e5155b 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 @@ -17,6 +17,7 @@ const val PASSWORD = "password" const val DEFAULT_SERVER_CONFIG = "defaultServerConfig" const val USER_DETAIL_MODEL = "userDetailModel" + const val INTENT_PARAM = "intentParam" val HOME_ICONS = arrayOf( R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher 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 5d1d930..174b53c 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 @@ -46,6 +46,24 @@ ): WellListModel /** + * 获取闸井详情 + */ + @GET("/well/info") + suspend fun obtainWellDetail( + @Header("token") token: String, + @Query("id") id: String + ): WellDetailModel + + /** + * 获取井下监控设备列表 + */ + @GET("/well/watchDataByWell") + suspend fun obtainMonitorResult( + @Header("token") token: String, + @Query("id") id: String + ): WellMonitorModel + + /** * 获取用户信息 */ @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 6aba522..deeaa36 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 @@ -49,6 +49,20 @@ } /** + * 获取闸井详情 + */ + suspend fun obtainWellDetail(id: String): WellDetailModel { + return api.obtainWellDetail(AuthenticationHelper.token!!, id) + } + + /** + * 获取井下监控设备列表 + */ + suspend fun obtainMonitorResult(id: String): WellMonitorModel { + return api.obtainMonitorResult(AuthenticationHelper.token!!, id) + } + + /** * 获取用户信息 */ suspend fun obtainUserDetail(): UserDetailModel { diff --git a/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt new file mode 100644 index 0000000..14f8b8d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/BigImageActivity.kt @@ -0,0 +1,95 @@ +package com.casic.app.smartwell.view; + +import android.annotation.SuppressLint +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.viewpager.widget.PagerAdapter +import androidx.viewpager.widget.ViewPager +import com.bumptech.glide.Glide +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.PageNavigationManager +import com.casic.app.smartwell.utils.StatusBarColorUtil +import com.gyf.immersionbar.ImmersionBar +import com.luck.picture.lib.photoview.PhotoView +import kotlinx.android.synthetic.main.activity_big_image.* +import java.util.* + + +class BigImageActivity : BaseActivity() { + + override fun initLayoutView(): Int = R.layout.activity_big_image + + override fun setupTopBarLayout() { + StatusBarColorUtil.setColor(this, ContextCompat.getColor(this, R.color.black)) + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + @SuppressLint("SetTextI18n") + override fun initData() { + val index = intent.getIntExtra("index", 0) + val urls = intent.getStringArrayListExtra("images") + if (urls == null || urls.size == 0) { + return + } + pageNumberView.text = "(" + (index + 1) + "/" + urls.size + ")" + imagePagerView.adapter = BigImageAdapter(this, urls) + imagePagerView.currentItem = index + imagePagerView.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { + override fun onPageScrollStateChanged(state: Int) { + + } + + override fun onPageScrolled( + position: Int, + positionOffset: Float, + positionOffsetPixels: Int + ) { + + } + + override fun onPageSelected(position: Int) { + pageNumberView.text = "(" + (position + 1) + "/" + urls.size + ")" + } + }) + } + + override fun initEvent() { + leftBackView.setOnClickListener { this.finish() } + } + + class BigImageAdapter(private var context: Context, imageList: ArrayList) : + PagerAdapter() { + + private var images: ArrayList = imageList + + override fun getCount(): Int = images.size + + override fun isViewFromObject(view: View, obj: Any): Boolean = view == obj + + override fun instantiateItem(container: ViewGroup, position: Int): Any { + val view = LayoutInflater.from(context).inflate( + R.layout.item_big_picture, + container, + false + ) + val photoView: PhotoView = view.findViewById(R.id.photoView) + Glide.with(context).load(images[position]).into(photoView) + photoView.scaleType = ImageView.ScaleType.CENTER_INSIDE + container.addView(view) + //点击大图取消预览 + photoView.setOnClickListener { + PageNavigationManager.currentActivity()?.finish() + } + return view + } + + override fun destroyItem(container: ViewGroup, position: Int, obj: Any) { + container.removeView(obj as View) + } + } +} diff --git a/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt new file mode 100644 index 0000000..4919677 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/MapNavigatorActivity.kt @@ -0,0 +1,21 @@ +package com.casic.app.smartwell.view + +import com.casic.app.smartwell.R +import com.casic.app.smartwell.base.BaseActivity + +class MapNavigatorActivity : BaseActivity() { + override fun initLayoutView(): Int = R.layout.activity_map_navigation + + override fun setupTopBarLayout() { + + } + + override fun initData() { + + } + + override fun initEvent() { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt new file mode 100644 index 0000000..2bc755b --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellDetailActivity.kt @@ -0,0 +1,122 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.GridLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.ImageRecyclerViewAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.extensions.combineImagePath +import com.casic.app.smartwell.extensions.navigatePageTo +import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellDetailViewModel +import com.pengxh.app.multilib.widget.dialog.AlertMessageDialog +import kotlinx.android.synthetic.main.activity_well_detail.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellDetailActivity : BaseActivity() { + + private lateinit var wellDetailViewModel: WellDetailViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_detail + + override fun setupTopBarLayout() { + titleView.text = "窨井详情" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellDetailViewModel = ViewModelProvider(this).get(WellDetailViewModel::class.java) + wellDetailViewModel.obtainWellDetail(id = wellId) + wellDetailViewModel.detailModel.observe(this, { + if (it.code == 200) { + val wellDetail = it.data!! + wellCodeView.text = wellDetail.wellCode + wellNameView.text = wellDetail.wellName + wellTypeView.text = wellDetail.wellTypeName + wellStateView.text = wellDetail.bfztName + val depth = wellDetail.deep.toString() + if (depth == "") { + wellDepthView.text = resources.getString(R.string.unknown) + } else { + wellDepthView.text = depth + } + //绑定窨井位置 + val wellPosition = wellDetail.position.toString() + wellLocationView.text = wellPosition + if (wellPosition.length > 12) { + tipsImageView.visibility = View.VISIBLE + tipsImageView.setOnClickListener { + AlertMessageDialog.Builder() + .setContext(this) + .setTitle("窨井详细位置") + .setMessage(wellPosition) + .setPositiveButton("知道了").setOnDialogButtonClickListener {}.build() + .show() + } + } else { + tipsImageView.visibility = View.GONE + } + + //绑定窨井图片 + if (wellDetail.photos == "") { + imageRecyclerView.visibility = View.GONE + } else { + imageRecyclerView.visibility = View.VISIBLE + //处理图片地址 + val urls: ArrayList = ArrayList() + val imageArray = wellDetail.photos.toString().split(";") + imageArray.forEach { path -> + if (path != "") { + urls.add(path.combineImagePath()) + } + } + val imageAdapter = ImageRecyclerViewAdapter(this, urls) + imageRecyclerView.layoutManager = GridLayoutManager(this, 3) + imageRecyclerView.adapter = imageAdapter + imageAdapter.setOnItemClickListener(object : + ImageRecyclerViewAdapter.OnItemClickListener { + override fun onItemClick(position: Int) { + if (urls[position].isEmpty()) { + "图片加载失败,无法查看大图".show(this@WellDetailActivity) + } else { + this@WellDetailActivity.navigatePageTo( + BigImageActivity::class.java, + position, + urls + ) + } + } + }) + } + + navigationButton.setOnClickListener { + this.navigatePageTo(MapNavigatorActivity::class.java, wellId) + } + } + }) + + //监控内容 + monitorLayout.setOnClickListener { + this.navigatePageTo(WellMonitorActivity::class.java, wellId) + } + } + + override fun initEvent() { + wellDetailViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file 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 f3a1863..206bfa2 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 @@ -12,13 +12,13 @@ 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.navigatePageTo 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 @@ -174,10 +174,12 @@ activity.wellListAdapter.setOnItemClickListener(object : WellListAdapter.OnItemClickListener { override fun onClicked(position: Int) { - Log.d( - kTag, - "onClicked: ${Gson().toJson(activity.dataBeans[position])}" - ) + val wellId = activity.dataBeans[position].id.toString() + if (wellId == "") { + "井编号异常,无法查看详情".show(activity) + return + } + activity.navigatePageTo(WellDetailActivity::class.java, wellId) } override fun onItemButtonClicked(position: Int) { diff --git a/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt new file mode 100644 index 0000000..34f0f5d --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/view/WellMonitorActivity.kt @@ -0,0 +1,58 @@ +package com.casic.app.smartwell.view + +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.recyclerview.widget.LinearLayoutManager +import com.casic.app.smartwell.R +import com.casic.app.smartwell.adapter.SensorListAdapter +import com.casic.app.smartwell.base.BaseActivity +import com.casic.app.smartwell.utils.Constant +import com.casic.app.smartwell.utils.DialogHelper +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.vm.WellMonitorViewModel +import kotlinx.android.synthetic.main.activity_well_monitor.* +import kotlinx.android.synthetic.main.include_base_title.* + +class WellMonitorActivity : BaseActivity() { + + private lateinit var wellMonitorViewModel: WellMonitorViewModel + + override fun initLayoutView(): Int = R.layout.activity_well_monitor + + override fun setupTopBarLayout() { + titleView.text = "监控内容" + leftBackView.visibility = View.VISIBLE + leftBackView.setOnClickListener { finish() } + } + + override fun initData() { + val wellId = intent.getStringExtra(Constant.INTENT_PARAM)!! + wellMonitorViewModel = ViewModelProvider(this).get(WellMonitorViewModel::class.java) + wellMonitorViewModel.obtainMonitorResult(id = wellId) + wellMonitorViewModel.monitorModel.observe(this, { + if (it.code == 200) { + if (it.data?.size == 0) { + emptyView!!.show("该井下无设备,或设备已离线,请检查", null) + } else { + emptyView!!.hide() + val sensorListAdapter = SensorListAdapter(this, it.data!!) + sensorListView!!.layoutManager = LinearLayoutManager(this) + sensorListView!!.adapter = sensorListAdapter + } + } + }) + } + + override fun initEvent() { + wellMonitorViewModel.loadState.observe(this, { + when (it) { + is LoadState.Loading -> { + DialogHelper.showLoadingDialog(this, "数据加载中,请稍后") + } + else -> { + DialogHelper.dismissLoadingDialog() + } + } + }) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt new file mode 100644 index 0000000..8075940 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellDetailViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellDetailModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellDetailViewModel : BaseViewModel() { + val detailModel = MutableLiveData() + + fun obtainWellDetail(id: String) = launch({ + loadState.value = LoadState.Loading + detailModel.value = RetrofitServiceManager.obtainWellDetail(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt new file mode 100644 index 0000000..518e021 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellMonitorViewModel.kt @@ -0,0 +1,20 @@ +package com.casic.app.smartwell.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.base.BaseViewModel +import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.model.WellMonitorModel +import com.casic.app.smartwell.utils.LoadState +import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager + +class WellMonitorViewModel : BaseViewModel() { + val monitorModel = MutableLiveData() + + fun obtainMonitorResult(id: String) = launch({ + loadState.value = LoadState.Loading + monitorModel.value = RetrofitServiceManager.obtainMonitorResult(id) + loadState.value = LoadState.Success + }, { + loadState.value = LoadState.Fail + }) +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_info.xml b/app/src/main/res/drawable/ic_info.xml new file mode 100644 index 0000000..6562ce3 --- /dev/null +++ b/app/src/main/res/drawable/ic_info.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/layout/activity_big_image.xml b/app/src/main/res/layout/activity_big_image.xml new file mode 100644 index 0000000..1230146 --- /dev/null +++ b/app/src/main/res/layout/activity_big_image.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_map_navigation.xml b/app/src/main/res/layout/activity_map_navigation.xml new file mode 100644 index 0000000..c9edfbd --- /dev/null +++ b/app/src/main/res/layout/activity_map_navigation.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_detail.xml b/app/src/main/res/layout/activity_well_detail.xml new file mode 100644 index 0000000..8dcc7c3 --- /dev/null +++ b/app/src/main/res/layout/activity_well_detail.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_well_monitor.xml b/app/src/main/res/layout/activity_well_monitor.xml new file mode 100644 index 0000000..80187e6 --- /dev/null +++ b/app/src/main/res/layout/activity_well_monitor.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_big_picture.xml b/app/src/main/res/layout/item_big_picture.xml new file mode 100644 index 0000000..d90eb44 --- /dev/null +++ b/app/src/main/res/layout/item_big_picture.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_sensor_recycleview.xml b/app/src/main/res/layout/item_sensor_recycleview.xml new file mode 100644 index 0000000..0eb7acd --- /dev/null +++ b/app/src/main/res/layout/item_sensor_recycleview.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-xxhdpi/load_image_error.png b/app/src/main/res/mipmap-xxhdpi/load_image_error.png new file mode 100644 index 0000000..357cbde --- /dev/null +++ b/app/src/main/res/mipmap-xxhdpi/load_image_error.png Binary files differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6c93418..386e258 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #333333 #F7F7F7 #CCCCCC + #13AD00 #54FFFFFF #54000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3ec61d7..c64485e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ 智能闸井 中国航天科工集团 + 未知 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0d5bbcb..ea18cd4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -82,4 +82,14 @@ @anim/popup_hide + + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..064f301 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file