mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-22 21:19:17 +01:00
Refactor + Redesign AppDialog
This commit refactors `AppDialog` by bringing it in line with the guidelines. In addition, it improves the design of it substantially by modifying the layout and making it a `BottomSheetDialogFragment`.
This commit is contained in:
parent
ce4d295d81
commit
2ce8581aa6
@ -14,45 +14,62 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import emu.skyline.EmulationActivity
|
||||
import emu.skyline.R
|
||||
import emu.skyline.adapter.AppItem
|
||||
import kotlinx.android.synthetic.main.game_dialog.*
|
||||
import kotlinx.android.synthetic.main.app_dialog.*
|
||||
|
||||
class GameDialog() : DialogFragment() {
|
||||
var item: AppItem? = null
|
||||
|
||||
constructor(item: AppItem) : this() {
|
||||
this.item = item
|
||||
}
|
||||
/**
|
||||
* This dialog is used to show extra game metadata and provide extra options such as pinning the game to the home screen
|
||||
*
|
||||
* @param item This is used to hold the [AppItem] between instances
|
||||
*/
|
||||
class AppDialog(val item: AppItem? = null) : BottomSheetDialogFragment() {
|
||||
|
||||
/**
|
||||
* This inflates the layout of the dialog after initial view creation
|
||||
*/
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return requireActivity().layoutInflater.inflate(R.layout.game_dialog, container)
|
||||
return requireActivity().layoutInflater.inflate(R.layout.app_dialog, container)
|
||||
}
|
||||
|
||||
/**
|
||||
* This fills all the dialog with the information from [item] if it is valid and setup all user interaction
|
||||
*/
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
if (item is AppItem) {
|
||||
game_icon.setImageBitmap(item?.icon)
|
||||
game_title.text = item?.title
|
||||
game_subtitle.text = item?.subTitle
|
||||
val missingIcon = context?.resources?.getDrawable(R.drawable.default_icon, context?.theme)?.toBitmap(256, 256)
|
||||
|
||||
game_icon.setImageBitmap(item.icon ?: missingIcon)
|
||||
game_title.text = item.title
|
||||
game_subtitle.text = item.subTitle ?: getString(R.string.metadata_missing)
|
||||
|
||||
val shortcutManager = activity?.getSystemService(ShortcutManager::class.java)!!
|
||||
game_pin.isEnabled = shortcutManager.isRequestPinShortcutSupported
|
||||
|
||||
game_pin.setOnClickListener {
|
||||
val info = ShortcutInfo.Builder(context, item?.title)
|
||||
info.setShortLabel(item?.meta?.name!!)
|
||||
val info = ShortcutInfo.Builder(context, item.title)
|
||||
info.setShortLabel(item.meta.name)
|
||||
info.setActivity(ComponentName(context!!, EmulationActivity::class.java))
|
||||
info.setIcon(Icon.createWithBitmap(item?.icon))
|
||||
info.setIcon(Icon.createWithBitmap(item.icon ?: missingIcon))
|
||||
|
||||
val intent = Intent(context, EmulationActivity::class.java)
|
||||
intent.data = item?.uri
|
||||
intent.data = item.uri
|
||||
intent.action = Intent.ACTION_VIEW
|
||||
|
||||
info.setIntent(intent)
|
||||
|
||||
shortcutManager.requestPinShortcut(info.build(), null)
|
||||
}
|
||||
|
||||
game_play.setOnClickListener {
|
||||
val intent = Intent(activity, EmulationActivity::class.java)
|
||||
intent.data = item?.uri
|
||||
intent.data = item.uri
|
||||
|
||||
startActivity(intent)
|
||||
}
|
||||
} else
|
@ -29,7 +29,7 @@ import emu.skyline.adapter.GridLayoutSpan
|
||||
import emu.skyline.adapter.LayoutType
|
||||
import emu.skyline.loader.BaseLoader
|
||||
import emu.skyline.loader.NroLoader
|
||||
import emu.skyline.utility.GameDialog
|
||||
import emu.skyline.utility.AppDialog
|
||||
import emu.skyline.utility.RandomAccessDocument
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import java.io.File
|
||||
|
@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="?attr/colorSecondaryVariant"
|
||||
android:pathData="M15.73,3L8.27,3L3,8.27v7.46L8.27,21h7.46L21,15.73L21,8.27L15.73,3zM12,17.3c-0.72,0 -1.3,-0.58 -1.3,-1.3 0,-0.72 0.58,-1.3 1.3,-1.3 0.72,0 1.3,0.58 1.3,1.3 0,0.72 -0.58,1.3 -1.3,1.3zM13,13h-2L11,7h2v6z" />
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_play.xml
Normal file
9
app/src/main/res/drawable/ic_play.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="?attr/colorOnSecondary"
|
||||
android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/>
|
||||
</vector>
|
63
app/src/main/res/layout/app_dialog.xml
Normal file
63
app/src/main/res/layout/app_dialog.xml
Normal file
@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/game_icon"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:contentDescription="@string/icon"
|
||||
app:shapeAppearanceOverlay="@style/roundedAppImage" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Display2"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/game_play"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="@string/play"
|
||||
app:icon="@drawable/ic_play" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/game_pin"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:text="@string/pin" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/game_icon"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:contentDescription="@string/icon"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintStart_toStartOf="@id/game_icon">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/game_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Display2"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
style="?android:attr/buttonBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:gravity="clip_vertical|fill_horizontal"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/game_pin"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="@string/pin" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/game_play"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/play" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -7,16 +7,12 @@
|
||||
<item name="colorSecondaryVariant">@color/colorSecondaryDark</item>
|
||||
<item name="colorOnSecondary">@color/colorOnSecondary</item>
|
||||
</style>
|
||||
<style name="AppTheme.ActionBar" parent="ThemeOverlay.MaterialComponents.ActionBar">
|
||||
<item name="android:background">@color/colorPrimary</item>
|
||||
<style name="AppTheme.ActionBar" parent="">
|
||||
<item name="android:textColorPrimary">@color/colorOnPrimary</item>
|
||||
<item name="android:textColorSecondary">@color/colorOnPrimary</item>
|
||||
</style>
|
||||
<style name="AppTheme.PopupMenu" parent="Widget.AppCompat.PopupMenu">
|
||||
<item name="android:background">@color/colorPrimary</item>
|
||||
<item name="android:textColorPrimary">@color/colorOnPrimary</item>
|
||||
</style>
|
||||
<style name="LicenseDialogTheme" parent="Theme.MaterialComponents.DayNight.Dialog.Alert">
|
||||
<item name="windowFixedWidthMajor">90%</item>
|
||||
<item name="windowFixedWidthMinor">90%</item>
|
||||
<style name="roundedAppImage" parent="">
|
||||
<item name="cornerFamily">rounded</item>
|
||||
<item name="cornerSize">6dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user