<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/primary"
            app:expandedTitleMarginBottom="102dp"
            app:expandedTitleMarginEnd="128dp"
            app:expandedTitleMarginStart="47dp"
            app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="238dp"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <FrameLayout
                    android:id="@+id/view_key_photo_layout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="false"
                    android:fitsSystemWindows="true"
                    android:visibility="gone">

                    <ImageView
                        android:id="@+id/view_key_photo"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:adjustViewBounds="false"
                        android:baselineAlignBottom="false"
                        android:cropToPadding="false"
                        android:fitsSystemWindows="true"
                        android:focusable="false"
                        android:scaleType="centerCrop"
                        android:src="@mipmap/ic_launcher" />

                    <!-- text protection scrim -->
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="bottom"
                        android:background="@drawable/scrim_bottom" />

                </FrameLayout>

                <TextView
                    android:id="@+id/view_key_status"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_above="@+id/toolbar2"
                    android:layout_marginEnd="48dp"
                    android:layout_marginLeft="48dp"
                    android:layout_marginRight="48dp"
                    android:layout_marginStart="48dp"
                    android:text=""
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="?attr/colorTabText"
                    tools:text="My Key" />

                <LinearLayout
                    android:id="@+id/toolbar2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginLeft="32dp"
                    android:minHeight="?attr/actionBarSize"
                    android:orientation="horizontal">

                    <ImageButton
                        android:id="@+id/view_key_action_encrypt_files"
                        android:contentDescription="@string/cd_encrypt_files"
                        style="?android:attr/borderlessButtonStyle"
                        android:layout_width="64dp"
                        android:layout_height="64dp"
                        android:src="@drawable/ic_action_encrypt_file_24dp"
                        android:visibility="invisible"
                        tools:visibility="visible" />

                    <ImageButton
                        android:id="@+id/view_key_action_encrypt_text"
                        android:contentDescription="@string/cd_encrypt_text"
                        style="?android:attr/borderlessButtonStyle"
                        android:layout_width="64dp"
                        android:layout_height="64dp"
                        android:src="@drawable/ic_action_encrypt_text_24dp"
                        android:visibility="invisible"
                        tools:visibility="visible" />

                    <ImageButton
                        android:id="@+id/view_key_action_nfc"
                        style="?android:attr/borderlessButtonStyle"
                        android:contentDescription="@string/cd_share_nfc"
                        android:layout_width="64dp"
                        android:layout_height="64dp"
                        android:src="@drawable/ic_nfc_white_24dp"
                        android:visibility="invisible"
                        tools:visibility="visible" />

                </LinearLayout>

                <ImageView
                    android:id="@+id/view_key_status_image"
                    android:layout_width="96dp"
                    android:layout_height="96dp"
                    android:layout_above="@id/toolbar2"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="16dp"
                    android:src="@drawable/status_signature_unverified_cutout_96dp"
                    android:visibility="invisible"
                    tools:visibility="visible" />

                <android.support.v7.widget.CardView
                    android:id="@+id/view_key_qr_code_layout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_above="@id/toolbar2"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="20dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:transitionName="qr_code"
                    android:visibility="visible"
                    app:layout_collapseMode="parallax"
                    card_view:cardBackgroundColor="@android:color/white"
                    card_view:cardCornerRadius="4dp"
                    card_view:cardElevation="2dp"
                    card_view:cardUseCompatPadding="true"
                    tools:visibility="invisible">

                    <ImageView
                        android:id="@+id/view_key_qr_code"
                        android:layout_width="96dp"
                        android:layout_height="96dp" />
                </android.support.v7.widget.CardView>

            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:elevation="4dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                android:touchscreenBlocksFocus="false"
                android:transitionGroup="false"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                tools:ignore="UnusedAttribute" />
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.FlingNestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <FrameLayout
                android:id="@+id/view_key_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <FrameLayout
                android:id="@+id/view_key_keybase_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <!--
                placeholder to improve the scrolling.
                Somehow the content must be large enough to enable scrolling on NestedScrollView
            -->
            <View
                android:layout_width="match_parent"
                android:layout_height="230dp"
                android:orientation="vertical" />

        </LinearLayout>

    </android.support.v4.widget.FlingNestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:contentDescription="@string/cd_exchange_keys"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="24dp"
        android:src="@drawable/ic_qrcode_white_24dp"
        android:visibility="invisible"
        app:layout_anchor="@id/app_bar_layout"
        app:layout_anchorGravity="bottom|right|end"
        tools:visibility="visible" />

</android.support.design.widget.CoordinatorLayout>
