<?xml version="1.0" encoding="utf-8"?>
<!--
  TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation version 3 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <import type="android.text.TextUtils" />
        <import type="android.view.View" />

        <variable
            name="passwordProblem"
            type="String" />
        <variable
            name="password"
            type="String" />
        <variable
            name="passwordRepeat"
            type="String" />
        <variable
            name="passwordsNotEqualProblem"
            type="Boolean" />
        <variable
            name="allowNoPassword"
            type="boolean" />
        <variable
            name="noPasswordChecked"
            type="boolean" />
    </data>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CheckBox
            android:visibility="@{allowNoPassword ? View.VISIBLE : View.GONE}"
            android:text="@string/set_password_view_checkbox_no_password"
            android:id="@+id/no_password_checkbox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:visibility="@{allowNoPassword &amp;&amp; noPasswordChecked ? View.GONE : View.VISIBLE}"
            android:id="@+id/field_password"
            android:text="@{password}"
            android:hint="@string/set_password_view_label_password"
            android:inputType="textPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:textColor="?colorAccent"
            android:gravity="center_horizontal"
            android:textAppearance="?android:textAppearanceMedium"
            tools:text="@string/password_validator_too_short"
            android:text="@{passwordProblem}"
            android:visibility="@{TextUtils.isEmpty(passwordProblem) || (allowNoPassword &amp;&amp; noPasswordChecked) ? View.GONE : View.VISIBLE}"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:visibility="@{allowNoPassword &amp;&amp; noPasswordChecked ? View.GONE : View.VISIBLE}"
            android:id="@+id/field_password_repeat"
            android:text="@{passwordRepeat}"
            android:hint="@string/set_password_view_label_password_repeat"
            android:inputType="textPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:visibility="@{safeUnbox(passwordsNotEqualProblem) &amp;&amp; !(allowNoPassword &amp;&amp; noPasswordChecked) ? View.VISIBLE : View.GONE}"
            android:textColor="?colorAccent"
            android:gravity="center_horizontal"
            android:textAppearance="?android:textAppearanceMedium"
            android:text="@string/set_password_view_not_identical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</layout>
