Use coroutines

This commit is contained in:
PabloG02 2023-04-07 23:17:08 +02:00 committed by Billy Laws
parent c57d572936
commit 5c4973e141

View File

@ -28,7 +28,12 @@ import emu.skyline.databinding.AppDialogBinding
import emu.skyline.loader.LoaderResult
import emu.skyline.provider.DocumentsProvider
import emu.skyline.settings.SettingsActivity
import emu.skyline.utils.ZipUtils
import emu.skyline.utils.serializable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
@ -64,10 +69,14 @@ class AppDialog : BottomSheetDialogFragment() {
val saveFolder = File(savesFolderRoot + item.titleId)
val inputZip = requireContext().contentResolver.openInputStream(uri)
if (inputZip != null) {
emu.skyline.utils.ZipUtils.Companion.unzip(inputZip, saveFolder)
CoroutineScope(Dispatchers.IO).launch {
ZipUtils.unzip(inputZip, saveFolder)
withContext(Dispatchers.Main){
binding.deleteSave.isEnabled = true
binding.exportSave.isEnabled = true
}
}
}
} else {
Snackbar.make(binding.root, "Zip file must have as name the TitleID of the game", Snackbar.LENGTH_LONG).show()
}
@ -152,6 +161,7 @@ class AppDialog : BottomSheetDialogFragment() {
binding.exportSave.isEnabled = saveExists
binding.exportSave.setOnClickListener {
CoroutineScope(Dispatchers.IO).launch {
val saveFolder = File(saveFolderPath)
//val outputZipFile = File.createTempFile("out", ".zip")
val outputZipFile = File("$saveFolderPath.zip")
@ -168,14 +178,15 @@ class AppDialog : BottomSheetDialogFragment() {
}
}
}
withContext(Dispatchers.Main) {
val file = DocumentFile.fromSingleUri(requireContext(), DocumentsContract.buildDocumentUri(DocumentsProvider.AUTHORITY, "${DocumentsProvider.ROOT_ID}/switch/nand/user/save/0000000000000000/00000000000000000000000000000001/${item.titleId}.zip"))!!
val intent = Intent(Intent.ACTION_SEND)
.setDataAndType(file.uri, "application/zip")
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
.putExtra(Intent.EXTRA_STREAM, file.uri)
startActivity(Intent.createChooser(intent, "Share save file"))
//outputZipFile.deleteOnExit()
}
}
}
binding.gameTitleId.setOnLongClickListener {