mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
Android: Convert SystemUpdateResultFragment to Kotlin
This commit is contained in:
parent
60cb886cd4
commit
c8907349be
@ -1,105 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.sysupdate.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.utils.WiiUtils;
|
||||
|
||||
public class SystemUpdateResultFragment extends DialogFragment
|
||||
{
|
||||
private int mResult;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||
{
|
||||
SystemUpdateViewModel viewModel =
|
||||
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);
|
||||
if (savedInstanceState == null)
|
||||
{
|
||||
mResult = viewModel.getResultData().getValue().intValue();
|
||||
viewModel.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResult = savedInstanceState.getInt("result");
|
||||
}
|
||||
|
||||
String message;
|
||||
switch (mResult)
|
||||
{
|
||||
case WiiUtils.UPDATE_RESULT_SUCCESS:
|
||||
message = getString(R.string.update_success);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_ALREADY_UP_TO_DATE:
|
||||
message = getString(R.string.already_up_to_date);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_REGION_MISMATCH:
|
||||
message = getString(R.string.region_mismatch);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_MISSING_UPDATE_PARTITION:
|
||||
message = getString(R.string.missing_update_partition);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_DISC_READ_FAILED:
|
||||
message = getString(R.string.disc_read_failed);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_SERVER_FAILED:
|
||||
message = getString(R.string.server_failed);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_DOWNLOAD_FAILED:
|
||||
message = getString(R.string.download_failed);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_IMPORT_FAILED:
|
||||
message = getString(R.string.import_failed);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_CANCELLED:
|
||||
message = getString(R.string.update_cancelled);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + mResult);
|
||||
}
|
||||
|
||||
String title;
|
||||
switch (mResult)
|
||||
{
|
||||
case WiiUtils.UPDATE_RESULT_SUCCESS:
|
||||
case WiiUtils.UPDATE_RESULT_ALREADY_UP_TO_DATE:
|
||||
title = getString(R.string.update_success_title);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_REGION_MISMATCH:
|
||||
case WiiUtils.UPDATE_RESULT_MISSING_UPDATE_PARTITION:
|
||||
case WiiUtils.UPDATE_RESULT_DISC_READ_FAILED:
|
||||
case WiiUtils.UPDATE_RESULT_SERVER_FAILED:
|
||||
case WiiUtils.UPDATE_RESULT_DOWNLOAD_FAILED:
|
||||
case WiiUtils.UPDATE_RESULT_IMPORT_FAILED:
|
||||
title = getString(R.string.update_failed_title);
|
||||
break;
|
||||
case WiiUtils.UPDATE_RESULT_CANCELLED:
|
||||
title = getString(R.string.update_cancelled_title);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + mResult);
|
||||
}
|
||||
|
||||
return new MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.ok, (dialog, which) -> dismiss())
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt("result", mResult);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.sysupdate.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.dolphinemu.dolphinemu.R
|
||||
import org.dolphinemu.dolphinemu.utils.WiiUtils
|
||||
|
||||
class SystemUpdateResultFragment : DialogFragment() {
|
||||
private var mResult = 0
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
|
||||
if (savedInstanceState == null) {
|
||||
mResult = viewModel.resultData.value!!.toInt()
|
||||
viewModel.clear()
|
||||
} else {
|
||||
mResult = savedInstanceState.getInt("result")
|
||||
}
|
||||
val message: String = when (mResult) {
|
||||
WiiUtils.UPDATE_RESULT_SUCCESS -> getString(R.string.update_success)
|
||||
WiiUtils.UPDATE_RESULT_ALREADY_UP_TO_DATE -> getString(R.string.already_up_to_date)
|
||||
WiiUtils.UPDATE_RESULT_REGION_MISMATCH -> getString(R.string.region_mismatch)
|
||||
WiiUtils.UPDATE_RESULT_MISSING_UPDATE_PARTITION -> getString(R.string.missing_update_partition)
|
||||
WiiUtils.UPDATE_RESULT_DISC_READ_FAILED -> getString(R.string.disc_read_failed)
|
||||
WiiUtils.UPDATE_RESULT_SERVER_FAILED -> getString(R.string.server_failed)
|
||||
WiiUtils.UPDATE_RESULT_DOWNLOAD_FAILED -> getString(R.string.download_failed)
|
||||
WiiUtils.UPDATE_RESULT_IMPORT_FAILED -> getString(R.string.import_failed)
|
||||
WiiUtils.UPDATE_RESULT_CANCELLED -> getString(R.string.update_cancelled)
|
||||
else -> throw IllegalStateException("Unexpected value: $mResult")
|
||||
}
|
||||
val title: String = when (mResult) {
|
||||
WiiUtils.UPDATE_RESULT_SUCCESS,
|
||||
WiiUtils.UPDATE_RESULT_ALREADY_UP_TO_DATE -> getString(R.string.update_success_title)
|
||||
WiiUtils.UPDATE_RESULT_REGION_MISMATCH,
|
||||
WiiUtils.UPDATE_RESULT_MISSING_UPDATE_PARTITION,
|
||||
WiiUtils.UPDATE_RESULT_DISC_READ_FAILED,
|
||||
WiiUtils.UPDATE_RESULT_SERVER_FAILED,
|
||||
WiiUtils.UPDATE_RESULT_DOWNLOAD_FAILED,
|
||||
WiiUtils.UPDATE_RESULT_IMPORT_FAILED -> getString(R.string.update_failed_title)
|
||||
WiiUtils.UPDATE_RESULT_CANCELLED -> getString(R.string.update_cancelled_title)
|
||||
else -> throw IllegalStateException("Unexpected value: $mResult")
|
||||
}
|
||||
|
||||
return MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.ok) { _: DialogInterface?, _: Int -> dismiss() }
|
||||
.create()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt("result", mResult)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user