chinwag-android/app/src/main/res/layout/activity_compose.xml
Konrad Pozniak 78152f0449
Full support for Android 15, edge-to-edge mode on Android 15 (#4897)
- Update to Api 35
- Update all dependencies that were blocked because they require Api 35
- fix some deprecation warnings
- implement the now required edge-to-edge mode

Edge-to-edge mode means that we now draw under the status bar and the
navigation bar and need to make sure we don't overlap with them.
Previously the system would do that for us, and we would only provide
the color we want the bars in.

For the edge-to-edge mode there are two Apis that are important:
- `fitsSystemWindows` - some Widgets, mostly from the Material library,
automatically handle system insets if you set this attribute on them to
true
- `ViewCompat.setOnApplyWindowInsetsListener` - this allows you to
manually handle the various insets. By returning new insets from the
callback it is possible to tell the system which ones are handled and
which ones should be taken care of by another view.

In most places edge-to-edge was straightforward to implement, except in
`ComposeActivity`, `AccountActivity` and `MainActivity` which required a
more custom approach, and a hacky solution to make landscape mode work
in `BaseActivity`.

There is also the `ViewCompat.setWindowInsetsAnimationCallback` Api
which allows animating with moving insets. I used that in
`LoginActivity` and `ComposeActivity` to animate the Views together with
the keyboard.

On Android Versions below 15 (Api <= 34) Tusky will look almost the same
as before. I think the only exception is the main bottom bar, which is
now slighty larger. We customized it to be smaller than the default, but
in edge-to-edge mode the height needs to be `wrap_content` or it won't
handle insets correctly.

Screenshots: 

<img
src="https://github.com/user-attachments/assets/2a1bf5d9-79fb-48eb-affc-1cbb1164d5f0"
width="280"/>
<img
src="https://github.com/user-attachments/assets/9edccdf2-c0e9-4881-a6df-bd0872934f28"
width="280"/>
<img
src="https://github.com/user-attachments/assets/2916a271-f53e-4d38-a83a-69083eb3053f"
width="280"/>
2025-02-06 11:37:54 +01:00

395 lines
17 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
android:id="@+id/activityCompose"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/composeAvatar"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="end"
android:padding="8dp"
tools:ignore="ContentDescription" />
<!--content description will be set in code -->
<Spinner
android:id="@+id/composePostLanguageButton"
style="@style/TuskyImageButton"
android:layout_width="52dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:contentDescription="@string/description_post_language"
android:padding="0dp"
android:textColor="?android:attr/textColorTertiary"
android:textSize="?attr/status_text_large"
android:textStyle="bold"
app:tooltipText="@string/description_post_language" />
<com.google.android.material.button.MaterialButton
android:id="@+id/atButton"
style="@style/TuskyImageButton"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="8dp"
android:text="@string/at_symbol"
android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_large"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
android:id="@+id/hashButton"
style="@style/TuskyImageButton"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:padding="8dp"
android:text="@string/hash_symbol"
android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_large"
android:textStyle="bold" />
<com.google.android.material.button.MaterialButton
android:id="@+id/descriptionMissingWarningButton"
style="@style/TuskyImageButton"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:contentDescription="@string/hint_media_description_missing"
android:padding="8dp"
app:icon="@drawable/ic_missing_description_24dp"
app:iconTint="@color/tusky_orange_light"
app:tooltipText="@string/hint_media_description_missing" />
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/composeMainScrollView"
android:layout_width="match_parent"
android:layout_height="@dimen/compose_activity_scrollview_height"
android:layout_marginBottom="52dp"
android:clipToPadding="false"
android:paddingTop="8dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/composeUsernameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="0dp"
android:textSize="?attr/status_text_small"
android:textStyle="bold"
android:visibility="gone"
tools:text="Posting as @username@domain"
tools:visibility="visible" />
<TextView
android:id="@+id/composeReplyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="6dp"
android:drawablePadding="6dp"
android:textSize="?attr/status_text_small"
android:textStyle="bold"
android:visibility="gone"
tools:text="Reply to @username"
tools:visibility="visible" />
<TextView
android:id="@+id/composeReplyContentView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:background="?attr/colorBackgroundAccent"
android:lineSpacingMultiplier="1.1"
android:paddingLeft="16dp"
android:paddingTop="4dp"
android:paddingRight="16dp"
android:paddingBottom="4dp"
android:textSize="?attr/status_text_small"
android:visibility="gone"
tools:text="Post content which may be preeettyy long, so please, make sure there's enough room for everything, okay? Not kidding. I wish Eugen answered me more often, sigh."
tools:visibility="visible" />
<LinearLayout
android:id="@+id/composeContentWarningBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.emoji2.widget.EmojiEditText
android:id="@+id/composeContentWarningField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:hint="@string/hint_content_warning"
android:inputType="text|textCapSentences"
android:lineSpacingMultiplier="1.1"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColorHint="?android:attr/textColorTertiary"
android:textSize="?attr/status_text_medium" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="8dp"
android:background="?android:attr/listDivider" />
</LinearLayout>
<com.keylesspalace.tusky.components.compose.view.EditTextTyped
android:id="@+id/composeEditField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:completionThreshold="2"
android:dropDownWidth="wrap_content"
android:hint="@string/hint_compose"
android:inputType="text|textMultiLine|textCapSentences"
android:lineSpacingMultiplier="1.1"
android:paddingLeft="16dp"
android:paddingTop="8dp"
android:paddingRight="16dp"
android:paddingBottom="8dp"
android:textColorHint="?android:attr/textColorTertiary"
android:textSize="?attr/status_text_large" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/composeMediaPreviewBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:visibility="gone" />
<com.keylesspalace.tusky.components.compose.view.PollPreviewView
android:id="@+id/pollPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="@dimen/poll_preview_min_width"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="@+id/addMediaBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="52dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:id="@+id/actionPhotoTake"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:padding="8dp"
android:text="@string/action_photo_take"
android:textSize="?attr/status_text_medium" />
<TextView
android:id="@+id/actionPhotoPick"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:padding="8dp"
android:text="@string/action_add_media"
android:textSize="?attr/status_text_medium" />
<TextView
android:id="@+id/addPollTextActionTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:padding="8dp"
android:text="@string/action_add_poll"
android:textSize="?attr/status_text_medium" />
</LinearLayout>
<com.keylesspalace.tusky.view.EmojiPicker
android:id="@+id/emojiView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="60dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
<com.keylesspalace.tusky.components.compose.view.ComposeOptionsView
android:id="@+id/composeOptionsBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:paddingStart="24dp"
android:paddingTop="12dp"
android:paddingEnd="24dp"
android:paddingBottom="60dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
<com.keylesspalace.tusky.components.compose.view.ComposeScheduleView
android:id="@+id/composeScheduleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="52dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
<LinearLayout
android:id="@+id/composeBottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:animateLayoutChanges="true"
android:background="?attr/colorSurface"
android:elevation="12dp"
android:gravity="center_vertical"
android:paddingStart="8dp"
android:paddingTop="4dp"
android:paddingEnd="8dp"
android:paddingBottom="4dp"
app:layout_insetEdge="bottom">
<ImageButton
android:id="@+id/composeAddMediaButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_add_media"
android:padding="4dp"
app:srcCompat="@drawable/ic_attach_file_24dp"
app:tooltipText="@string/action_add_media" />
<ImageButton
android:id="@+id/composeToggleVisibilityButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_toggle_visibility"
android:padding="4dp"
app:tooltipText="@string/action_toggle_visibility"
tools:src="@drawable/ic_public_24dp" />
<ImageButton
android:id="@+id/composeHideMediaButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_hide_media"
android:padding="4dp"
app:tooltipText="@string/action_hide_media"
tools:src="@drawable/ic_eye_24dp" />
<ImageButton
android:id="@+id/composeContentWarningButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_content_warning"
android:padding="4dp"
app:srcCompat="@drawable/ic_cw_24dp"
app:tooltipText="@string/action_content_warning" />
<ImageButton
android:id="@+id/composeEmojiButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_emoji_keyboard"
android:padding="4dp"
app:srcCompat="@drawable/ic_emoji_24dp"
app:tooltipText="@string/action_emoji_keyboard" />
<ImageButton
android:id="@+id/composeScheduleButton"
style="@style/TuskyImageButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/action_schedule_post"
android:padding="4dp"
app:srcCompat="@drawable/ic_access_time"
app:tooltipText="@string/action_schedule_post" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/composeCharactersLeftView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_medium"
android:textStyle="bold"
tools:text="500" />
<com.keylesspalace.tusky.components.compose.view.TootButton
android:id="@+id/composeTootButton"
style="@style/TuskyButton"
android:layout_width="@dimen/toot_button_width"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="?attr/status_text_medium"
app:iconGravity="textStart" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>