citra_android: fix DiskShaderCacheProgress crash (#6346)

This commit is contained in:
hank121314 2023-03-13 13:46:38 +08:00 committed by GitHub
parent 2cbf6fbb17
commit aa8df317af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -6,7 +6,6 @@ package org.citra.citra_emu.disk_shader_cache;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -56,10 +55,10 @@ public class DiskShaderCacheProgress {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity emulationActivity = Objects.requireNonNull(getActivity()); final Activity emulationActivity = requireActivity();
final String title = Objects.requireNonNull(Objects.requireNonNull(getArguments()).getString("title")); final String title = Objects.requireNonNull(requireArguments().getString("title"));
final String message = Objects.requireNonNull(Objects.requireNonNull(getArguments()).getString("message")); final String message = Objects.requireNonNull(requireArguments().getString("message"));
LayoutInflater inflater = LayoutInflater.from(emulationActivity); LayoutInflater inflater = LayoutInflater.from(emulationActivity);
View view = inflater.inflate(R.layout.dialog_progress_bar, null); View view = inflater.inflate(R.layout.dialog_progress_bar, null);
@ -75,15 +74,17 @@ public class DiskShaderCacheProgress {
finishLock.notifyAll(); finishLock.notifyAll();
} }
return new MaterialAlertDialogBuilder(emulationActivity) dialog = new MaterialAlertDialogBuilder(emulationActivity)
.setView(view)
.setTitle(title) .setTitle(title)
.setMessage(message) .setMessage(message)
.setNegativeButton(android.R.string.cancel, (dialog, which) -> emulationActivity.onBackPressed()) .setNegativeButton(android.R.string.cancel, (dialog, which) -> emulationActivity.onBackPressed())
.create(); .create();
return dialog;
} }
private void onUpdateProgress(String msg, int progress, int max) { private void onUpdateProgress(String msg, int progress, int max) {
Objects.requireNonNull(getActivity()).runOnUiThread(() -> { requireActivity().runOnUiThread(() -> {
progressBar.setProgress(progress); progressBar.setProgress(progress);
progressBar.setMax(max); progressBar.setMax(max);
progressText.setText(String.format("%d/%d", progress, max)); progressText.setText(String.format("%d/%d", progress, max));