<?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>

        <variable
            name="viewModel"
            type="com.topjohnwu.magisk.legacy.flash.FlashViewModel" />

    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
            style="@style/WidgetFoundation.Appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@{viewModel.insets.left}"
            android:paddingRight="@{viewModel.insets.right}">

            <com.google.android.material.appbar.MaterialToolbar
                style="@style/WidgetFoundation.Toolbar"
                onMenuClick="@{(item) -> viewModel.onMenuItemClicked(item)}"
                onNavigationClick="@{() -> viewModel.backPressed()}"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="?attr/actionBarSize"
                android:paddingTop="@{viewModel.insets.top}"
                app:contentInsetLeft="0dp"
                app:contentInsetStart="0dp"
                app:menu="@menu/menu_flash"
                app:navigationIcon="@drawable/ic_back_md2">

                <androidx.appcompat.widget.AppCompatTextView
                    movieBehavior="@{viewModel.loading}"
                    movieBehaviorText="@{viewModel.behaviorText}"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:textAppearance="@style/AppearanceFoundation.Body"
                    android:textStyle="bold"
                    android:fontFamily="monospace"
                    android:gravity="center"
                    android:textColor="?colorOnSurface"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    tools:text="Flashing..." />

            </com.google.android.material.appbar.MaterialToolbar>

        </com.google.android.material.appbar.AppBarLayout>

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size}"
            tools:layout_marginTop="@dimen/internal_action_bar_size">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/flash_content"
                adapter="@{viewModel.adapter}"
                itemBinding="@{viewModel.itemBinding}"
                items="@{viewModel.items}"
                scrollToLast="@{true}"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:orientation="vertical"
                android:paddingLeft="@{viewModel.insets.left}"
                android:paddingRight="@{viewModel.insets.right}"
                android:paddingBottom="@{viewModel.insets.bottom}"
                app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                tools:listitem="@layout/item_console_md2" />

        </HorizontalScrollView>

        <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
            gone="@{!viewModel.loaded || !viewModel.canShowReboot}"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/l1"
            android:layout_marginBottom="@{(int) @dimen/l1 + viewModel.insets.bottom}"
            android:onClick="@{() -> viewModel.restartPressed()}"
            android:text="@string/reboot"
            android:textAllCaps="false"
            android:textColor="?colorOnPrimary"
            android:textStyle="bold"
            app:backgroundTint="?colorPrimary"
            app:icon="@drawable/ic_restart"
            app:tint="?colorOnPrimary" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>
