Modify the parameters of the 'verify' method in CreateSudokuActivity and alter the method so that it catches IllegalArgumentExceptions thrown by the 'parseFixedValues' method of the GameInfoContainer class.
This commit is contained in:
parent
6e638afe41
commit
295c35710b
2 changed files with 15 additions and 5 deletions
|
@ -107,13 +107,17 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean verify(Context context, GameType gameType, String boardContent) {
|
public static boolean verify(GameType gameType, String boardContent) {
|
||||||
Toast.makeText(context, R.string.verify_custom_sudoku_process_toast, Toast.LENGTH_SHORT).show();
|
|
||||||
int boardSize = gameType.getSize() * gameType.getSize();
|
int boardSize = gameType.getSize() * gameType.getSize();
|
||||||
|
|
||||||
GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified,
|
GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified,
|
||||||
gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][gameType.getSize()]);
|
gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][gameType.getSize()]);
|
||||||
container.parseFixedValues(boardContent);
|
|
||||||
|
try {
|
||||||
|
container.parseFixedValues(boardContent);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QQWing verifier = new QQWing(gameType, GameDifficulty.Unspecified);
|
QQWing verifier = new QQWing(gameType, GameDifficulty.Unspecified);
|
||||||
verifier.setRecordHistory(true);
|
verifier.setRecordHistory(true);
|
||||||
|
@ -124,12 +128,18 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onFinalizeDialogPositiveClick() {
|
public void onFinalizeDialogPositiveClick() {
|
||||||
|
Toast.makeText(CreateSudokuActivity.this, R.string.verify_custom_sudoku_process_toast, Toast.LENGTH_SHORT).show();
|
||||||
String boardContent = gameController.getCodeOfField();
|
String boardContent = gameController.getCodeOfField();
|
||||||
boolean distinctlySolvable = verify(CreateSudokuActivity.this, gameController.getGameType(), boardContent);
|
boolean distinctlySolvable = verify(gameController.getGameType(), boardContent);
|
||||||
|
|
||||||
if(distinctlySolvable) {
|
if(distinctlySolvable) {
|
||||||
Toast.makeText(CreateSudokuActivity.this, R.string.finished_verifying_custom_sudoku_toast, Toast.LENGTH_LONG).show();
|
Toast.makeText(CreateSudokuActivity.this, R.string.finished_verifying_custom_sudoku_toast, Toast.LENGTH_LONG).show();
|
||||||
final Intent intent = new Intent(this, GameActivity.class);
|
final Intent intent = new Intent(this, GameActivity.class);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Since the GameActivity expects the links of imported sudokus to start with an url scheme,
|
||||||
|
add one to the start of the encoded board
|
||||||
|
*/
|
||||||
intent.setData(Uri.parse(GameActivity.URL_SCHEME_WITHOUT_HOST + "://" + boardContent));
|
intent.setData(Uri.parse(GameActivity.URL_SCHEME_WITHOUT_HOST + "://" + boardContent));
|
||||||
intent.putExtra("isCustom", true);
|
intent.putExtra("isCustom", true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -437,7 +437,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
}
|
}
|
||||||
|
|
||||||
GameType gameType = Enum.valueOf(GameType.class, "Default_" + size + "x" + size);
|
GameType gameType = Enum.valueOf(GameType.class, "Default_" + size + "x" + size);
|
||||||
boolean solvable = CreateSudokuActivity.verify(MainActivity.this, gameType, inputSudoku);
|
boolean solvable = CreateSudokuActivity.verify(gameType, inputSudoku);
|
||||||
|
|
||||||
if (solvable) {
|
if (solvable) {
|
||||||
Toast.makeText(MainActivity.this, R.string.finished_verifying_custom_sudoku_toast, Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.this, R.string.finished_verifying_custom_sudoku_toast, Toast.LENGTH_LONG).show();
|
||||||
|
|
Loading…
Reference in a new issue