<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright (C) 2019 Google Inc.
  ~
  ~ 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.
  -->

<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="video"
            type="com.example.android.devbyteviewer.domain.DevByteVideo" />

        <variable
            name="videoCallback"
            type="com.example.android.devbyteviewer.ui.VideoClick" />
    </data>

    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="0dp"
        app:cardElevation="5dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="16dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/left_well"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_begin="8dp" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/right_well"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:orientation="vertical"
                app:layout_constraintGuide_end="8dp" />

            <ImageView
                android:id="@+id/play_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="14dp"
                app:layout_constraintStart_toStartOf="@+id/left_well"
                app:layout_constraintTop_toBottomOf="@+id/video_thumbnail"
                app:srcCompat="@drawable/ic_play_circle_outline_black_48dp" />

            <TextView
                android:id="@+id/title"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:layout_marginTop="16dp"
                android:text="@{video.title}"
                android:textAlignment="viewStart"
                android:textAllCaps="false"
                android:textColor="@color/text_black"
                android:textStyle="bold"
                app:layout_constraintEnd_toStartOf="@+id/right_well"
                app:layout_constraintStart_toEndOf="@+id/play_icon"
                app:layout_constraintTop_toBottomOf="@+id/video_thumbnail"
                tools:text="Video title" />


            <TextView
                android:id="@+id/description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginBottom="16dp"
                android:text="@{video.shortDescription}"
                android:textAlignment="viewStart"
                android:textAllCaps="false"
                android:textColor="@color/text_light"
                android:textSize="14sp"
                app:layout_constraintEnd_toEndOf="@+id/right_well"
                app:layout_constraintStart_toStartOf="@+id/left_well"
                app:layout_constraintTop_toBottomOf="@+id/title"
                app:layout_constraintBottom_toBottomOf="parent"
                tools:text="this is a video @android:string/fingerprint_icon_content_description" />

            <ImageView
                android:id="@+id/video_thumbnail"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:adjustViewBounds="false"
                android:cropToPadding="false"
                android:scaleType="centerCrop"
                app:imageUrl="@{video.thumbnail}"
                app:layout_constraintDimensionRatio="h,4:3"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:srcCompat="@tools:sample/backgrounds/scenic" />

            <View
                android:id="@+id/clickableOverlay"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="?attr/selectableItemBackground"
                android:onClick="@{() -> videoCallback.onClick(video)}"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </com.google.android.material.card.MaterialCardView>
</layout>