<!--
  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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="io.timelimit.android.ui.overview.about.AboutFragment">

    <data>
        <variable
            name="handlers"
            type="io.timelimit.android.ui.overview.about.AboutFragmentHandlers" />

        <variable
            name="fullVersionStatus"
            type="io.timelimit.android.ui.overview.about.FullVersionStatus" />

        <variable
            name="fullVersionEndDate"
            type="String" />

        <variable
            name="customServerUrl"
            type="String" />

        <variable
            name="showPremiumCard"
            type="boolean" />

        <import type="io.timelimit.android.ui.overview.about.FullVersionStatus" />
        <import type="io.timelimit.android.BuildConfig" />
        <import type="android.text.TextUtils" />
        <import type="android.view.View" />
    </data>

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:padding="8dp"
                        android:layout_gravity="center_vertical"
                        android:src="@mipmap/ic_launcher"
                        android:layout_width="56dp"
                        android:layout_height="56dp" />

                    <LinearLayout
                        android:padding="8dp"
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <TextView
                            android:textAppearance="?android:textAppearanceLarge"
                            android:text="@string/app_name"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                        <TextView
                            android:textAppearance="?android:textAppearanceMedium"
                            tools:text="@string/about_version"
                            android:text="@{@string/about_version(BuildConfig.VERSION_NAME)}"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />
                    </LinearLayout>

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <include android:id="@+id/update"
                layout="@layout/update_view" />

            <androidx.cardview.widget.CardView
                android:visibility="@{showPremiumCard ? View.VISIBLE : View.GONE}"
                android:onClick="@{() -> handlers.startPurchase()}"
                android:foreground="?selectableItemBackground"
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="vertical"
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        tools:text="@string/about_full_version"
                        android:text="@{fullVersionStatus == FullVersionStatus.InLocalMode ? @string/about_sal : @string/about_full_version}"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:visibility="@{fullVersionStatus == FullVersionStatus.InLocalMode ? View.VISIBLE : View.GONE}"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_full_version_not_in_local_mode"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:visibility="@{fullVersionStatus == FullVersionStatus.Expired ? View.VISIBLE : View.GONE}"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_full_version_expired"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:visibility="@{fullVersionStatus == FullVersionStatus.Available ? View.VISIBLE : View.GONE}"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@{@string/about_full_version_until(fullVersionEndDate)}"
                        tools:text="@string/about_full_version_until"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:visibility="@{fullVersionStatus == FullVersionStatus.AlwaysAvailable ? View.VISIBLE : View.GONE}"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_full_version_always"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        tools:text="@string/about_full_version_tap_hint"
                        android:text="@{fullVersionStatus == FullVersionStatus.InLocalMode || fullVersionStatus == FullVersionStatus.AlwaysAvailable ? @string/about_sal_tap_hint : @string/about_full_version_tap_hint}"
                        android:textAppearance="?android:textAppearanceSmall"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="vertical"
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_contact_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:autoLink="web"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_contact_mail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <include android:id="@+id/reset_shown_hints_view"
                layout="@layout/reset_shown_hints" />

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:padding="8dp"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_terms_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:visibility="@{BuildConfig.hasServer ? View.VISIBLE : View.GONE}"
                        android:id="@+id/terms_text_1"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/terms_default_server"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:id="@+id/terms_text_2"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/terms_gpl"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:visibility="@{BuildConfig.hasServer ? View.VISIBLE : View.GONE}"
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="vertical"
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:text="@string/custom_server_status_title"
                        android:textAppearance="?android:textAppearanceLarge"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:textAppearance="?android:textAppearanceMedium"
                        tools:text="@string/custom_server_status_disabled"
                        android:text="@{TextUtils.isEmpty(customServerUrl) ? @string/custom_server_status_disabled : @string/custom_server_status_enabled(customServerUrl)}"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:foreground="?selectableItemBackground"
                android:id="@+id/error_diagnose_card"
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:padding="8dp"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_diagnose_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_diagnose_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:padding="8dp"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_contained_software_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:id="@+id/contained_software_text"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_contained_software_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:padding="8dp"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_developer_key_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_developer_key_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                app:cardUseCompatPadding="true"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:orientation="vertical"
                    android:padding="8dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <TextView
                        android:textAppearance="?android:textAppearanceLarge"
                        android:text="@string/about_source_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:id="@+id/source_code_url"
                        android:textAppearance="?android:textAppearanceMedium"
                        android:text="@string/about_source_text"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

        </LinearLayout>
    </ScrollView>

</layout>
