Skip to content

Commit

Permalink
DrawerFragment: set insets for edge to edge screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan09811 authored Dec 21, 2024
1 parent f01645a commit 17a9283
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.content.pm.ActivityInfo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import android.content.pm.ActivityInfo;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.graphics.Insets;

import com.google.android.material.navigation.NavigationView;
import com.panda3ds.pandroid.AlberDriver;
Expand Down Expand Up @@ -49,6 +52,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
drawerLayout = view.findViewById(R.id.drawer_layout);

((NavigationView)view.findViewById(R.id.menu)).setNavigationItemSelectedListener(this);
setInsets(((NavigationView)view.findViewById(R.id.menu)));
refresh();
}

Expand All @@ -63,6 +67,29 @@ private void refresh() {
((AppCompatTextView)drawerLayout.findViewById(R.id.game_publisher)).setText(game.getPublisher());
}

private void setInsets(NavigationView navigationView) {
ViewCompat.setOnApplyWindowInsetsListener(
navigationView,
new androidx.core.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsets) {
Insets cutInsets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout());
int left = 0;
int right = 0;
if (ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_LTR) {
left = cutInsets.left;
} else {
right = cutInsets.right;
}

view.setPadding(left, cutInsets.top, right, 0);
return windowInsets;
}
}
);
}


@Override
public void onDetach() {
if (drawerContainer != null) {
Expand Down

0 comments on commit 17a9283

Please sign in to comment.