Address feedback

This commit is contained in:
PabloG02 2023-06-05 08:39:49 +02:00
parent 3733187c14
commit 409ff26f02
4 changed files with 28 additions and 19 deletions

View file

@ -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()
}
}

View file

@ -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,12 +44,8 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
}
if (taskViewModel.isRunning.value == false) {
val task = requireArguments().getSerializable(TASK) as? () -> Any
if (task != null) {
taskViewModel.task = task
taskViewModel.runTask()
}
}
return dialog
}
@ -55,16 +53,16 @@ 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
}

View file

@ -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) {

View file

@ -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)