<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="editMode"
            type="boolean" />

        <variable
            name="vm"
            type="com.rdiot.yx485.bean.RoomData" />

        <import type="android.view.View" />

    </data>


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/cl_item"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@{vm.power ?@drawable/bg_room_device_on:@drawable/bg_room_device_off}"
        app:layout_constraintDimensionRatio="H,1:1"
        tools:background="@drawable/bg_room_device_on">

        <!--名称-->
        <TextView
            android:id="@+id/tv_room_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="26dp"
            android:layout_marginTop="26dp"
            android:layout_marginEnd="5dp"
            android:ellipsize="end"
            android:maxLines="1"
            android:text="@{vm.name}"
            android:textColor="@{vm.power ? @color/white:@color/main_text_color}"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintEnd_toStartOf="@+id/iv_switch"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="客厅"
            tools:textColor="@color/white" />

        <!--开关-->
        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/iv_switch"
            srcString="@{vm.power?`icon_on`:`icon_off`}"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginEnd="12dp"
            android:visibility="@{vm.editMode?View.GONE:View.VISIBLE}"
            app:layout_constraintBottom_toBottomOf="@id/tv_room_name"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/tv_room_name"
            tools:srcCompat="@mipmap/icon_on" />


        <!--删除-->
        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/iv_del"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginEnd="12dp"
            android:visibility="@{vm.editMode?View.VISIBLE:View.GONE}"
            app:layout_constraintBottom_toBottomOf="@id/tv_room_name"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@id/tv_room_name"
            app:srcCompat="@mipmap/icon_delete"
            tools:visibility="gone" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/gl1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.1" />


        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/gl2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.55" />

        <LinearLayout
            android:id="@+id/ll_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="28dp"
            android:layout_marginBottom="34dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="@+id/gl1"
            app:layout_constraintTop_toBottomOf="@+id/tv_room_name">

            <!--温度-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:orientation="horizontal">

                <androidx.appcompat.widget.AppCompatImageView
                    srcString="@{vm.power?`icon_temperature_on`:`icon_temperature_off`}"
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/tv_room_name"
                    app:srcCompat="@mipmap/icon_temperature_w" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="3dp"
                    android:text="@{@string/temp_title(vm.temperature)}"
                    android:textColor="@{vm.power? @color/white:@color/main_text_color}"
                    android:textSize="16sp"
                    tools:text="25℃"
                    tools:textColor="@color/white" />
            </LinearLayout>


            <!--湿度-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:layout_weight="1"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <androidx.appcompat.widget.AppCompatImageView
                    srcString="@{vm.power?`icon_humidity_on`:`icon_humidity_off`}"
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/tv_room_name"
                    app:srcCompat="@mipmap/icon_humidity_on" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="3dp"
                    android:text="@{@string/humidity_title(vm.humidity)}"
                    android:textColor="@{vm.power? @color/white:@color/main_text_color}"
                    android:textSize="16sp"
                    tools:text="49%"
                    tools:textColor="@color/white" />
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="@+id/ll_1"
            app:layout_constraintStart_toStartOf="@+id/gl2"
            app:layout_constraintTop_toTopOf="@+id/ll_1">

            <!--pm2.5-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <androidx.appcompat.widget.AppCompatImageView
                    srcString="@{vm.power?`icon_pm25_on`:`icon_pm25_off`}"
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/tv_room_name"
                    app:srcCompat="@mipmap/icon_pm25_on" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="3dp"
                    android:text="@{String.format(`%d`,vm.pm25)}"
                    android:textColor="@{vm.power? @color/white:@color/main_text_color}"
                    android:textSize="16sp"
                    tools:text="400"
                    tools:textColor="@color/white" />
            </LinearLayout>

            <!--co2-->
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <androidx.appcompat.widget.AppCompatImageView
                    srcString="@{vm.power?`icon_co2_on`:`icon_co2_off`}"
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/tv_room_name"
                    app:srcCompat="@mipmap/icon_co2_on" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="3dp"
                    android:text="@{String.format(`%d`,vm.co2)}"
                    android:textColor="@{vm.power? @color/white:@color/main_text_color}"
                    android:textSize="16sp"
                    tools:text="423"
                    tools:textColor="@color/white" />
            </LinearLayout>

        </LinearLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>


</layout>