mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
ConversationListArchiveActivity: properly implement edge-to-edge
This commit is contained in:
@@ -23,7 +23,6 @@ public class ConversationListArchiveActivity extends PassphraseRequiredActionBar
|
||||
protected void onCreate(Bundle icicle, boolean ready) {
|
||||
setContentView(R.layout.activity_conversation_list_archive);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setElevation(0); // TODO: use custom toolbar instead
|
||||
if (isRelayingMessageContent(this)) {
|
||||
getSupportActionBar().setTitle(isSharing(this) ? R.string.chat_share_with_title : R.string.forward_to);
|
||||
getSupportActionBar().setSubtitle(R.string.chat_archived_label);
|
||||
|
||||
@@ -108,6 +108,11 @@ public class ConversationListFragment extends BaseConversationListFragment
|
||||
emptyState = ViewUtil.findById(view, R.id.empty_state);
|
||||
emptySearch = ViewUtil.findById(view, R.id.empty_search);
|
||||
|
||||
// allow content to be drawn behind the navigation bar
|
||||
list.setClipToPadding(false);
|
||||
// add padding to avoid content hidden behind system bars
|
||||
ViewUtil.applyWindowInsets(list);
|
||||
|
||||
if (archive) {
|
||||
fab.setVisibility(View.GONE);
|
||||
TextView emptyTitle = ViewUtil.findById(view, R.id.empty_title);
|
||||
@@ -115,6 +120,8 @@ public class ConversationListFragment extends BaseConversationListFragment
|
||||
} else {
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// Apply insets to prevent fab from being covered by system bars
|
||||
ViewUtil.applyWindowInsetsAsMargin(fab);
|
||||
|
||||
list.setHasFixedSize(true);
|
||||
list.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
|
||||
@@ -297,6 +297,74 @@ public class ViewUtil {
|
||||
return selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply window insets to a view by adding margin to avoid drawing it behind system bars.
|
||||
* Convenience method that applies insets to all sides.
|
||||
*
|
||||
* @param view The view to apply insets to
|
||||
*/
|
||||
public static void applyWindowInsetsAsMargin(@NonNull View view) {
|
||||
applyWindowInsetsAsMargin(view, true, true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply window insets to a view by adding margin to avoid drawing it behind system bars.
|
||||
*
|
||||
* This method stores the original margin values in view tags to ensure that
|
||||
* margin doesn't accumulate on multiple inset applications.
|
||||
*
|
||||
* @param view The view to apply insets to
|
||||
* @param left Whether to apply left inset
|
||||
* @param top Whether to apply top inset
|
||||
* @param right Whether to apply right inset
|
||||
* @param bottom Whether to apply bottom inset
|
||||
*/
|
||||
public static void applyWindowInsetsAsMargin(@NonNull View view, boolean left, boolean top, boolean right, boolean bottom) {
|
||||
// Store the original margin as a tag only if not already stored
|
||||
// This prevents losing the true original margin on subsequent calls
|
||||
if (view.getTag(R.id.tag_window_insets_margin_left) == null) {
|
||||
ViewGroup.LayoutParams params = view.getLayoutParams();
|
||||
if (params instanceof ViewGroup.MarginLayoutParams) {
|
||||
ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) params;
|
||||
view.setTag(R.id.tag_window_insets_margin_left, marginParams.leftMargin);
|
||||
view.setTag(R.id.tag_window_insets_margin_top, marginParams.topMargin);
|
||||
view.setTag(R.id.tag_window_insets_margin_right, marginParams.rightMargin);
|
||||
view.setTag(R.id.tag_window_insets_margin_bottom, marginParams.bottomMargin);
|
||||
}
|
||||
}
|
||||
|
||||
ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
|
||||
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
|
||||
|
||||
// Retrieve the original margin values from tags with null checks
|
||||
Integer leftTag = (Integer) v.getTag(R.id.tag_window_insets_margin_left);
|
||||
Integer topTag = (Integer) v.getTag(R.id.tag_window_insets_margin_top);
|
||||
Integer rightTag = (Integer) v.getTag(R.id.tag_window_insets_margin_right);
|
||||
Integer bottomTag = (Integer) v.getTag(R.id.tag_window_insets_margin_bottom);
|
||||
int baseMarginLeft = leftTag != null ? leftTag : 0;
|
||||
int baseMarginTop = topTag != null ? topTag : 0;
|
||||
int baseMarginRight = rightTag != null ? rightTag : 0;
|
||||
int baseMarginBottom = bottomTag != null ? bottomTag : 0;
|
||||
|
||||
ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
|
||||
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||
ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) layoutParams;
|
||||
marginParams.leftMargin = baseMarginLeft + insets.left;
|
||||
marginParams.topMargin = baseMarginTop + insets.top;
|
||||
marginParams.rightMargin = baseMarginRight + insets.right;
|
||||
marginParams.bottomMargin = baseMarginBottom + insets.bottom;
|
||||
v.setLayoutParams(marginParams);
|
||||
}
|
||||
|
||||
return windowInsets;
|
||||
});
|
||||
|
||||
// Request the initial insets to be dispatched if the view is attached
|
||||
if (view.isAttachedToWindow()) {
|
||||
ViewCompat.requestApplyInsets(view);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply window insets to a view by adding padding to avoid drawing elements behind system bars.
|
||||
* Convenience method that applies insets to all sides.
|
||||
|
||||
Reference in New Issue
Block a user