Merge pull request #10109 from JosJuice/android-clear-confirmation

Android: Show confirmation dialog for clearing game settings
This commit is contained in:
Mai M 2021-09-19 16:10:22 -04:00 committed by GitHub
commit 70a9003947
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -3,6 +3,7 @@
package org.dolphinemu.dolphinemu.dialogs; package org.dolphinemu.dolphinemu.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast; import android.widget.Toast;
@ -10,6 +11,7 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import org.dolphinemu.dolphinemu.DolphinApplication;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.ConvertActivity; import org.dolphinemu.dolphinemu.activities.ConvertActivity;
import org.dolphinemu.dolphinemu.features.cheats.ui.CheatsActivity; import org.dolphinemu.dolphinemu.features.cheats.ui.CheatsActivity;
@ -99,7 +101,7 @@ public class GamePropertiesDialog extends DialogFragment
CheatsActivity.launch(getContext(), gameId, gameTdbId, revision, isWii)); CheatsActivity.launch(getContext(), gameId, gameTdbId, revision, isWii));
itemsBuilder.add(R.string.properties_clear_game_settings, (dialog, i) -> itemsBuilder.add(R.string.properties_clear_game_settings, (dialog, i) ->
clearGameSettings(gameId)); clearGameSettingsWithConfirmation(gameId));
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(), AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(),
R.style.DolphinDialogBase); R.style.DolphinDialogBase);
@ -109,8 +111,19 @@ public class GamePropertiesDialog extends DialogFragment
return builder.create(); return builder.create();
} }
private void clearGameSettings(String gameId) private void clearGameSettingsWithConfirmation(String gameId)
{ {
new AlertDialog.Builder(requireContext(), R.style.DolphinDialogBase)
.setTitle(R.string.properties_clear_game_settings)
.setMessage(R.string.properties_clear_game_settings_confirmation)
.setPositiveButton(R.string.yes, (dialog, i) -> clearGameSettings(gameId))
.setNegativeButton(R.string.no, null)
.show();
}
private static void clearGameSettings(String gameId)
{
Context context = DolphinApplication.getAppContext();
String gameSettingsPath = String gameSettingsPath =
DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini"; DirectoryInitialization.getUserDirectory() + "/GameSettings/" + gameId + ".ini";
String gameProfilesPath = DirectoryInitialization.getUserDirectory() + "/Config/Profiles/"; String gameProfilesPath = DirectoryInitialization.getUserDirectory() + "/Config/Profiles/";
@ -122,24 +135,24 @@ public class GamePropertiesDialog extends DialogFragment
{ {
if (gameSettingsFile.delete() || hadGameProfiles) if (gameSettingsFile.delete() || hadGameProfiles)
{ {
Toast.makeText(getContext(), Toast.makeText(context,
getResources().getString(R.string.properties_clear_success, gameId), context.getResources().getString(R.string.properties_clear_success, gameId),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
else else
{ {
Toast.makeText(getContext(), Toast.makeText(context,
getResources().getString(R.string.properties_clear_failure, gameId), context.getResources().getString(R.string.properties_clear_failure, gameId),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }
} }
else else
{ {
Toast.makeText(getContext(), R.string.properties_clear_missing, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.properties_clear_missing, Toast.LENGTH_SHORT).show();
} }
} }
private boolean recursivelyDeleteGameProfiles(@NonNull final File file, String gameId) private static boolean recursivelyDeleteGameProfiles(@NonNull final File file, String gameId)
{ {
boolean hadGameProfiles = false; boolean hadGameProfiles = false;

View File

@ -364,6 +364,7 @@
<string name="properties_edit_game_settings">Edit Game Settings</string> <string name="properties_edit_game_settings">Edit Game Settings</string>
<string name="properties_edit_cheats">Edit Cheats</string> <string name="properties_edit_cheats">Edit Cheats</string>
<string name="properties_clear_game_settings">Clear Game Settings and Cheats</string> <string name="properties_clear_game_settings">Clear Game Settings and Cheats</string>
<string name="properties_clear_game_settings_confirmation">Are you sure you want to delete all game-specific settings and cheats for this game?</string>
<string name="properties_clear_success">Cleared settings for %1$s</string> <string name="properties_clear_success">Cleared settings for %1$s</string>
<string name="properties_clear_failure">Unable to clear settings for %1$s</string> <string name="properties_clear_failure">Unable to clear settings for %1$s</string>
<string name="properties_clear_missing">No game settings to delete</string> <string name="properties_clear_missing">No game settings to delete</string>