Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

package org.dolphinemu.dolphinemu.activities

import android.annotation.SuppressLint
import android.content.DialogInterface
import android.content.Intent
import android.graphics.Rect
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.SparseIntArray
Expand All @@ -16,6 +16,7 @@ import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -87,6 +88,92 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {

private lateinit var binding: ActivityEmulationBinding

private val requestChangeDisc = registerForActivityResult(
ActivityResultContracts.GetContent()
) { uri: Uri? ->
if (uri != null) {
NativeLibrary.ChangeDisc(uri.toString())
}
}

val requestSkylanderFile = registerForActivityResult(
ActivityResultContracts.GetContent()
) { uri: Uri? ->
if (uri != null) {
val slot = SkylanderConfig.loadSkylander(
skylanderSlots[skylanderSlot].portalSlot,
uri.toString()
)!!
clearSkylander(skylanderSlot)
skylanderSlots[skylanderSlot].portalSlot = slot.first!!
skylanderSlots[skylanderSlot].label = slot.second!!
skylandersBinding.figureManager.adapter!!.notifyItemChanged(skylanderSlot)
skylanderSlot = -1
skylanderData = Skylander.BLANK_SKYLANDER
}
}

val requestCreateSkylander = registerForActivityResult(
ActivityResultContracts.CreateDocument("*/*")
) { uri: Uri? ->
if (uri != null) {
if (skylanderData.id != -1 && skylanderData.variant != -1) {
val slot = SkylanderConfig.createSkylander(
skylanderData.id,
skylanderData.variant,
uri.toString(),
skylanderSlots[skylanderSlot].portalSlot
)
clearSkylander(skylanderSlot)
skylanderSlots[skylanderSlot].portalSlot = slot.first
skylanderSlots[skylanderSlot].label = slot.second
skylandersBinding.figureManager.adapter?.notifyItemChanged(skylanderSlot)
skylanderSlot = -1
skylanderData = Skylander.BLANK_SKYLANDER
}
}
}

val requestInfinityFigureFile = registerForActivityResult(
ActivityResultContracts.GetContent()
) { uri: Uri? ->
if (uri != null) {
val label = InfinityConfig.loadFigure(infinityPosition, uri.toString())
if (label != null && label != "Unknown Figure") {
clearInfinityFigure(infinityPosition)
infinityFigures[infinityPosition].label = label
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1
infinityFigureData = Figure.BLANK_FIGURE
} else {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.incompatible_figure_selected)
.setMessage(R.string.select_compatible_figure)
.setPositiveButton(android.R.string.ok, null)
.show()
}
}
}

val requestCreateInfinityFigure = registerForActivityResult(
ActivityResultContracts.CreateDocument("*/*")
) { uri: Uri? ->
if (uri != null) {
if (infinityFigureData.number != -1L) {
val label = InfinityConfig.createFigure(
infinityFigureData.number,
uri.toString(),
infinityPosition
)
clearInfinityFigure(infinityPosition)
infinityFigures[infinityPosition].label = label!!
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1
infinityFigureData = Figure.BLANK_FIGURE
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
ThemeHelper.setTheme(this)

Expand Down Expand Up @@ -263,70 +350,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
return super.onKeyLongPress(keyCode, event)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, result: Intent?) {
super.onActivityResult(requestCode, resultCode, result)
// If the user picked a file, as opposed to just backing out.
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_CHANGE_DISC) {
NativeLibrary.ChangeDisc(result!!.data.toString())
} else if (requestCode == REQUEST_SKYLANDER_FILE) {
val slot = SkylanderConfig.loadSkylander(
skylanderSlots[skylanderSlot].portalSlot,
result!!.data.toString()
)!!
clearSkylander(skylanderSlot)
skylanderSlots[skylanderSlot].portalSlot = slot.first!!
skylanderSlots[skylanderSlot].label = slot.second!!
skylandersBinding.figureManager.adapter!!.notifyItemChanged(skylanderSlot)
skylanderSlot = -1
skylanderData = Skylander.BLANK_SKYLANDER
} else if (requestCode == REQUEST_CREATE_SKYLANDER) {
if (skylanderData.id != -1 && skylanderData.variant != -1) {
val slot = SkylanderConfig.createSkylander(
skylanderData.id,
skylanderData.variant,
result!!.data.toString(),
skylanderSlots[skylanderSlot].portalSlot
)
clearSkylander(skylanderSlot)
skylanderSlots[skylanderSlot].portalSlot = slot.first
skylanderSlots[skylanderSlot].label = slot.second
skylandersBinding.figureManager.adapter?.notifyItemChanged(skylanderSlot)
skylanderSlot = -1
skylanderData = Skylander.BLANK_SKYLANDER
}
} else if (requestCode == REQUEST_INFINITY_FIGURE_FILE) {
val label = InfinityConfig.loadFigure(infinityPosition, result!!.data.toString())
if (label != null && label != "Unknown Figure") {
clearInfinityFigure(infinityPosition)
infinityFigures[infinityPosition].label = label
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1
infinityFigureData = Figure.BLANK_FIGURE
} else {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.incompatible_figure_selected)
.setMessage(R.string.select_compatible_figure)
.setPositiveButton(android.R.string.ok, null)
.show()
}
} else if (requestCode == REQUEST_CREATE_INFINITY_FIGURE) {
if (infinityFigureData.number != -1L) {
val label = InfinityConfig.createFigure(
infinityFigureData.number,
result!!.data.toString(),
infinityPosition
)
clearInfinityFigure(infinityPosition)
infinityFigures[infinityPosition].label = label!!
infinityBinding.figureManager.adapter?.notifyItemChanged(infinityPosition)
infinityPosition = -1
infinityFigureData = Figure.BLANK_FIGURE
}
}
}
}

