Expand GameActivity so that it accepts a string containing an enconded sudoku board (for now with default difficulty 'easy')

This commit is contained in:
uykek 2020-05-13 23:24:03 +02:00
parent c0743f7a08
commit 385959d9eb

View file

@ -12,6 +12,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Point; import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -21,6 +22,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -28,7 +30,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RatingBar; import android.widget.RatingBar;
import android.widget.TextView; import android.widget.TextView;
@ -53,6 +54,7 @@ import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
import org.secuso.privacyfriendlysudoku.ui.view.WinDialog; import org.secuso.privacyfriendlysudoku.ui.view.WinDialog;
import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding; import org.secuso.privacyfriendlysudoku.ui.view.databinding.DialogFragmentShareBoardBinding;
import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -104,25 +106,44 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
if(savedInstanceState == null) { if(savedInstanceState == null) {
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { Uri data = getIntent().getData();
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name()));
loadLevel = extras.getBoolean("loadLevel", false);
if (loadLevel) {
loadLevelID = extras.getInt("loadLevelID");
}
}
gameController = new GameController(sharedPref, getApplicationContext()); gameController = new GameController(sharedPref, getApplicationContext());
List<GameInfoContainer> loadableGames = GameStateManager.getLoadableGameList(); boolean intentReceivedFromMainActivity = extras != null &&
(extras.containsKey("gameType") || extras.containsKey("loadLevel"));
if (data != null && !intentReceivedFromMainActivity) {
String input = data.toString();
input = input.replace("sudoku.de://", "");
int sectionSize = (int)Math.sqrt(input.length());
int boardSize = sectionSize * sectionSize;
GameInfoContainer container = new GameInfoContainer(0, null, null, null, new int [boardSize], new boolean [boardSize][sectionSize]);
container.parseFixedValues(input);
container.parseGameType("Default_" + sectionSize + "x" + sectionSize);
container.parseDifficulty("Easy");
gameController.loadLevel(container);
if (loadLevel && loadableGames.size() > loadLevelID) {
// load level from GameStateManager
gameController.loadLevel(loadableGames.get(loadLevelID));
} else { } else {
// load a new level if (extras != null) {
gameController.loadNewLevel(gameType, gameDifficulty); gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name()));
loadLevel = extras.getBoolean("loadLevel", false);
if (loadLevel) {
loadLevelID = extras.getInt("loadLevelID");
}
}
List<GameInfoContainer> loadableGames = GameStateManager.getLoadableGameList();
if (loadLevel && loadableGames.size() > loadLevelID) {
// load level from GameStateManager
gameController.loadLevel(loadableGames.get(loadLevelID));
} else {
// load a new level
gameController.loadNewLevel(gameType, gameDifficulty);
}
} }
} else { } else {
gameController = savedInstanceState.getParcelable("gameController"); gameController = savedInstanceState.getParcelable("gameController");