mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-01-15 16:33:15 -03:00
Android: Format MainPresenter
This commit is contained in:
@@ -104,8 +104,9 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
|
||||
fun onCreate() {
|
||||
// Ask the user to grant write permission if relevant and not already granted
|
||||
if (DirectoryInitialization.isWaitingForWriteAccess(activity))
|
||||
if (DirectoryInitialization.isWaitingForWriteAccess(activity)) {
|
||||
PermissionsHandler.requestWritePermission(activity)
|
||||
}
|
||||
|
||||
val versionName = BuildConfig.VERSION_NAME
|
||||
mainView.setVersionString(versionName)
|
||||
@@ -118,85 +119,83 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
}
|
||||
|
||||
fun launchFileListActivity() {
|
||||
val intent =
|
||||
if (DirectoryInitialization.preferOldFolderPicker(activity)) {
|
||||
FileBrowserHelper.createDirectoryPickerIntent(
|
||||
activity,
|
||||
FileBrowserHelper.GAME_EXTENSIONS,
|
||||
)
|
||||
} else {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
|
||||
}
|
||||
val intent = if (DirectoryInitialization.preferOldFolderPicker(activity)) {
|
||||
FileBrowserHelper.createDirectoryPickerIntent(
|
||||
activity,
|
||||
FileBrowserHelper.GAME_EXTENSIONS,
|
||||
)
|
||||
} else {
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
|
||||
}
|
||||
requestDirectory.launch(intent)
|
||||
}
|
||||
|
||||
fun handleOptionSelection(itemId: Int, activity: ComponentActivity): Boolean =
|
||||
when (itemId) {
|
||||
R.id.menu_settings -> {
|
||||
mainView.launchSettingsActivity(MenuTag.SETTINGS)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_grid_options -> {
|
||||
mainView.showGridOptions()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_refresh -> {
|
||||
mainView.setRefreshing(true)
|
||||
GameFileCacheManager.startRescan()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.button_add_directory -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(activity) { launchFileListActivity() }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_open_file -> {
|
||||
requestGameFile.launch("*/*")
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_load_wii_system_menu -> {
|
||||
launchWiiSystemMenu()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_online_system_update -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(activity) { launchOnlineUpdate() }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_install_wad -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestWadFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_import_wii_save -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestWiiSaveFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_import_nand_backup -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestNandBinFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_about -> {
|
||||
showAboutDialog()
|
||||
false
|
||||
}
|
||||
|
||||
else -> false
|
||||
fun handleOptionSelection(itemId: Int, activity: ComponentActivity): Boolean = when (itemId) {
|
||||
R.id.menu_settings -> {
|
||||
mainView.launchSettingsActivity(MenuTag.SETTINGS)
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_grid_options -> {
|
||||
mainView.showGridOptions()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_refresh -> {
|
||||
mainView.setRefreshing(true)
|
||||
GameFileCacheManager.startRescan()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.button_add_directory -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(activity) { launchFileListActivity() }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_open_file -> {
|
||||
requestGameFile.launch("*/*")
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_load_wii_system_menu -> {
|
||||
launchWiiSystemMenu()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_online_system_update -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(activity) { launchOnlineUpdate() }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_install_wad -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestWadFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_import_wii_save -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestWiiSaveFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_import_nand_backup -> {
|
||||
AfterDirectoryInitializationRunner().runWithLifecycle(
|
||||
activity
|
||||
) { requestNandBinFile.launch("*/*") }
|
||||
true
|
||||
}
|
||||
|
||||
R.id.menu_about -> {
|
||||
showAboutDialog()
|
||||
false
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
|
||||
fun onResume() {
|
||||
if (dirToAdd != null) {
|
||||
GameFileCache.addGameFolder(dirToAdd!!)
|
||||
@@ -226,24 +225,25 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
val recursive = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.boolean
|
||||
val childNames = ContentHandler.getChildNames(uri, recursive)
|
||||
if (Arrays.stream(childNames).noneMatch {
|
||||
FileBrowserHelper.GAME_EXTENSIONS
|
||||
.contains(FileBrowserHelper.getExtension(it, false))
|
||||
}) {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(
|
||||
activity.getString(
|
||||
R.string.wrong_file_extension_in_directory,
|
||||
FileBrowserHelper.setToSortedDelimitedString(FileBrowserHelper.GAME_EXTENSIONS)
|
||||
FileBrowserHelper.GAME_EXTENSIONS.contains(
|
||||
FileBrowserHelper.getExtension(
|
||||
it, false
|
||||
)
|
||||
)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show()
|
||||
}) {
|
||||
MaterialAlertDialogBuilder(activity).setMessage(
|
||||
activity.getString(
|
||||
R.string.wrong_file_extension_in_directory,
|
||||
FileBrowserHelper.setToSortedDelimitedString(FileBrowserHelper.GAME_EXTENSIONS)
|
||||
)
|
||||
).setPositiveButton(android.R.string.ok, null).show()
|
||||
}
|
||||
|
||||
val contentResolver = activity.contentResolver
|
||||
val canonicalizedUri = contentResolver.canonicalize(uri)
|
||||
if (canonicalizedUri != null)
|
||||
if (canonicalizedUri != null) {
|
||||
uri = canonicalizedUri
|
||||
}
|
||||
|
||||
val takeFlags = result.flags and Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
activity.contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||
@@ -253,10 +253,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
|
||||
fun installWAD(path: String?) {
|
||||
ThreadUtil.runOnThreadAndShowResult(
|
||||
activity,
|
||||
R.string.import_in_progress,
|
||||
0,
|
||||
{
|
||||
activity, R.string.import_in_progress, 0, {
|
||||
val success = WiiUtils.installWAD(path!!)
|
||||
val message =
|
||||
if (success) R.string.wad_install_success else R.string.wad_install_failure
|
||||
@@ -266,26 +263,20 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
|
||||
fun importWiiSave(path: String?) {
|
||||
ThreadUtil.runOnThreadAndShowResult(
|
||||
activity,
|
||||
R.string.import_in_progress,
|
||||
0,
|
||||
{
|
||||
activity, R.string.import_in_progress, 0, {
|
||||
val canOverwrite = BooleanSupplier {
|
||||
val latch = CountDownLatch(1)
|
||||
val decision = AtomicReference<Boolean>()
|
||||
activity.runOnUiThread {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.wii_save_exists)
|
||||
MaterialAlertDialogBuilder(activity).setMessage(R.string.wii_save_exists)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes) { _: DialogInterface?, _: Int ->
|
||||
decision.set(true)
|
||||
latch.countDown()
|
||||
}
|
||||
.setNegativeButton(R.string.no) { _: DialogInterface?, _: Int ->
|
||||
}.setNegativeButton(R.string.no) { _: DialogInterface?, _: Int ->
|
||||
decision.set(false)
|
||||
latch.countDown()
|
||||
}
|
||||
.show()
|
||||
}.show()
|
||||
}
|
||||
try {
|
||||
latch.await()
|
||||
@@ -307,23 +298,18 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
}
|
||||
|
||||
fun importNANDBin(path: String?) {
|
||||
MaterialAlertDialogBuilder(activity)
|
||||
.setMessage(R.string.nand_import_warning)
|
||||
MaterialAlertDialogBuilder(activity).setMessage(R.string.nand_import_warning)
|
||||
.setNegativeButton(R.string.no) { dialog: DialogInterface, _: Int -> dialog.dismiss() }
|
||||
.setPositiveButton(R.string.yes) { dialog: DialogInterface, _: Int ->
|
||||
dialog.dismiss()
|
||||
ThreadUtil.runOnThreadAndShowResult(
|
||||
activity,
|
||||
R.string.import_in_progress,
|
||||
R.string.do_not_close_app,
|
||||
{
|
||||
activity, R.string.import_in_progress, R.string.do_not_close_app, {
|
||||
// ImportNANDBin unfortunately doesn't provide any result value...
|
||||
// It does however show a panic alert if something goes wrong.
|
||||
WiiUtils.importNANDBin(path!!)
|
||||
null
|
||||
})
|
||||
}
|
||||
.show()
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun launchOnlineUpdate() {
|
||||
@@ -333,8 +319,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
launchUpdateProgressBarFragment(activity)
|
||||
} else {
|
||||
SystemMenuNotInstalledDialogFragment().show(
|
||||
activity.supportFragmentManager,
|
||||
SystemMenuNotInstalledDialogFragment.TAG
|
||||
activity.supportFragmentManager, SystemMenuNotInstalledDialogFragment.TAG
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -345,8 +330,7 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
EmulationActivity.launchSystemMenu(activity)
|
||||
} else {
|
||||
SystemMenuNotInstalledDialogFragment().show(
|
||||
activity.supportFragmentManager,
|
||||
SystemMenuNotInstalledDialogFragment.TAG
|
||||
activity.supportFragmentManager, SystemMenuNotInstalledDialogFragment.TAG
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -373,8 +357,9 @@ class MainPresenter(private val mainView: MainView, private val activity: Fragme
|
||||
|
||||
private fun launchUpdateProgressBarFragment(activity: FragmentActivity) {
|
||||
val progressBarFragment = SystemUpdateProgressBarDialogFragment()
|
||||
progressBarFragment
|
||||
.show(activity.supportFragmentManager, SystemUpdateProgressBarDialogFragment.TAG)
|
||||
progressBarFragment.show(
|
||||
activity.supportFragmentManager, SystemUpdateProgressBarDialogFragment.TAG
|
||||
)
|
||||
progressBarFragment.isCancelable = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user