Skip to content

Commit

Permalink
fix(platform): Fix edge to edge glitch in MainActivity
Browse files Browse the repository at this point in the history
Refs: #1713

Signed-off-by: Stefan Niedermann <[email protected]>
  • Loading branch information
stefan-niedermann committed Jan 3, 2025
1 parent 18a3fa3 commit e76cae0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import androidx.activity.OnBackPressedCallback;
import androidx.activity.result.ActivityResultLauncher;
Expand All @@ -30,10 +31,12 @@
import androidx.appcompat.widget.PopupMenu;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.Insets;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.splashscreen.SplashScreen;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
Expand Down Expand Up @@ -243,6 +246,28 @@ protected void onCreate(Bundle savedInstanceState) {

drawerMenuInflater = new DrawerMenuInflater<>(this, binding.navigationView.getMenu());

ViewCompat.setOnApplyWindowInsetsListener(binding.navigationView, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
final var mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
mlp.topMargin = insets.top;
mlp.leftMargin = insets.left;
mlp.bottomMargin = insets.bottom;
mlp.rightMargin = insets.right;
v.setLayoutParams(mlp);
return WindowInsetsCompat.CONSUMED;
});
ViewCompat.setOnApplyWindowInsetsListener(binding.fab, (v, windowInsets) -> {
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
final var mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
final var defaultMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
mlp.topMargin = insets.top + defaultMargin;
mlp.leftMargin = insets.left + defaultMargin;
mlp.bottomMargin = insets.bottom + defaultMargin;
mlp.rightMargin = insets.right + defaultMargin;
v.setLayoutParams(mlp);
return WindowInsetsCompat.CONSUMED;
});

preferencesViewModel.isDebugModeEnabled$().observe(this, enabled -> headerBinding.copyDebugLogs.setVisibility(enabled ? View.VISIBLE : View.GONE));
filterViewModel.hasActiveFilter().observe(this, hasActiveFilter -> {
final var menu = binding.toolbar.getMenu();
Expand Down Expand Up @@ -506,6 +531,8 @@ private void applyBoardTheme(@ColorInt int color) {

utils.deck.themeSearchBar(binding.toolbar);
utils.deck.themeSearchView(binding.searchView);
utils.deck.themeAppBarLayoutAndStatusBarWithBackground(binding.appBarLayout);
// utils.deck.themeStatusBar(this, binding.appBarLayout);
utils.deck.themeTabLayoutOnTransparent(binding.stackTitles);
utils.deck.themeEmptyContentView(binding.emptyContentViewStacks);
utils.deck.themeEmptyContentView(binding.emptyContentViewSearchNoTerm);
Expand Down
43 changes: 22 additions & 21 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,30 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
android:layout_height="match_parent">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.MainActivity">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:windowBackground"
android:fitsSystemWindows="true">

<com.google.android.material.search.SearchBar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/main_menu"
app:navigationIcon="@drawable/ic_arrow_back_24dp" />

</com.google.android.material.appbar.AppBarLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -49,7 +64,7 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
Expand Down Expand Up @@ -116,26 +131,11 @@
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:windowBackground">

<com.google.android.material.search.SearchBar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/main_menu"
app:navigationIcon="@drawable/ic_arrow_back_24dp" />

</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
Expand All @@ -144,7 +144,8 @@
android:layout_margin="@dimen/fab_margin"
android:text="@string/add_card"
android:visibility="gone"
app:icon="@drawable/ic_add_24dp" />
app:icon="@drawable/ic_add_24dp"
tools:visibility="visible" />

<com.google.android.material.search.SearchView
android:id="@+id/search_view"
Expand Down Expand Up @@ -188,7 +189,7 @@
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="false"
android:fitsSystemWindows="true"
android:theme="@style/NavigationView"
app:headerLayout="@layout/nav_header_main"
app:itemRippleColor="?attr/colorControlHighlight"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_card_edit_tab_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
android:orientation="vertical"
android:fitsSystemWindows="true">

<LinearLayout
android:id="@+id/replyComment"
Expand Down

0 comments on commit e76cae0

Please sign in to comment.