diff options
author | PabloG02 <tioo23000@gmail.com> | 2023-06-05 08:39:49 +0200 |
---|---|---|
committer | PabloG02 <tioo23000@gmail.com> | 2023-06-06 00:07:54 +0200 |
commit | 409ff26f029861235b3f7b12400eea82c843244d (patch) | |
tree | f833790d0891b24654b0de35790b538c8de6e01e /src/android/app | |
parent | Attempt to move the unzip coroutine to a ViewModel (diff) | |
download | yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar.gz yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar.bz2 yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar.lz yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar.xz yuzu-409ff26f029861235b3f7b12400eea82c843244d.tar.zst yuzu-409ff26f029861235b3f7b12400eea82c843244d.zip |
Diffstat (limited to 'src/android/app')
4 files changed, 28 insertions, 19 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt index 0bdbabe79..d2fa46323 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/HomeSettingsFragment.kt @@ -275,7 +275,8 @@ class HomeSettingsFragment : Fragment() { private fun shareLog() { val file = DocumentFile.fromSingleUri( - mainActivity, DocumentsContract.buildDocumentUri( + mainActivity, + DocumentsContract.buildDocumentUri( DocumentProvider.AUTHORITY, "${DocumentProvider.ROOT_ID}/log/yuzu_log.txt" ) @@ -287,7 +288,11 @@ class HomeSettingsFragment : Fragment() { .putExtra(Intent.EXTRA_STREAM, file.uri) startActivity(Intent.createChooser(intent, "Share log")) } else { - Toast.makeText(requireContext(), getText(R.string.share_log_missing), Toast.LENGTH_SHORT).show() + Toast.makeText( + requireContext(), + getText(R.string.share_log_missing), + Toast.LENGTH_SHORT + ).show() } } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/IndeterminateProgressDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/IndeterminateProgressDialogFragment.kt index 10a897392..c7880d8cc 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/IndeterminateProgressDialogFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/IndeterminateProgressDialogFragment.kt @@ -1,22 +1,24 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + package org.yuzu.yuzu_emu.fragments import android.app.Dialog import android.os.Bundle import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.DialogFragment +import androidx.fragment.app.activityViewModels import androidx.lifecycle.ViewModelProvider import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding import org.yuzu.yuzu_emu.model.TaskViewModel -import java.io.Serializable class IndeterminateProgressDialogFragment : DialogFragment() { - private lateinit var taskViewModel: TaskViewModel + private val taskViewModel: TaskViewModel by activityViewModels() override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - taskViewModel = ViewModelProvider(requireActivity())[TaskViewModel::class.java] - val titleId = requireArguments().getInt(TITLE) val progressBinding = DialogProgressBarBinding.inflate(layoutInflater) @@ -42,11 +44,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() { } if (taskViewModel.isRunning.value == false) { - val task = requireArguments().getSerializable(TASK) as? () -> Any - if (task != null) { - taskViewModel.task = task - taskViewModel.runTask() - } + taskViewModel.runTask() } return dialog } @@ -55,18 +53,18 @@ class IndeterminateProgressDialogFragment : DialogFragment() { const val TAG = "IndeterminateProgressDialogFragment" private const val TITLE = "Title" - private const val TASK = "Task" fun newInstance( + activity: AppCompatActivity, titleId: Int, task: () -> Any ): IndeterminateProgressDialogFragment { val dialog = IndeterminateProgressDialogFragment() val args = Bundle() + ViewModelProvider(activity)[TaskViewModel::class.java].task = task args.putInt(TITLE, titleId) - args.putSerializable(TASK, task as Serializable) dialog.arguments = args return dialog } } -}
\ No newline at end of file +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/TaskViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/TaskViewModel.kt index 23723bceb..27ea725a5 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/TaskViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/TaskViewModel.kt @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + package org.yuzu.yuzu_emu.model import androidx.lifecycle.LiveData @@ -30,7 +33,9 @@ class TaskViewModel : ViewModel() { } fun runTask() { - if (_isRunning.value == true) return + if (_isRunning.value == true) { + return + } _isRunning.value = true viewModelScope.launch(Dispatchers.IO) { @@ -39,4 +44,4 @@ class TaskViewModel : ViewModel() { _isComplete.postValue(true) } } -}
\ No newline at end of file +} diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index 2001ad704..6805efb55 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -345,15 +345,15 @@ class MainActivity : AppCompatActivity(), ThemeProvider { FileUtil.unzip(inputZip, cacheFirmwareDir) val unfilteredNumOfFiles = cacheFirmwareDir.list()?.size ?: -1 val filteredNumOfFiles = cacheFirmwareDir.list(filterNCA)?.size ?: -2 - if (unfilteredNumOfFiles != filteredNumOfFiles) { - messageToShow = MessageDialogFragment.newInstance( + messageToShow = if (unfilteredNumOfFiles != filteredNumOfFiles) { + MessageDialogFragment.newInstance( R.string.firmware_installed_failure, R.string.firmware_installed_failure_description ) } else { firmwarePath.deleteRecursively() cacheFirmwareDir.copyRecursively(firmwarePath, true) - messageToShow = getString(R.string.save_file_imported_success) + getString(R.string.save_file_imported_success) } } catch (e: Exception) { messageToShow = getString(R.string.fatal_error) @@ -364,6 +364,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider { } IndeterminateProgressDialogFragment.newInstance( + this, R.string.firmware_installing, task ).show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG) |