Replace hardcoded URL schemes in GameActivity and CreateSudokuActivity with constants

This commit is contained in:
uykek 2020-07-01 18:45:53 +02:00
parent 47b83dc316
commit 2af00fd31c
2 changed files with 9 additions and 6 deletions

View file

@ -138,7 +138,7 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo
if(solvable) { if(solvable) {
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);
intent.setData(Uri.parse("sudoku://" + boardContent)); intent.setData(Uri.parse(GameActivity.URL_SCHEME_WITHOUT_HOST + "://" + boardContent));
startActivity(intent); startActivity(intent);
finish(); finish();
} else { } else {

View file

@ -63,6 +63,10 @@ import java.util.List;
public class GameActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, IGameSolvedListener ,ITimerListener, IHintDialogFragmentListener, IResetDialogFragmentListener, IShareDialogFragmentListener { public class GameActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, IGameSolvedListener ,ITimerListener, IHintDialogFragmentListener, IResetDialogFragmentListener, IShareDialogFragmentListener {
public static final String URL_SCHEME_WITHOUT_HOST = "sudoku";
public static final String URL_SCHEME_WITH_HOST = "http";
public static final String URL_HOST = "sudoku";
GameController gameController; GameController gameController;
SudokuFieldLayout layout; SudokuFieldLayout layout;
SudokuKeyboardLayout keyboard; SudokuKeyboardLayout keyboard;
@ -124,9 +128,9 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
if (data != null && !intentReceivedFromMainActivity) { if (data != null && !intentReceivedFromMainActivity) {
String input = ""; String input = "";
if (data.getScheme().equals("sudoku")){ if (data.getScheme().equals(URL_SCHEME_WITHOUT_HOST)){
input = data.getHost(); input = data.getHost();
} else if (data.getScheme().equals("http") && data.getHost().equals("sudoku")){ } else if (data.getScheme().equals(URL_SCHEME_WITH_HOST) && data.getHost().equals(URL_HOST)){
input = data.getPath(); input = data.getPath();
input =input.replace("/", ""); input =input.replace("/", "");
} }
@ -140,7 +144,6 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
try { try {
container.parseGameType("Default_" + sectionSize + "x" + sectionSize); container.parseGameType("Default_" + sectionSize + "x" + sectionSize);
container.parseFixedValues(input); container.parseFixedValues(input);
difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified); difficultyCheck = new QQWing(container.getGameType(), GameDifficulty.Unspecified);
difficultyCheck.setRecordHistory(true); difficultyCheck.setRecordHistory(true);
difficultyCheck.setPuzzle(container.getFixedValues()); difficultyCheck.setPuzzle(container.getFixedValues());
@ -384,8 +387,8 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
break; break;
case R.id.menu_share: case R.id.menu_share:
String codeForClipboard = "sudoku://" + gameController.getCodeOfField(); String codeForClipboard = URL_SCHEME_WITHOUT_HOST + "://" + gameController.getCodeOfField();
String codeForClipboard1 = "http://sudoku" + gameController.getCodeOfField(); String codeForClipboard1 = URL_SCHEME_WITH_HOST + "://" + URL_HOST + "/" + gameController.getCodeOfField();
ShareBoardDialog shareDialog = new ShareBoardDialog(); ShareBoardDialog shareDialog = new ShareBoardDialog();
shareDialog.setDisplayCode(codeForClipboard); shareDialog.setDisplayCode(codeForClipboard);
shareDialog.setCopyClickListener(new View.OnClickListener() { shareDialog.setCopyClickListener(new View.OnClickListener() {