From e2a5da1d67840e3a30f200faea5dad0715402339 Mon Sep 17 00:00:00 2001 From: lynxnb Date: Sat, 5 Nov 2022 15:22:25 +0100 Subject: [PATCH] Fix `AppDialog` layout * Add a drag indicator at the top * Fix flex layout wrapping when buttons didn't fit on a single line * Fix BottomSheetDialog peek height too small on landscape orientation * General cleanup of the layout --- app/src/main/java/emu/skyline/AppDialog.kt | 35 ++-- .../emu/skyline/preference/LicenseDialog.kt | 9 + app/src/main/res/layout/app_dialog.xml | 171 ++++++++++-------- 3 files changed, 122 insertions(+), 93 deletions(-) diff --git a/app/src/main/java/emu/skyline/AppDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt index 49585726..ff043554 100644 --- a/app/src/main/java/emu/skyline/AppDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -50,27 +50,17 @@ class AppDialog : BottomSheetDialogFragment() { */ override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = AppDialogBinding.inflate(inflater).also { binding = it }.root - /** - * This expands the bottom sheet so that it's fully visible and map the B button to back - */ - override fun onStart() { - super.onStart() - - val behavior = BottomSheetBehavior.from(requireView().parent as View) - behavior.state = BottomSheetBehavior.STATE_EXPANDED - - dialog?.setOnKeyListener { _, keyCode, event -> - if (keyCode == KeyEvent.KEYCODE_BUTTON_B && event.action == KeyEvent.ACTION_UP) { - dialog?.onBackPressed() - return@setOnKeyListener true - } - false - } - } - override fun onViewCreated(view : View, savedInstanceState : Bundle?) { super.onViewCreated(view, savedInstanceState) + // Set the peek height after the root view has been laid out + view.apply { + post { + val behavior = BottomSheetBehavior.from(parent as View) + behavior.peekHeight = height + } + } + val missingIcon = ContextCompat.getDrawable(requireActivity(), R.drawable.default_icon)!!.toBitmap(256, 256) binding.gameIcon.setImageBitmap(item.icon ?: missingIcon) @@ -100,5 +90,14 @@ class AppDialog : BottomSheetDialogFragment() { shortcutManager.requestPinShortcut(info.build(), null) } + + dialog?.setOnKeyListener { _, keyCode, event -> + if (keyCode == KeyEvent.KEYCODE_BUTTON_B && event.action == KeyEvent.ACTION_UP) { + dialog?.onBackPressed() + true + } else { + false + } + } } } diff --git a/app/src/main/java/emu/skyline/preference/LicenseDialog.kt b/app/src/main/java/emu/skyline/preference/LicenseDialog.kt index 8b620f1d..9f801642 100644 --- a/app/src/main/java/emu/skyline/preference/LicenseDialog.kt +++ b/app/src/main/java/emu/skyline/preference/LicenseDialog.kt @@ -8,6 +8,7 @@ package emu.skyline.preference import android.graphics.Rect import android.os.Bundle import android.view.* +import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialogFragment import emu.skyline.databinding.LicenseDialogBinding @@ -35,6 +36,14 @@ class LicenseDialog : BottomSheetDialogFragment() { override fun onViewCreated(view : View, savedInstanceState : Bundle?) { super.onViewCreated(view, savedInstanceState) + // Set the peek height after the root view has been laid out + view.apply { + post { + val behavior = BottomSheetBehavior.from(parent as View) + behavior.peekHeight = (height * 0.7).toInt() + } + } + binding.libraryTitle.text = requireArguments().getString(LicensePreference.LIBRARY_TITLE_ARG) binding.libraryUrl.text = requireArguments().getString(LicensePreference.LIBRARY_URL_ARG) binding.libraryCopyright.text = requireArguments().getString(LicensePreference.LIBRARY_COPYRIGHT_ARG) diff --git a/app/src/main/res/layout/app_dialog.xml b/app/src/main/res/layout/app_dialog.xml index c1f47237..37f1a4ec 100644 --- a/app/src/main/res/layout/app_dialog.xml +++ b/app/src/main/res/layout/app_dialog.xml @@ -2,94 +2,115 @@ + android:orientation="vertical"> - + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:nextFocusRight="@id/game_play" + android:paddingHorizontal="16dp" + android:paddingBottom="16dp"> - + app:layout_constraintTop_toTopOf="@+id/constraintLayout" + app:shapeAppearance="?attr/shapeAppearanceSmallComponent" + tools:src="@drawable/default_icon" /> - + android:layout_marginStart="16dp" + app:layout_constraintHeight_min="140dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@id/game_icon" + app:layout_constraintTop_toTopOf="parent"> - - - - -