<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ActivityView">

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

        <!-- provider -->

        <TextView
            android:id="@+id/tvProvider"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_provider"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Spinner
            android:id="@+id/spProvider"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvProvider" />

        <!-- auto config -->

        <TextView
            android:id="@+id/tvDomain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_domain"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/spProvider" />

        <EditText
            android:id="@+id/etDomain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/default_hint_domain"
            android:inputType="textUri"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvDomain" />

        <Button
            android:id="@+id/btnAutoConfig"
            style="@style/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:minWidth="0dp"
            android:minHeight="0dp"
            android:text="@string/title_autoconfig"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etDomain" />

        <!-- IMAP -->

        <TextView
            android:id="@+id/tvImap"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_imap"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/btnAutoConfig" />

        <TextView
            android:id="@+id/tvPop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_pop"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textStyle="italic"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvImap" />

        <TextView
            android:id="@+id/tvInsecure"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/title_insecure"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textStyle="italic"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvPop" />

        <!-- host -->

        <TextView
            android:id="@+id/tvHost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_host"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvInsecure" />

        <EditText
            android:id="@+id/etHost"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/default_hint_imap"
            android:inputType="textUri"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvHost" />

        <CheckBox
            android:id="@+id/cbStartTls"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_starttls"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etHost" />

        <CheckBox
            android:id="@+id/cbInsecure"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_allow_insecure"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/cbStartTls" />

        <!-- port -->

        <TextView
            android:id="@+id/tvPort"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_port"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/cbInsecure" />

        <EditText
            android:id="@+id/etPort"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/default_imap_port"
            android:inputType="number"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvPort" />

        <Button
            android:id="@+id/btnAuthorize"
            style="@style/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:minWidth="0dp"
            android:minHeight="0dp"
            android:text="@string/title_authorize"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etPort" />

        <!-- user -->

        <TextView
            android:id="@+id/tvUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_user"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/btnAuthorize" />

        <EditText
            android:id="@+id/etUser"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvUser" />

        <!-- password -->

        <TextView
            android:id="@+id/tvPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_password"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etUser" />

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/tilPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvPassword"
            app:passwordToggleEnabled="true">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword" />
        </com.google.android.material.textfield.TextInputLayout>

        <View
            android:id="@+id/vwColor"
            android:layout_width="@dimen/color_pick"
            android:layout_height="@dimen/color_pick"
            android:layout_marginTop="@dimen/base_margin"
            android:layout_marginStart="@dimen/content_margin"
            android:background="@color/colorAccent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tilPassword" />

        <ImageView
            android:id="@+id/ibColorDefault"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="12dp"
            android:layout_marginTop="12dp"
            android:src="@drawable/baseline_delete_24"
            app:layout_constraintBottom_toBottomOf="@id/vwColor"
            app:layout_constraintStart_toEndOf="@id/vwColor"
            app:layout_constraintTop_toBottomOf="@id/tilPassword" />
        
        <Button
            android:id="@+id/btnAdvanced"
            style="@style/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:minWidth="0dp"
            android:minHeight="0dp"
            android:text="@string/title_setup_advanced"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/vwColor" />

        <!-- advanced -->

        <TextView
            android:id="@+id/tvName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_account_name"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />

        <EditText
            android:id="@+id/etName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/title_account_name_hint"
            android:inputType="text"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvName" />

        <TextView
            android:id="@+id/tvSignature"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_account_signature"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etName" />

        <EditText
            android:id="@+id/etSignature"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fontFamily="monospace"
            android:hint="@string/title_optional"
            android:inputType="textCapSentences|textMultiLine"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvSignature" />

        <CheckBox
            android:id="@+id/cbSynchronize"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_synchronize_account"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etSignature" />

        <CheckBox
            android:id="@+id/cbPrimary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_primary_account"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />

        <!-- keep alive -->

        <TextView
            android:id="@+id/tvInterval"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_keep_alive_interval"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/cbPrimary" />

        <EditText
            android:id="@+id/etInterval"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/default_interval"
            android:inputType="number"
            android:textAppearance="@style/TextAppearance.AppCompat.Medium"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvInterval" />

        <!-- check -->

        <Button
            android:id="@+id/btnCheck"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_check"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etInterval" />

        <ProgressBar
            android:id="@+id/pbCheck"
            style="@style/Base.Widget.AppCompat.ProgressBar"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginStart="12dp"
            android:indeterminate="true"
            app:layout_constraintBottom_toBottomOf="@id/btnCheck"
            app:layout_constraintStart_toEndOf="@id/btnCheck"
            app:layout_constraintTop_toTopOf="@id/btnCheck" />

        <ImageButton
            android:id="@+id/ibDelete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:src="@drawable/baseline_delete_24"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/etInterval" />

        <TextView
            android:id="@+id/tvIdle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:minWidth="100dp"
            android:text="@string/title_no_idle"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            android:textStyle="bold"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/btnCheck" />

        <TextView
            android:id="@+id/tvDrafts"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="100dp"
            android:text="@string/title_folder_drafts"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintBottom_toBottomOf="@+id/spDrafts"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/spDrafts" />

        <Spinner
            android:id="@+id/spDrafts"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/tvDrafts"
            app:layout_constraintTop_toBottomOf="@id/tvIdle" />

        <TextView
            android:id="@+id/tvSent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="100dp"
            android:text="@string/title_folder_sent"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintBottom_toBottomOf="@+id/spSent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/spSent" />

        <Spinner
            android:id="@+id/spSent"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/tvSent"
            app:layout_constraintTop_toBottomOf="@id/spDrafts" />

        <TextView
            android:id="@+id/tvAll"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="100dp"
            android:text="@string/title_folder_all"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintBottom_toBottomOf="@+id/spAll"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/spAll" />

        <Spinner
            android:id="@+id/spAll"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/tvAll"
            app:layout_constraintTop_toBottomOf="@id/spSent" />

        <TextView
            android:id="@+id/tvTrash"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="100dp"
            android:text="@string/title_folder_trash"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintBottom_toBottomOf="@+id/spTrash"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/spTrash" />

        <Spinner
            android:id="@+id/spTrash"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/tvTrash"
            app:layout_constraintTop_toBottomOf="@id/spAll" />

        <TextView
            android:id="@+id/tvJunk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="100dp"
            android:text="@string/title_folder_junk"
            android:textAppearance="@style/TextAppearance.AppCompat.Small"
            app:layout_constraintBottom_toBottomOf="@+id/spJunk"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/spJunk" />

        <Spinner
            android:id="@+id/spJunk"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/tvJunk"
            app:layout_constraintTop_toBottomOf="@id/spTrash" />

        <!-- save -->

        <Button
            android:id="@+id/btnSave"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="@string/title_save"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/spJunk" />

        <ProgressBar
            android:id="@+id/pbSave"
            style="@style/Base.Widget.AppCompat.ProgressBar"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginStart="12dp"
            android:indeterminate="true"
            app:layout_constraintBottom_toBottomOf="@id/btnSave"
            app:layout_constraintStart_toEndOf="@id/btnSave"
            app:layout_constraintTop_toTopOf="@id/btnSave" />

        <ProgressBar
            android:id="@+id/pbWait"
            style="@style/Base.Widget.AppCompat.ProgressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.constraintlayout.widget.Group
            android:id="@+id/grpServer"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:constraint_referenced_ids="tvDomain,etDomain,btnAutoConfig,tvImap,tvPop,tvInsecure,tvHost,etHost,tvPort,etPort" />

        <androidx.constraintlayout.widget.Group
            android:id="@+id/grpAuthorize"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:constraint_referenced_ids="tvUser,etUser,tvPassword,tilPassword" />

        <androidx.constraintlayout.widget.Group
            android:id="@+id/grpAdvanced"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:constraint_referenced_ids="tvName,etName,tvSignature,etSignature,cbSynchronize,cbPrimary,tvInterval,etInterval" />

        <androidx.constraintlayout.widget.Group
            android:id="@+id/grpFolders"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:constraint_referenced_ids="tvDrafts,spDrafts,tvSent,spSent,tvAll,spAll,tvTrash,spTrash,tvJunk,spJunk" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
