diff options
author | ebraminio <ebrahim@gnu.org> | 2023-05-28 12:48:56 +0330 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-28 11:18:56 +0200 |
commit | 10c70dd5f1bd498de32e323cd2832e247df80db7 (patch) | |
tree | 20032bf120b5716f05b8dd2cb5150452d31c7535 | |
parent | 7d1259a39a81828d63ad6e32c53d791c60191e2c (diff) | |
download | AntennaPod-10c70dd5f1bd498de32e323cd2832e247df80db7.zip |
Make drawer's corners round (#6478)
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java | 41 | ||||
-rw-r--r-- | app/src/main/res/layout/nav_list.xml | 5 | ||||
-rw-r--r-- | app/src/main/res/values/dimens.xml | 2 |
3 files changed, 44 insertions, 4 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index 9f3e6465f..0916b93ad 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -1,9 +1,13 @@ package de.danoeh.antennapod.fragment; +import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.ContextMenu; @@ -17,12 +21,17 @@ import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.core.graphics.Insets; import androidx.core.util.Pair; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.google.android.material.shape.MaterialShapeDrawable; +import com.google.android.material.shape.ShapeAppearanceModel; import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; @@ -55,6 +64,7 @@ import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.model.feed.Feed; import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.appstartintent.MainActivityStarter; +import de.danoeh.antennapod.ui.common.ThemeUtils; import de.danoeh.antennapod.ui.home.HomeFragment; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -94,6 +104,20 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View root = inflater.inflate(R.layout.nav_list, container, false); + setupDrawerRoundBackground(root); + ViewCompat.setOnApplyWindowInsetsListener(root, (view, insets) -> { + Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + view.setPadding(bars.left, bars.top, bars.right, 0); + float navigationBarHeight = 0; + Activity activity = getActivity(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && activity != null) { + navigationBarHeight = getActivity().getWindow().getNavigationBarDividerColor() == Color.TRANSPARENT + ? 0 : 1 * getResources().getDisplayMetrics().density; // Assuming the divider is 1dp in height + } + float bottomInset = Math.max(0f, Math.round(bars.bottom - navigationBarHeight)); + ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).bottomMargin = (int) bottomInset; + return insets; + }); SharedPreferences preferences = getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); openFolders = new HashSet<>(preferences.getStringSet(PREF_OPEN_FOLDERS, new HashSet<>())); // Must not modify @@ -112,6 +136,23 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS return root; } + private void setupDrawerRoundBackground(View root) { + // Akin to this logic: + // https://github.com/material-components/material-components-android/blob/8938da8c/lib/java/com/google/android/material/navigation/NavigationView.java#L405 + ShapeAppearanceModel.Builder shapeBuilder = ShapeAppearanceModel.builder(); + float cornerSize = getResources().getDimension(R.dimen.drawer_corner_size); + boolean isRtl = getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + if (isRtl) { + shapeBuilder.setTopLeftCornerSize(cornerSize).setBottomLeftCornerSize(cornerSize); + } else { + shapeBuilder.setTopRightCornerSize(cornerSize).setBottomRightCornerSize(cornerSize); + } + MaterialShapeDrawable drawable = new MaterialShapeDrawable(shapeBuilder.build()); + int themeColor = ThemeUtils.getColorFromAttr(root.getContext(), android.R.attr.windowBackground); + drawable.setFillColor(ColorStateList.valueOf(themeColor)); + root.setBackground(drawable); + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); diff --git a/app/src/main/res/layout/nav_list.xml b/app/src/main/res/layout/nav_list.xml index 52fde0a5f..c0090cc73 100644 --- a/app/src/main/res/layout/nav_list.xml +++ b/app/src/main/res/layout/nav_list.xml @@ -5,15 +5,12 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_layout" android:layout_width="match_parent" - android:layout_height="match_parent" - android:fitsSystemWindows="true" - android:background="?android:attr/windowBackground"> + android:layout_height="match_parent"> <LinearLayout android:id="@+id/nav_settings" android:layout_width="match_parent" android:layout_height="@dimen/listitem_iconwithtext_height" - android:fitsSystemWindows="true" android:layout_alignParentBottom="true" android:background="?attr/selectableItemBackground" android:contentDescription="@string/settings_label" diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f5f6aa0a8..1020df135 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="additional_horizontal_spacing">0dp</dimen> + <!-- Should match with @dimen/m3_navigation_drawer_layout_corner_size --> + <dimen name="drawer_corner_size">16dp</dimen> </resources>
\ No newline at end of file |