From 2ce8581aa6b5d5fabd979d5706dbb727c041fbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=97=B1=20PixelyIon?= Date: Mon, 13 Apr 2020 01:53:03 +0530 Subject: [PATCH] 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`. --- .../{utility/GameDialog.kt => AppDialog.kt} | 51 ++++++++---- app/src/main/java/emu/skyline/MainActivity.kt | 2 +- app/src/main/res/drawable/ic_missing.xml | 9 -- app/src/main/res/drawable/ic_play.xml | 9 ++ app/src/main/res/layout/app_dialog.xml | 63 ++++++++++++++ app/src/main/res/layout/game_dialog.xml | 83 ------------------- app/src/main/res/values/styles.xml | 14 ++-- 7 files changed, 112 insertions(+), 119 deletions(-) rename app/src/main/java/emu/skyline/{utility/GameDialog.kt => AppDialog.kt} (57%) delete mode 100644 app/src/main/res/drawable/ic_missing.xml create mode 100644 app/src/main/res/drawable/ic_play.xml create mode 100644 app/src/main/res/layout/app_dialog.xml delete mode 100644 app/src/main/res/layout/game_dialog.xml diff --git a/app/src/main/java/emu/skyline/utility/GameDialog.kt b/app/src/main/java/emu/skyline/AppDialog.kt similarity index 57% rename from app/src/main/java/emu/skyline/utility/GameDialog.kt rename to app/src/main/java/emu/skyline/AppDialog.kt index 5e7338c8..f78e793e 100644 --- a/app/src/main/java/emu/skyline/utility/GameDialog.kt +++ b/app/src/main/java/emu/skyline/AppDialog.kt @@ -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 diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index a23eb85d..de1255ad 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -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 diff --git a/app/src/main/res/drawable/ic_missing.xml b/app/src/main/res/drawable/ic_missing.xml deleted file mode 100644 index 4f095d4c..00000000 --- a/app/src/main/res/drawable/ic_missing.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_play.xml b/app/src/main/res/drawable/ic_play.xml new file mode 100644 index 00000000..acabd42a --- /dev/null +++ b/app/src/main/res/drawable/ic_play.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/app_dialog.xml b/app/src/main/res/layout/app_dialog.xml new file mode 100644 index 00000000..f67dfae6 --- /dev/null +++ b/app/src/main/res/layout/app_dialog.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + +