mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
ConversationListActivity: properly implement edge-to-edge
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user