<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2017 Jorge Ruesga

     Licensed under the Apache License, ServerVersion 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>
        <import type="android.view.View" />
        <variable name="provider" type="com.ruesga.rview.attachments.Provider" />
        <variable name="isSelected" type="boolean" />
        <variable name="text" type="java.lang.CharSequence" />
        <variable name="account" type="java.lang.CharSequence" />
        <variable name="icon" type="int" />
        <variable name="handlers" type="com.ruesga.rview.attachments.fragments.ProviderChooserFragment.EventHandlers" />
    </data>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:tag="@{provider}"
            app:bindAttachmentBackgroundResource="@{isSelected ? com.ruesga.rview.attachments.R.drawable.selector_attachment_item : com.ruesga.rview.attachments.R.attr.selectableItemBackground}"
            app:bindAttachmentSelected="@{isSelected}"
            android:onClick="@{handlers::onProviderPressed}"
            android:padding="8dp"
            android:minHeight="?attr/listPreferredItemHeightSmall"
            android:gravity="center_vertical"
            android:orientation="horizontal"
            tools:ignore="UseCompoundDrawables,UselessParent">
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                app:bindAttachmentResourceDrawable="@{icon}"
                android:tint="@color/attachmentItemTint"
                android:visibility="@{safeUnbox(icon) == 0 ? View.INVISIBLE : View.VISIBLE}"
                tools:ignore="ContentDescription" />
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="vertical">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:text="@{text}"
                    android:maxLines="1"
                    android:ellipsize="end"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="?android:attr/textColorSecondary"
                    android:textSize="16sp" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="16dp"
                    android:layout_marginStart="16dp"
                    android:text="@{account}"
                    android:maxLines="1"
                    android:ellipsize="end"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="?android:attr/textColorSecondary"
                    android:visibility="@{account == null ? View.GONE : View.VISIBLE}"
                    android:textSize="10sp"
                    tools:ignore="SmallSp"/>
            </LinearLayout>
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginEnd="5dp"
                android:layout_marginRight="5dp"
                android:padding="3dp"
                app:srcCompat="@drawable/ic_logout"
                android:tint="@color/attachmentItemTint"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:visibility="@{account == null ? View.GONE : View.VISIBLE}"
                android:onClick="@{handlers::onProviderSignoff}"
                android:tag="@{provider}"
                tools:ignore="ContentDescription" />
        </LinearLayout>
    </FrameLayout>
</layout>