Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Android: Add online system update functionality
- Loading branch information
1 parent
8ad1292
commit 55378ca
Showing
13 changed files
with
548 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,4 +155,3 @@ | |
</application> | ||
|
||
</manifest> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...rg/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateProgressBarDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.dolphinemu.dolphinemu.features.sysupdate.ui; | ||
|
||
import android.app.Dialog; | ||
import android.app.ProgressDialog; | ||
import android.content.pm.ActivityInfo; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.DialogFragment; | ||
import androidx.lifecycle.ViewModelProvider; | ||
|
||
import org.dolphinemu.dolphinemu.R; | ||
|
||
public class OnlineUpdateProgressBarDialogFragment extends DialogFragment | ||
{ | ||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) | ||
{ | ||
// Store the current orientation to be restored later | ||
final int orientation = getActivity().getRequestedOrientation(); | ||
// Rotating the device while the update is running can result in a title failing to import. | ||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); | ||
|
||
SystemUpdateViewModel viewModel = | ||
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); | ||
|
||
ProgressDialog progressDialog = new ProgressDialog(requireContext()); | ||
progressDialog.setTitle(getString(R.string.updating)); | ||
// We need to set the message to something here, otherwise the text will not appear when we set it later. | ||
progressDialog.setMessage(""); | ||
progressDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.cancel), (dialog, i) -> | ||
{ | ||
}); | ||
progressDialog.setOnShowListener((dialogInterface) -> | ||
{ | ||
// By default, the ProgressDialog will immediately dismiss itself upon a button being pressed. | ||
// Setting the OnClickListener again after the dialog is shown overrides this behavior. | ||
progressDialog.getButton(Dialog.BUTTON_NEGATIVE).setOnClickListener((view) -> | ||
{ | ||
viewModel.setCanceled(); | ||
}); | ||
}); | ||
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); | ||
|
||
viewModel.getProgressData().observe(this, (@Nullable Integer progress) -> | ||
{ | ||
progressDialog.setProgress(progress.intValue()); | ||
}); | ||
|
||
viewModel.getTotalData().observe(this, (@Nullable Integer total) -> | ||
{ | ||
if (total == 0) | ||
{ | ||
return; | ||
} | ||
|
||
progressDialog.setMax(total.intValue()); | ||
}); | ||
|
||
viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> | ||
{ | ||
progressDialog.setMessage(getString(R.string.updating_message, titleId)); | ||
}); | ||
|
||
viewModel.getResultData().observe(this, (@Nullable Integer result) -> | ||
{ | ||
if (result == -1) | ||
{ | ||
// This is the default value, ignore | ||
return; | ||
} | ||
|
||
OnlineUpdateResultFragment progressBarFragment = new OnlineUpdateResultFragment(); | ||
progressBarFragment.show(getParentFragmentManager(), "OnlineUpdateResultFragment"); | ||
|
||
getActivity().setRequestedOrientation(orientation); | ||
|
||
dismiss(); | ||
}); | ||
|
||
if (savedInstanceState == null) | ||
{ | ||
final String region; | ||
int selectedItem = viewModel.getRegion(); | ||
|
||
switch (selectedItem) | ||
{ | ||
case 0: | ||
region = "EUR"; | ||
break; | ||
case 1: | ||
region = "JPN"; | ||
break; | ||
case 2: | ||
region = "KOR"; | ||
break; | ||
case 3: | ||
region = "USA"; | ||
break; | ||
default: | ||
region = ""; | ||
break; | ||
} | ||
viewModel.startUpdate(region); | ||
} | ||
return progressDialog; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...g/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateRegionSelectDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.dolphinemu.dolphinemu.features.sysupdate.ui; | ||
|
||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.fragment.app.DialogFragment; | ||
import androidx.lifecycle.ViewModelProvider; | ||
|
||
import org.dolphinemu.dolphinemu.R; | ||
|
||
public class OnlineUpdateRegionSelectDialogFragment extends DialogFragment | ||
{ | ||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) | ||
{ | ||
String[] items = {getString(R.string.europe), getString( | ||
R.string.japan), getString(R.string.korea), getString(R.string.united_states)}; | ||
int checkedItem = -1; | ||
|
||
return new AlertDialog.Builder(requireContext(), R.style.DolphinDialogBase) | ||
.setTitle(R.string.region_select_title) | ||
.setSingleChoiceItems(items, checkedItem, (dialog, which) -> | ||
{ | ||
SystemUpdateViewModel viewModel = | ||
new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); | ||
viewModel.setRegion(which); | ||
|
||
OnlineUpdateProgressBarDialogFragment progressBarFragment = | ||
new OnlineUpdateProgressBarDialogFragment(); | ||
progressBarFragment | ||
.show(getParentFragmentManager(), "OnlineUpdateProgressBarDialogFragment"); | ||
progressBarFragment.setCancelable(false); | ||
|
||
dismiss(); | ||
}) | ||
.create(); | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/OnlineUpdateResultFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package org.dolphinemu.dolphinemu.features.sysupdate.ui; | ||
|
||
import android.app.Dialog; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AlertDialog; | ||
import androidx.fragment.app.DialogFragment; | ||
import androidx.lifecycle.ViewModelProvider; | ||
|
||
import org.dolphinemu.dolphinemu.R; | ||
import org.dolphinemu.dolphinemu.utils.WiiUtils; | ||
|
||
public class OnlineUpdateResultFragment 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 AlertDialog.Builder(requireContext(), R.style.DolphinDialogBase) | ||
.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); | ||
} | ||
} |
Oops, something went wrong.