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
This commit is contained in:
lynxnb 2022-11-05 15:22:25 +01:00 committed by Mark Collins
parent 4146261069
commit e2a5da1d67
3 changed files with 122 additions and 93 deletions

View File

@ -50,27 +50,17 @@ class AppDialog : BottomSheetDialogFragment() {
*/ */
override fun onCreateView(inflater : LayoutInflater, container : ViewGroup?, savedInstanceState : Bundle?) = AppDialogBinding.inflate(inflater).also { binding = it }.root 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?) { override fun onViewCreated(view : View, savedInstanceState : Bundle?) {
super.onViewCreated(view, savedInstanceState) 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) val missingIcon = ContextCompat.getDrawable(requireActivity(), R.drawable.default_icon)!!.toBitmap(256, 256)
binding.gameIcon.setImageBitmap(item.icon ?: missingIcon) binding.gameIcon.setImageBitmap(item.icon ?: missingIcon)
@ -100,5 +90,14 @@ class AppDialog : BottomSheetDialogFragment() {
shortcutManager.requestPinShortcut(info.build(), null) 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
}
}
} }
} }

View File

@ -8,6 +8,7 @@ package emu.skyline.preference
import android.graphics.Rect import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import emu.skyline.databinding.LicenseDialogBinding import emu.skyline.databinding.LicenseDialogBinding
@ -35,6 +36,14 @@ class LicenseDialog : BottomSheetDialogFragment() {
override fun onViewCreated(view : View, savedInstanceState : Bundle?) { override fun onViewCreated(view : View, savedInstanceState : Bundle?) {
super.onViewCreated(view, savedInstanceState) 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.libraryTitle.text = requireArguments().getString(LicensePreference.LIBRARY_TITLE_ARG)
binding.libraryUrl.text = requireArguments().getString(LicensePreference.LIBRARY_URL_ARG) binding.libraryUrl.text = requireArguments().getString(LicensePreference.LIBRARY_URL_ARG)
binding.libraryCopyright.text = requireArguments().getString(LicensePreference.LIBRARY_COPYRIGHT_ARG) binding.libraryCopyright.text = requireArguments().getString(LicensePreference.LIBRARY_COPYRIGHT_ARG)

View File

@ -2,26 +2,45 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<emu.skyline.views.DragIndicatorView
android:id="@+id/drag_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:nextFocusRight="@id/game_play" android:nextFocusRight="@id/game_play"
android:padding="16dp"> android:paddingHorizontal="16dp"
android:paddingBottom="16dp">
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
android:id="@+id/game_icon" android:id="@+id/game_icon"
android:layout_width="150dp" android:layout_width="140dp"
android:layout_height="150dp" android:layout_height="140dp"
android:contentDescription="@string/icon" android:contentDescription="@string/icon"
android:focusable="false" android:focusable="false"
app:shapeAppearance="?attr/shapeAppearanceMediumComponent" app:layout_constraintBottom_toBottomOf="@+id/constraintLayout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
app:shapeAppearance="?attr/shapeAppearanceSmallComponent"
tools:src="@drawable/default_icon" /> tools:src="@drawable/default_icon" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content" android:id="@+id/constraintLayout"
android:layout_height="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:orientation="vertical"> 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">
<TextView <TextView
android:id="@+id/game_title" android:id="@+id/game_title"
@ -40,10 +59,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="@android:color/tertiary_text_light" android:textColor="@android:color/tertiary_text_light"
android:textSize="12sp" android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/game_title" app:layout_constraintStart_toStartOf="@id/game_title"
app:layout_constraintTop_toBottomOf="@id/game_title" app:layout_constraintTop_toBottomOf="@id/game_title"
tools:text="Version" /> tools:text="1.0.0" />
<TextView <TextView
android:id="@+id/game_author" android:id="@+id/game_author"
@ -54,42 +73,44 @@
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/game_version" app:layout_constraintStart_toStartOf="@id/game_version"
app:layout_constraintTop_toBottomOf="@id/game_version" app:layout_constraintTop_toBottomOf="@id/game_version"
tools:layout_editor_absoluteY="64dp"
tools:text="Nintendo" /> tools:text="Nintendo" />
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="start" app:flexWrap="nowrap"
android:layout_marginTop="28dp" app:layout_constraintBottom_toBottomOf="parent"
app:flexWrap="wrap" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/game_title" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/game_author"> app:layout_constraintTop_toBottomOf="@+id/game_author"
app:layout_constraintVertical_bias="1">
<Button <Button
android:id="@+id/game_play" android:id="@+id/game_play"
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon" style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="6dp" android:contentDescription="@string/play"
android:focusedByDefault="true" android:focusedByDefault="true"
android:text="@string/play" android:text="@string/play"
android:textColor="?attr/colorAccent" android:textColor="?attr/colorAccent"
app:icon="@drawable/ic_play" app:icon="@drawable/ic_play"
app:iconTint="?attr/colorAccent" app:iconTint="?attr/colorAccent"
app:layout_minWidth="146dp" /> app:layout_flexGrow="1"
app:layout_maxWidth="180dp" />
<Button <Button
android:id="@+id/game_pin" android:id="@+id/game_pin"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
android:layout_width="wrap_content" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="8dp"
android:contentDescription="@string/pin"
android:textColor="?attr/colorAccent" android:textColor="?attr/colorAccent"
app:icon="@drawable/ic_add_home" app:icon="@drawable/ic_add_home"
app:iconGravity="textStart" app:iconGravity="textStart"
app:iconPadding="0dp" app:iconPadding="0dp" />
app:layout_maxWidth="55dp" />
</com.google.android.flexbox.FlexboxLayout> </com.google.android.flexbox.FlexboxLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout> </LinearLayout>