ConversationListActivity: properly implement edge-to-edge

This commit is contained in:
adbenitez
2025-11-26 07:55:35 +01:00
parent 10164032f0
commit b09838f033
4 changed files with 31 additions and 10 deletions
@@ -45,6 +45,19 @@ public abstract class BaseActionBarActivity extends AppCompatActivity {
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Apply window insets for edge-to-edge display
// The toolbar/app bar should extend behind the status bar with padding applied
View toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
// Check if toolbar is inside an AppBarLayout
View parent = (View) toolbar.getParent();
if (parent instanceof com.google.android.material.appbar.AppBarLayout) {
ViewUtil.applyWindowInsets(parent, true, true, true, false);
} else {
ViewUtil.applyWindowInsets(toolbar, true, true, true, false);
}
}
// For activities without a custom toolbar, apply insets to status_bar_background view
View statusBarBackground = findViewById(R.id.status_bar_background);
if (statusBarBackground != null) {
@@ -111,7 +111,7 @@ public class ConversationListFragment extends BaseConversationListFragment
// allow content to be drawn behind the navigation bar
list.setClipToPadding(false);
// add padding to avoid content hidden behind system bars
ViewUtil.applyWindowInsets(list);
ViewUtil.applyWindowInsets(list, true, archive, true, true);
if (archive) {
fab.setVisibility(View.GONE);
@@ -297,6 +297,18 @@ public class ViewUtil {
return selection;
}
/**
* Get combined insets from status bar, navigation bar and display cutout areas.
*
* @param windowInsets The window insets to extract from
* @return Combined insets using the maximum values from system bars and display cutout
*/
private static Insets getCombinedInsets(@NonNull WindowInsetsCompat windowInsets) {
Insets systemBars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Insets displayCutout = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout());
return Insets.max(systemBars, displayCutout);
}
/**
* Apply window insets to a view by adding margin to avoid drawing it behind system bars.
* Convenience method that applies insets to all sides.
@@ -334,7 +346,7 @@ public class ViewUtil {
}
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Insets insets = getCombinedInsets(windowInsets);
// Retrieve the original margin values from tags with null checks
Integer leftTag = (Integer) v.getTag(R.id.tag_window_insets_margin_left);
@@ -398,7 +410,7 @@ public class ViewUtil {
}
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Insets insets = getCombinedInsets(windowInsets);
// Retrieve the original padding values from tags with null checks
Integer leftTag = (Integer) v.getTag(R.id.tag_window_insets_padding_left);
@@ -434,7 +446,7 @@ public class ViewUtil {
*/
public static void applyWindowInsetsAsHeight(@NonNull View view) {
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
Insets insets = getCombinedInsets(windowInsets);
android.view.ViewGroup.LayoutParams params = v.getLayoutParams();
if (params != null) {
@@ -4,8 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@id/container"
android:orientation="vertical"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
@@ -13,7 +11,7 @@
android:id="@+id/toolbar"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:contentInsetStart="0dp"
@@ -95,9 +93,7 @@
<FrameLayout android:id="@+id/fragment_container"
android:layout_below="@id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground"
/>
android:layout_height="match_parent"/>
<org.thoughtcrime.securesms.components.SearchToolbar
android:id="@+id/search_toolbar"