<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright 2019, The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!-- Wrapping the layout into /layout to make it available with data binding. -->
<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 to make available to the XML via data binding. In this case,
         the whole ViewModel, so that we can access the LiveData,
         click handlers, and state variables. -->
    <data>

        <variable
            name="sleepTrackerViewModel"
            type="com.example.android.trackmysleepquality.sleeptracker.SleepTrackerViewModel" />
    </data>

    <!-- Start of the visible fragment layout using ConstraintLayout -->
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".sleeptracker.SleepTrackerFragment">

        <!-- This lesson we will switch to RecyclerView to properly
         display the sleep data-->

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/sleep_list"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/clear_button"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/stop_button"/>

        <!-- With data binding and LiveData, we can track the buttons' visibility states
             from the ViewModel. The click handler is in the ViewModel as well, and
             you can set it for the Views using this lambda pattern. -->

        <Button
            android:id="@+id/start_button"
            style="@style/SleepButtons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin"
            android:enabled="@{sleepTrackerViewModel.startButtonVisible}"
            android:onClick="@{() -> sleepTrackerViewModel.onStart()}"
            android:text="@string/start"
            app:layout_constraintBaseline_toBaselineOf="@id/stop_button"
            app:layout_constraintEnd_toStartOf="@+id/stop_button"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintStart_toStartOf="parent" />

        <Button
            android:id="@+id/stop_button"
            style="@style/SleepButtons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin"
            android:layout_marginEnd="@dimen/margin"
            android:enabled="@{sleepTrackerViewModel.stopButtonVisible}"
            android:onClick="@{() -> sleepTrackerViewModel.onStop()}"
            android:text="@string/stop"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/start_button"
            app:layout_constraintTop_toTopOf="parent" />

        <Button
            android:id="@+id/clear_button"
            style="@style/SleepButtons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin"
            android:layout_marginEnd="@dimen/margin"
            android:layout_marginBottom="@dimen/margin"
            android:enabled="@{sleepTrackerViewModel.clearButtonVisible}"
            android:onClick="@{() -> sleepTrackerViewModel.onClear()}"
            android:text="@string/clear"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
