Expand GameActivity so that it accepts a string containing an enconded sudoku board (for now with default difficulty 'easy')
This commit is contained in:
parent
c0743f7a08
commit
385959d9eb
1 changed files with 37 additions and 16 deletions
|
@ -12,6 +12,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
|
@ -21,6 +22,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
|||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -28,7 +30,6 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RatingBar;
|
||||
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.databinding.DialogFragmentShareBoardBinding;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -104,6 +106,26 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
|||
if(savedInstanceState == null) {
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
Uri data = getIntent().getData();
|
||||
gameController = new GameController(sharedPref, getApplicationContext());
|
||||
|
||||
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);
|
||||
|
||||
} else {
|
||||
if (extras != null) {
|
||||
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
|
||||
gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name()));
|
||||
|
@ -113,8 +135,6 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
|||
}
|
||||
}
|
||||
|
||||
gameController = new GameController(sharedPref, getApplicationContext());
|
||||
|
||||
List<GameInfoContainer> loadableGames = GameStateManager.getLoadableGameList();
|
||||
|
||||
if (loadLevel && loadableGames.size() > loadLevelID) {
|
||||
|
@ -124,6 +144,7 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
|||
// load a new level
|
||||
gameController.loadNewLevel(gameType, gameDifficulty);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gameController = savedInstanceState.getParcelable("gameController");
|
||||
// in case we get the same object back
|
||||
|
|
Loading…
Reference in a new issue