desc:传感器设置
parent
ac25a7dd6f
commit
d0f3aa8e59
@ -0,0 +1,48 @@
|
||||
package com.yinuo.safetywatcher.watcher.adapter
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.yinuo.safetywatcher.R
|
||||
import com.yinuo.safetywatcher.databinding.LayoutItemSensorBinding
|
||||
import com.yinuo.safetywatcher.watcher.base.BaseRvAdapter
|
||||
import com.yinuo.safetywatcher.watcher.bean.SensorData
|
||||
import com.yinuo.safetywatcher.watcher.ui.SensorSettingActivity
|
||||
|
||||
class SensorAdapter :
|
||||
BaseRvAdapter<SensorData, LayoutItemSensorBinding, SensorAdapter.SensorViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SensorViewHolder {
|
||||
return SensorViewHolder(
|
||||
LayoutItemSensorBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
class SensorViewHolder(private val binding: LayoutItemSensorBinding) :
|
||||
BaseViewHolder<SensorData, LayoutItemSensorBinding>(binding) {
|
||||
|
||||
override fun bindView(data: SensorData) {
|
||||
val context = binding.root.context
|
||||
binding.sensorSetting.setOnClickListener {
|
||||
context.startActivity(Intent(context, SensorSettingActivity::class.java))
|
||||
}
|
||||
|
||||
binding.sensorName.text = data.name
|
||||
val state = data.state
|
||||
binding.sensorStatus.text = context.getText(getShowStatus(state))
|
||||
binding.sensorStatus.setTextColor(context.getColor(getShowStatusColor(state)))
|
||||
}
|
||||
|
||||
private fun getShowStatusColor(state: Int): Int {
|
||||
return if (state == 0) R.color.color_ok else R.color.color_error
|
||||
}
|
||||
|
||||
private fun getShowStatus(state: Int): Int {
|
||||
return if (state == 0) R.string.status_ok else R.string.status_error
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.yinuo.safetywatcher.watcher.base
|
||||
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
abstract class BaseRvAdapter<T, B : ViewBinding, VH : BaseRvAdapter.BaseViewHolder<T, B>> :
|
||||
RecyclerView.Adapter<VH>() {
|
||||
|
||||
private val mDatas = mutableListOf<T>()
|
||||
|
||||
fun setData(values: List<T>) {
|
||||
mDatas.addAll(values)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return mDatas.size
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int) {
|
||||
holder.bindView(mDatas[position])
|
||||
}
|
||||
|
||||
|
||||
abstract class BaseViewHolder<T, B : ViewBinding>(binding: B) : ViewHolder(binding.root) {
|
||||
abstract fun bindView(data: T)
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.yinuo.safetywatcher.watcher.bean
|
||||
|
||||
data class SensorData(val name: String, val state: Int = 0)
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/_2A4284" />
|
||||
<corners android:radius="@dimen/_20dp" />
|
||||
</shape>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/_842A2A" />
|
||||
<corners android:radius="@dimen/_20dp" />
|
||||
</shape>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/_242f4d" />
|
||||
<corners android:radius="@dimen/_20dp" />
|
||||
</shape>
|
@ -1,7 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/_121dp"
|
||||
android:paddingTop="@dimen/_61dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_name"
|
||||
android:layout_width="@dimen/_600dp"
|
||||
android:layout_height="@dimen/_100dp"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:textColor="@color/white"
|
||||
android:textColorHint="@color/white"
|
||||
android:hint="@string/sensor_name_txt"
|
||||
android:paddingStart="@dimen/_30dp"
|
||||
android:background="@drawable/cloud_sync_btn_bg"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_step"
|
||||
android:layout_width="@dimen/_600dp"
|
||||
android:layout_height="@dimen/_100dp"
|
||||
android:layout_marginTop="@dimen/_40dp"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:textColor="@color/white"
|
||||
android:textColorHint="@color/white"
|
||||
android:hint="@string/sensor_step_txt"
|
||||
android:paddingStart="@dimen/_30dp"
|
||||
android:background="@drawable/cloud_sync_btn_bg"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="@dimen/_600dp"
|
||||
android:layout_height="@dimen/_100dp"
|
||||
android:layout_marginTop="@dimen/_40dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/cloud_sync_btn_bg">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:textColor="@color/white"
|
||||
android:textColorHint="@color/white"
|
||||
android:paddingStart="@dimen/_30dp"
|
||||
android:hint="@string/sensor_type_txt"
|
||||
android:background="#00000000"/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/_31dp"
|
||||
android:layout_height="@dimen/_17dp"
|
||||
android:src="@mipmap/ic_arrow_down"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="@dimen/_30dp"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_warn_setting"
|
||||
android:layout_width="@dimen/_380dp"
|
||||
android:layout_height="@dimen/_80dp"
|
||||
android:layout_marginTop="@dimen/_40dp"
|
||||
android:textColor="@color/white"
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:text="@string/sensor_warn_setting_txt"
|
||||
android:background="@drawable/warn_setting_btn_bg"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/_40dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_save"
|
||||
android:layout_width="@dimen/_160dp"
|
||||
android:layout_height="@dimen/_80dp"
|
||||
android:textColor="@color/white"
|
||||
android:gravity="center"
|
||||
android:text="@string/save"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:background="@drawable/save_btn_bg"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sensor_init"
|
||||
android:layout_width="@dimen/_260dp"
|
||||
android:layout_height="@dimen/_80dp"
|
||||
android:layout_marginStart="@dimen/_38dp"
|
||||
android:textColor="@color/white"
|
||||
android:gravity="center"
|
||||
android:textSize="@dimen/_30dp"
|
||||
android:text="@string/sensor_init_txt"
|
||||
android:background="@drawable/sensor_init_btn_bg"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/_108dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sensor_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/_172dp"
|
||||
android:text="传感器"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sensor_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/_372dp"
|
||||
android:text="正常"
|
||||
android:textColor="@color/color_ok"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="1px"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sensor_setting"
|
||||
android:layout_width="@dimen/_132dp"
|
||||
android:layout_height="@dimen/_55dp"
|
||||
android:layout_marginEnd="@dimen/_172dp"
|
||||
android:background="@mipmap/op_bg"
|
||||
android:gravity="center"
|
||||
android:text="@string/setting"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="@dimen/_30dp" />
|
||||
</LinearLayout>
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue