<?xml version="1.0" encoding="utf-8"?>
<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="com.topjohnwu.magisk.core.Info" />

        <import type="com.topjohnwu.magisk.ui.home.MagiskState" />

        <import type="com.topjohnwu.magisk.ui.home.DeveloperItem" />

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.ui.home.HomeViewModel" />

    </data>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true"
        android:paddingTop="@dimen/internal_action_bar_size"
        android:paddingBottom="@dimen/l3"
        app:fitsSystemWindowsInsets="top|bottom"
        tools:layout_marginTop="24dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:orientation="vertical"
            android:paddingTop="@dimen/l1">

            <Button
                style="@style/WidgetFoundation.Button"
                gone="@{!viewModel.showTest}"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:onClick="@{() -> viewModel.onTestPressed()}"
                android:text="TEST"
                android:textAllCaps="false"
                tools:visibility="gone" />

            <com.google.android.material.card.MaterialCardView
                style="@style/WidgetFoundation.Card.Primary"
                goneUnless="@{viewModel.noticeVisible}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                android:layout_marginBottom="@dimen/l1"
                android:focusable="false">

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

                    <TextView
                        android:id="@+id/home_notice_content"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:padding="@dimen/l1"
                        android:text="@string/home_notice_content"
                        android:textAppearance="@style/AppearanceFoundation.Caption.OnPrimary"
                        app:layout_constraintEnd_toStartOf="@+id/home_notice_hide"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                    <Button
                        android:id="@+id/home_notice_hide"
                        style="@style/WidgetFoundation.Button.Text.OnPrimary"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:onClick="@{() -> viewModel.hideNotice()}"
                        android:text="@string/hide"
                        android:textAllCaps="false"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toTopOf="parent" />

                </androidx.constraintlayout.widget.ConstraintLayout>

            </com.google.android.material.card.MaterialCardView>

            <include
                android:id="@+id/home_magisk_wrapper"
                layout="@layout/include_home_magisk"
                viewModel="@{viewModel}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                app:layout_constraintTop_toBottomOf="@+id/home_device_wrapper" />

            <include
                android:id="@+id/home_manager_wrapper"
                layout="@layout/include_home_manager"
                viewModel="@{viewModel}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginTop="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                app:layout_constraintTop_toBottomOf="@+id/home_magisk_wrapper" />

            <Space
                gone="@{!viewModel.showSafetyNet &amp;&amp; !Info.env.isActive}"
                android:layout_width="match_parent"
                android:layout_height="@dimen/l1" />

            <Button
                style="@style/WidgetFoundation.Button.Outlined"
                gone="@{!viewModel.showSafetyNet}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                android:onClick="@{() -> viewModel.onSafetyNetPressed()}"
                android:text="@string/home_check_safetynet"
                android:textAllCaps="false"
                android:textSize="12sp"
                app:cornerRadius="@dimen/r1"
                app:icon="@drawable/ic_safetynet_md2" />

            <Button
                style="@style/WidgetFoundation.Button.Outlined.Error"
                goneUnless="@{Info.env.isActive}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/l1"
                android:layout_marginEnd="@dimen/l1"
                android:onClick="@{() -> viewModel.onDeletePressed()}"
                android:text="@string/uninstall_magisk_title"
                android:textAllCaps="false"
                android:textSize="12sp"
                app:cornerRadius="@dimen/r1"
                app:icon="@drawable/ic_delete_md2" />

            <com.google.android.material.card.MaterialCardView
                style="@style/WidgetFoundation.Card"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_margin="@dimen/l1"
                android:focusable="false">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:paddingTop="@dimen/l1">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="@dimen/l1"
                        android:layout_marginEnd="@dimen/l1"
                        android:text="@string/home_support_title"
                        android:textAppearance="@style/AppearanceFoundation.Title" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="@dimen/l1"
                        android:layout_marginTop="@dimen/l_50"
                        android:layout_marginEnd="@dimen/l1"
                        android:text="@string/home_support_content"
                        android:textAppearance="@style/AppearanceFoundation.Caption.Variant" />

                    <include
                        item="@{DeveloperItem.Main.INSTANCE}"
                        layout="@layout/item_developer"
                        viewModel="@{viewModel}"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/l_50" />

                    <include
                        item="@{DeveloperItem.App.INSTANCE}"
                        layout="@layout/item_developer"
                        viewModel="@{viewModel}"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/l_50" />

                </LinearLayout>

            </com.google.android.material.card.MaterialCardView>

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</layout>
