<?xml version="1.0" encoding="utf-8"?>
<!-- The main application activity for Hauk. -->
<LinearLayout 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=".ui.MainActivity">
    
    <androidx.appcompat.widget.Toolbar
        android:id="@+id/mainToolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingRight="16dp"
            android:paddingLeft="16dp"
            android:paddingTop="16dp"
            android:paddingBottom="16dp">

            <!-- Logo displayed at the top of the activity. -->
            <ImageView
                android:id="@+id/imgLogo"
                android:layout_width="match_parent"
                android:layout_height="143dp"
                android:contentDescription="@string/img_alt_logo"
                android:onClick="openProjectSite"
                app:srcCompat="@drawable/ic_logo" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="19dp" />

            <!-- Heading displayed underneath the Hauk logo. -->
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:onClick="openProjectSite"
                android:text="@string/label_heading"
                android:textAppearance="@style/TextAppearance.AppCompat.Large" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:onClick="openProjectSite"
                android:text="@string/label_source_link" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="19dp" />

            <!-- Connection preferences. -->
            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <!-- Share duration, in minutes. -->
                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:labelFor="@id/txtDuration"
                        android:maxWidth="125dp"
                        android:layout_gravity="center_vertical"
                        android:text="@string/label_duration" />

                    <EditText
                        android:id="@+id/txtDuration"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:ems="10"
                        android:inputType="number"
                        android:autofillHints="minutes" />

                    <Spinner
                        android:id="@+id/selUnit"
                        android:layout_width="wrap_content"
                        android:layout_height="45dp"
                        android:entries="@array/sel_unit_opts"
                        android:gravity="center_vertical"/>
                </TableRow>

                <!-- The sharing mode (alone or group share). -->
                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="45dp"
                        android:gravity="center_vertical"
                        android:maxWidth="125dp"
                        android:layout_gravity="center_vertical"
                        android:text="@string/label_mode" />

                    <Spinner
                        android:id="@+id/selMode"
                        android:layout_width="match_parent"
                        android:layout_height="45dp"
                        android:gravity="center_vertical"
                        android:entries="@array/sel_mode_opts"
                        android:layout_weight="1" />

                </TableRow>

                <!-- If doing a solo share, whether or not to allow adoption by others. -->
                <TableRow
                    android:id="@+id/rowAllowAdopt"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_marginTop="10dp"
                        android:maxWidth="125dp"
                        android:text="@string/label_allow_adopt" />

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

                        <CheckBox
                            android:id="@+id/chkAllowAdopt"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/chk_allow_adopt" />

                        <TextView
                            android:id="@+id/labelAdoptWhatsThis"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColor="@android:color/holo_blue_dark"
                            android:paddingStart="30dp"
                            android:paddingEnd="0dp"
                            android:paddingTop="10dp"
                            android:paddingBottom="5dp"
                            android:onClick="explainAdoption"
                            android:clickable="true"
                            android:focusable="true"
                            android:text="@string/label_explain_adopt" />

                    </LinearLayout>


                </TableRow>

                <!-- Current nickname if doing a group share. -->
                <TableRow
                    android:id="@+id/rowNickname"
                    android:visibility="gone"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:labelFor="@id/txtNickname"
                        android:maxWidth="125dp"
                        android:layout_gravity="center_vertical"
                        android:text="@string/label_nickname" />

                    <EditText
                        android:id="@+id/txtNickname"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:autofillHints="nickname"
                        android:ems="10"
                        android:inputType="textPersonName" />
                </TableRow>

                <!-- Join PIN, if joining a group share. -->
                <TableRow
                    android:id="@+id/rowPIN"
                    android:visibility="gone"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:labelFor="@id/txtGroupCode"
                        android:maxWidth="125dp"
                        android:layout_gravity="center_vertical"
                        android:text="@string/label_pin" />

                    <EditText
                        android:id="@+id/txtGroupCode"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:autofillHints="code"
                        android:maxLength="6"
                        android:ems="10"
                        android:inputType="number" />
                </TableRow>

                <!-- The current connection status. -->
                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="45dp"
                        android:gravity="center_vertical"
                        android:maxWidth="125dp"
                        android:text="@string/label_status" />

                    <TextView
                        android:id="@+id/labelStatusCur"
                        android:layout_width="match_parent"
                        android:layout_height="45dp"
                        android:paddingStart="7dp"
                        android:paddingEnd="0dp"
                        android:gravity="center_vertical"
                        android:textStyle="bold"
                        android:textColor="@color/statusOff"
                        android:text="@string/label_status_none" />

                </TableRow>
            </TableLayout>

            <Space
                android:layout_width="match_parent"
                android:layout_height="25dp" />

            <LinearLayout
                android:id="@+id/layoutGroupPIN"
                android:visibility="gone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textColor="?attr/editTextColor"
                    android:textStyle="bold"
                    android:textSize="18sp"
                    android:text="@string/label_pin_head" />

                <TextView
                    android:id="@+id/labelShowPin"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textSize="55dp"
                    android:textColor="?attr/editTextColor"
                    android:textStyle="bold"
                    android:letterSpacing="0.1"
                    android:textIsSelectable="true"
                    tools:ignore="SpUsage" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:layout_marginTop="5dp"
                    android:text="@string/label_pin_help" />

                <Space
                    android:layout_width="match_parent"
                    android:layout_height="25dp" />

                <!-- The button to adopt another's location share. -->
                <Button
                    android:id="@+id/btnAdopt"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/btn_adopt" />

            </LinearLayout>

            <!-- The button that starts and stops the location sharing. -->
            <Button
                android:id="@+id/btnShare"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/btn_start"
                android:onClick="startSharing" />

            <!-- The button that adds a new sharing link. -->
            <Button
                android:id="@+id/btnLink"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:enabled="false"
                android:text="@string/btn_link" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="25dp" />

            <!-- The header above the list of active share links. -->
            <TextView
                android:id="@+id/headerLinks"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/label_heading_no_links"
                android:textAppearance="@style/TextAppearance.AppCompat.Large" />

            <Space
                android:layout_width="match_parent"
                android:layout_height="15dp" />

            <!-- The list of currently active links. Contains instances of the content_link layout. -->
            <TableLayout
                android:id="@+id/tableLinks"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </TableLayout>

        </LinearLayout>
    </ScrollView>

</LinearLayout>