private fun enableFullscreenImmersive() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
Expand Down Expand Up @@ -480,12 +503,7 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
MENU_ACTION_LOAD_SLOT4 -> NativeLibrary.LoadState(3)
MENU_ACTION_LOAD_SLOT5 -> NativeLibrary.LoadState(4)
MENU_ACTION_LOAD_SLOT6 -> NativeLibrary.LoadState(5)
MENU_ACTION_CHANGE_DISC -> {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "*/*"
startActivityForResult(intent, REQUEST_CHANGE_DISC)
}
MENU_ACTION_CHANGE_DISC -> requestChangeDisc.launch("*/*")

MENU_SET_IR_MODE -> setIRMode()
MENU_ACTION_CHOOSE_DOUBLETAP -> chooseDoubleTapButton()
Expand Down Expand Up @@ -997,11 +1015,6 @@ class EmulationActivity : AppCompatActivity(), ThemeProvider {
companion object {
private const val BACKSTACK_NAME_MENU = "menu"
private const val BACKSTACK_NAME_SUBMENU = "submenu"
const val REQUEST_CHANGE_DISC = 1
const val REQUEST_SKYLANDER_FILE = 2
const val REQUEST_CREATE_SKYLANDER = 3
const val REQUEST_INFINITY_FIGURE_FILE = 4
const val REQUEST_CREATE_INFINITY_FIGURE = 5

private var ignoreLaunchRequests = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import android.os.Bundle
import android.provider.DocumentsContract
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
Expand Down Expand Up @@ -38,6 +40,40 @@ class UserDataActivity : AppCompatActivity() {

private lateinit var mBinding: ActivityUserDataBinding

private val requestImport = registerForActivityResult(
ActivityResultContracts.OpenDocument()
) { uri: Uri? ->
if (uri != null) {
val arguments = Bundle()
arguments.putString(
UserDataImportWarningDialog.KEY_URI_RESULT,
uri.toString()
)

val dialog = UserDataImportWarningDialog()
dialog.arguments = arguments
dialog.show(supportFragmentManager, UserDataImportWarningDialog.TAG)
}
}

private val requestExport = registerForActivityResult(
ActivityResultContracts.CreateDocument("application/zip")
) { uri: Uri? ->
if (uri != null) {
taskViewModel.clear()
taskViewModel.task = { exportUserData(uri) }

val arguments = Bundle()
arguments.putInt(TaskDialog.KEY_TITLE, R.string.export_in_progress)
arguments.putInt(TaskDialog.KEY_MESSAGE, 0)
arguments.putBoolean(TaskDialog.KEY_CANCELLABLE, true)

val dialog = TaskDialog()
dialog.arguments = arguments
dialog.show(supportFragmentManager, TaskDialog.TAG)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
taskViewModel = ViewModelProvider(this)[TaskViewModel::class.java]

Expand Down Expand Up @@ -85,34 +121,6 @@ class UserDataActivity : AppCompatActivity() {
return true
}

public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

if (requestCode == REQUEST_CODE_IMPORT && resultCode == RESULT_OK) {
val arguments = Bundle()
arguments.putString(
UserDataImportWarningDialog.KEY_URI_RESULT,
data!!.data!!.toString()
)

val dialog = UserDataImportWarningDialog()
dialog.arguments = arguments
dialog.show(supportFragmentManager, UserDataImportWarningDialog.TAG)
} else if (requestCode == REQUEST_CODE_EXPORT && resultCode == RESULT_OK) {
taskViewModel.clear()
taskViewModel.task = { exportUserData(data!!.data!!) }

val arguments = Bundle()
arguments.putInt(TaskDialog.KEY_TITLE, R.string.export_in_progress)
arguments.putInt(TaskDialog.KEY_MESSAGE, 0)
arguments.putBoolean(TaskDialog.KEY_CANCELLABLE, true)

val dialog = TaskDialog()
dialog.arguments = arguments
dialog.show(supportFragmentManager, TaskDialog.TAG)
}
}

private fun openFileManager() {
// First, try to open the user data folder directly
try {
Expand Down Expand Up @@ -171,15 +179,14 @@ class UserDataActivity : AppCompatActivity() {
}

private fun importUserData() {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.type = "application/zip"
startActivityForResult(intent, REQUEST_CODE_IMPORT)
requestImport.launch(arrayOf("application/zip"))
}

fun importUserData(source: Uri): Int {
try {
if (!isDolphinUserDataBackup(source))
if (!isDolphinUserDataBackup(source)) {
return R.string.user_data_import_invalid_file
}

taskViewModel.onResultDismiss = {
// Restart the app to apply the imported user data.
Expand Down Expand Up @@ -274,10 +281,7 @@ class UserDataActivity : AppCompatActivity() {
}

private fun exportUserData() {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.type = "application/zip"
intent.putExtra(Intent.EXTRA_TITLE, "dolphin-emu.zip")
startActivityForResult(intent, REQUEST_CODE_EXPORT)
requestExport.launch("dolphin-emu.zip")
}

private fun exportUserData(destination: Uri): Int {
Expand Down Expand Up @@ -340,9 +344,6 @@ class UserDataActivity : AppCompatActivity() {
}

companion object {
private const val REQUEST_CODE_IMPORT = 0
private const val REQUEST_CODE_EXPORT = 1

private const val BUFFER_SIZE = 64 * 1024

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,8 @@ class FigureSlotAdapter(
}

holder.binding.buttonLoadFigure.setOnClickListener {
val loadFigure = Intent(Intent.ACTION_OPEN_DOCUMENT)
loadFigure.addCategory(Intent.CATEGORY_OPENABLE)
loadFigure.type = "*/*"
activity.setInfinityFigureData(0, "", figure.position, position)
activity.startActivityForResult(
loadFigure,
EmulationActivity.REQUEST_INFINITY_FIGURE_FILE
)
activity.requestInfinityFigureFile.launch("*/*")
}

val inflater = LayoutInflater.from(activity)
Expand Down Expand Up @@ -110,28 +104,11 @@ class FigureSlotAdapter(
.show()
createDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (binding.infinityNum.text.toString().isNotBlank()) {
val createFigure = Intent(Intent.ACTION_CREATE_DOCUMENT)
createFigure.addCategory(Intent.CATEGORY_OPENABLE)
createFigure.type = "*/*"
val num = binding.infinityNum.text.toString().toLong()
val name = InfinityConfig.LIST_FIGURES[num]
if (name != null) {
createFigure.putExtra(
Intent.EXTRA_TITLE,
"$name.bin"
)
activity.setInfinityFigureData(num, name, figure.position, position)
} else {
createFigure.putExtra(
Intent.EXTRA_TITLE,
"Unknown(Number: $num).bin"
)
activity.setInfinityFigureData(num, "Unknown", figure.position, position)
}
activity.startActivityForResult(
createFigure,
EmulationActivity.REQUEST_CREATE_INFINITY_FIGURE
)
val title = if (name != null) "$name.bin" else "Unknown(Number: $num).bin"
activity.setInfinityFigureData(num, name ?: "Unknown", figure.position, position)
activity.requestCreateInfinityFigure.launch(title)
createDialog.dismiss()
} else {
Toast.makeText(
Expand Down
Loading