diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt
index b035f9f4..e994068c 100644
--- a/app/src/main/java/emu/skyline/MainActivity.kt
+++ b/app/src/main/java/emu/skyline/MainActivity.kt
@@ -21,6 +21,7 @@ import emu.skyline.adapter.GameItem
import emu.skyline.loader.BaseLoader
import emu.skyline.loader.NroLoader
import emu.skyline.loader.TitleEntry
+import emu.skyline.utility.GameDialog
import emu.skyline.utility.RandomAccessDocument
import kotlinx.android.synthetic.main.main_activity.*
import java.io.File
@@ -31,7 +32,7 @@ import java.util.*
class MainActivity : AppCompatActivity(), View.OnClickListener {
private lateinit var sharedPreferences: SharedPreferences
private var adapter = GameAdapter(this)
- private fun notifyUser(text: String) {
+ fun notifyUser(text: String) {
Snackbar.make(findViewById(android.R.id.content), text, Snackbar.LENGTH_SHORT).show()
}
@@ -116,6 +117,14 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
startActivity(intent)
}
}
+ game_list.onItemLongClickListener = AdapterView.OnItemLongClickListener { parent, _, position, _ ->
+ val item = parent.getItemAtPosition(position)
+ if (item is GameItem) {
+ val dialog = GameDialog(item)
+ dialog.show(supportFragmentManager, "game")
+ }
+ true
+ }
if (sharedPreferences.getString("search_location", "") == "") {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.flags = Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION or Intent.FLAG_GRANT_PREFIX_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
diff --git a/app/src/main/java/emu/skyline/adapter/GameAdapter.kt b/app/src/main/java/emu/skyline/adapter/GameAdapter.kt
index be31a38e..24df521c 100644
--- a/app/src/main/java/emu/skyline/adapter/GameAdapter.kt
+++ b/app/src/main/java/emu/skyline/adapter/GameAdapter.kt
@@ -16,7 +16,7 @@ import android.widget.TextView
import emu.skyline.R
import emu.skyline.loader.TitleEntry
-internal class GameItem(val meta: TitleEntry) : BaseItem() {
+class GameItem(val meta: TitleEntry) : BaseItem() {
val icon: Bitmap?
get() = meta.icon
diff --git a/app/src/main/java/emu/skyline/loader/BaseLoader.kt b/app/src/main/java/emu/skyline/loader/BaseLoader.kt
index 0f342d44..3394edbc 100644
--- a/app/src/main/java/emu/skyline/loader/BaseLoader.kt
+++ b/app/src/main/java/emu/skyline/loader/BaseLoader.kt
@@ -29,7 +29,7 @@ fun getTitleFormat(uri: Uri, contentResolver: ContentResolver): TitleFormat {
return TitleFormat.valueOf(uriStr.substring(uriStr.lastIndexOf(".") + 1).toUpperCase(Locale.ROOT))
}
-internal class TitleEntry(var name: String, var author: String, var romType: TitleFormat, var valid: Boolean, @Transient var uri: Uri, @Transient var icon: Bitmap) : Serializable {
+class TitleEntry(var name: String, var author: String, var romType: TitleFormat, var valid: Boolean, var uri: Uri, var icon: Bitmap) : Serializable {
constructor(context: Context, author: String, romType: TitleFormat, valid: Boolean, uri: Uri) : this("", author, romType, valid, uri, context.resources.getDrawable(R.drawable.ic_missing, context.theme).toBitmap(256, 256)) {
context.contentResolver.query(uri, null, null, null, null)?.use { cursor ->
val nameIndex: Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
diff --git a/app/src/main/java/emu/skyline/utility/GameDialog.kt b/app/src/main/java/emu/skyline/utility/GameDialog.kt
new file mode 100644
index 00000000..d4b6d966
--- /dev/null
+++ b/app/src/main/java/emu/skyline/utility/GameDialog.kt
@@ -0,0 +1,60 @@
+package emu.skyline.utility
+
+import android.content.ComponentName
+import android.content.Intent
+import android.content.pm.ShortcutInfo
+import android.content.pm.ShortcutManager
+import android.graphics.drawable.Icon
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.DialogFragment
+import emu.skyline.GameActivity
+import emu.skyline.R
+import emu.skyline.adapter.GameItem
+import kotlinx.android.synthetic.main.game_dialog.*
+
+class GameDialog() : DialogFragment() {
+ var item: GameItem? = null
+
+ constructor(item: GameItem) : this() {
+ this.item = item
+ }
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
+ return requireActivity().layoutInflater.inflate(R.layout.game_dialog, container)
+ }
+
+ override fun onActivityCreated(savedInstanceState: Bundle?) {
+ super.onActivityCreated(savedInstanceState)
+ if (item is GameItem) {
+ game_icon.setImageBitmap(item?.icon)
+ game_title.text = item?.title
+ game_subtitle.text = item?.subTitle
+ val shortcutManager = activity?.getSystemService(ShortcutManager::class.java)!!
+ game_pin.isEnabled = shortcutManager.isRequestPinShortcutSupported
+ game_pin.setOnClickListener {
+ run {
+ val info = ShortcutInfo.Builder(context, item?.title)
+ info.setShortLabel(item?.meta?.name!!)
+ info.setActivity(ComponentName(context!!, GameActivity::class.java))
+ info.setIcon(Icon.createWithBitmap(item?.icon))
+ val intent = Intent(context, GameActivity::class.java)
+ intent.data = item?.uri
+ intent.action = Intent.ACTION_VIEW
+ info.setIntent(intent)
+ shortcutManager.requestPinShortcut(info.build(), null)
+ }
+ }
+ game_play.setOnClickListener {
+ run {
+ val intent = Intent(activity, GameActivity::class.java)
+ intent.data = item?.uri
+ startActivity(intent)
+ }
+ }
+ } else
+ activity?.supportFragmentManager?.beginTransaction()?.remove(this)?.commit()
+ }
+}
diff --git a/app/src/main/res/layout/game_dialog.xml b/app/src/main/res/layout/game_dialog.xml
new file mode 100644
index 00000000..10d46591
--- /dev/null
+++ b/app/src/main/res/layout/game_dialog.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d24a63f2..3dd30565 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -12,6 +12,8 @@
Icon
Cannot find any ROMs
NROs
+ Pin
+ Play
Clear
Share