<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2020 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->
<com.android.internal.widget.ConversationLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:tag="conversation"
    android:theme="@style/Theme.DeviceDefault.Notification"
    >

    <include layout="@layout/notification_template_conversation_icon_container" />

    <!-- Wraps entire "expandable" notification -->
    <com.android.internal.widget.RemeasuringLinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:clipToPadding="false"
        android:clipChildren="false"
        android:orientation="vertical"
        >
        <!-- LinearLayout for Expand Button-->
        <com.android.internal.widget.RemeasuringLinearLayout
            android:id="@+id/expand_button_and_content_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="start|top"
            android:orientation="horizontal"
            android:clipChildren="false"
            android:clipToPadding="false">
            <!--TODO: move this into a separate layout and share logic with the header to bring back app opps etc-->
            <com.android.internal.widget.RemeasuringLinearLayout
                android:id="@+id/notification_action_list_margin_target"
                android:layout_width="0dp"
                android:orientation="vertical"
                android:layout_height="wrap_content"
                android:layout_weight="1">

                <!-- Header -->

                <!-- Use layout_marginStart instead of paddingStart to work around strange
                     measurement behavior on lower display densities. -->
                <include
                    layout="@layout/notification_template_conversation_header"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="2dp"
                    android:layout_marginStart="@dimen/conversation_content_start"
                    />

                <!-- Messages -->
                <com.android.internal.widget.MessagingLinearLayout
                    android:id="@+id/notification_messaging"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="@dimen/notification_text_size"
                    android:spacing="@dimen/notification_messaging_spacing"
                    android:clipToPadding="false"
                    android:clipChildren="false"
                    />
            </com.android.internal.widget.RemeasuringLinearLayout>

            <!-- This is where the expand button container will be placed when collapsed-->
        </com.android.internal.widget.RemeasuringLinearLayout>

        <include layout="@layout/notification_template_smart_reply_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/notification_content_margin"
            android:layout_marginStart="@dimen/conversation_content_start"
            android:layout_marginEnd="@dimen/notification_content_margin_end" />
        <include layout="@layout/notification_material_action_list" />
    </com.android.internal.widget.RemeasuringLinearLayout>

    <!--expand_button_a11y_container ensures talkback focus order is correct when view is expanded.
    The -1px of marginTop and 1px of paddingTop make sure expand_button_a11y_container is prior to
    its sibling view in accessibility focus order.
    {see android.view.ViewGroup.addChildrenForAccessibility()}
    expand_button_container will be moved under expand_button_and_content_container when collapsed,
    this dynamic movement ensures message can flow under expand button when expanded-->
    <FrameLayout
        android:id="@+id/expand_button_a11y_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end|top"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:layout_marginTop="-1px"
        android:paddingTop="1px"
        >
        <!--expand_button_container is dynamically placed between here and at the end of the
        layout. It starts here since only FrameLayout layout params have gravity-->
        <FrameLayout
            android:id="@+id/expand_button_container"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="end|top"
            android:clipChildren="false"
            android:clipToPadding="false">
            <!--expand_button_touch_container makes sure that we can nicely center the expand
            content in the collapsed layout while the parent makes sure that we're never laid out
            bigger than the messaging content.-->
            <LinearLayout
                android:id="@+id/expand_button_touch_container"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/conversation_expand_button_height"
                android:orientation="horizontal"
                android:layout_gravity="end|top"
                android:paddingEnd="0dp"
                android:clipToPadding="false"
                android:clipChildren="false"
                >
                <!-- Images -->
                <com.android.internal.widget.MessagingLinearLayout
                    android:id="@+id/conversation_image_message_container"
                    android:forceHasOverlappingRendering="false"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginStart="@dimen/conversation_image_start_margin"
                    android:spacing="0dp"
                    android:layout_gravity="center"
                    android:clipToPadding="false"
                    android:clipChildren="false"
                    />
                <include layout="@layout/notification_expand_button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    />
            </LinearLayout>
        </FrameLayout>
    </FrameLayout>
</com.android.internal.widget.ConversationLayout>
