Fixed #22.
This commit is contained in:
parent
1aa5500c64
commit
7a3347718a
4 changed files with 23 additions and 20 deletions
|
@ -771,7 +771,7 @@ public class GameController implements IModelChangedListener, Parcelable {
|
||||||
out.writeParcelable(gameType, 0);
|
out.writeParcelable(gameType, 0);
|
||||||
out.writeParcelable(difficulty, 0);
|
out.writeParcelable(difficulty, 0);
|
||||||
out.writeParcelable(gameBoard, 0);
|
out.writeParcelable(gameBoard, 0);
|
||||||
out.writeParcelable(undoRedoManager, 0);
|
//out.writeParcelable(undoRedoManager, 0);
|
||||||
|
|
||||||
out.writeTypedList(errorList);
|
out.writeTypedList(errorList);
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,7 @@ public class GameController implements IModelChangedListener, Parcelable {
|
||||||
gameType = in.readParcelable(GameType.class.getClassLoader());
|
gameType = in.readParcelable(GameType.class.getClassLoader());
|
||||||
difficulty = in.readParcelable(GameDifficulty.class.getClassLoader());
|
difficulty = in.readParcelable(GameDifficulty.class.getClassLoader());
|
||||||
gameBoard = in.readParcelable(GameBoard.class.getClassLoader());
|
gameBoard = in.readParcelable(GameBoard.class.getClassLoader());
|
||||||
undoRedoManager = in.readParcelable(UndoRedoManager.class.getClassLoader());
|
undoRedoManager = new UndoRedoManager(gameBoard);//*/in.readParcelable(UndoRedoManager.class.getClassLoader());
|
||||||
|
|
||||||
in.readTypedList(errorList, CellConflict.CREATOR);
|
in.readTypedList(errorList, CellConflict.CREATOR);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Looper;
|
||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
@ -26,6 +27,7 @@ import org.secuso.privacyfriendlysudoku.ui.MainActivity;
|
||||||
import org.secuso.privacyfriendlysudoku.ui.view.R;
|
import org.secuso.privacyfriendlysudoku.ui.view.R;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.IllegalFormatCodePointException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
@ -50,12 +52,16 @@ public class GeneratorService extends IntentService {
|
||||||
|
|
||||||
private final List<Pair<GameType, GameDifficulty>> generationList = new LinkedList<>();
|
private final List<Pair<GameType, GameDifficulty>> generationList = new LinkedList<>();
|
||||||
private final DatabaseHelper dbHelper = new DatabaseHelper(this);
|
private final DatabaseHelper dbHelper = new DatabaseHelper(this);
|
||||||
|
//private Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
|
||||||
public GeneratorService() {
|
public GeneratorService() {
|
||||||
super("Generator Service");
|
super("Generator Service");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GeneratorService(String name) { super(name); }
|
||||||
|
|
||||||
|
|
||||||
private void buildGenerationList() {
|
private void buildGenerationList() {
|
||||||
generationList.clear();
|
generationList.clear();
|
||||||
|
|
||||||
|
@ -80,14 +86,21 @@ public class GeneratorService extends IntentService {
|
||||||
|
|
||||||
private void handleGenerationStop() {
|
private void handleGenerationStop() {
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
stopSelf();
|
//mHandler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleGenerationStart(Intent intent) {
|
private void handleGenerationStart(Intent intent) {
|
||||||
GameType gameType = intent.getParcelableExtra(EXTRA_GAMETYPE);
|
GameType gameType;
|
||||||
GameDifficulty gameDifficulty = intent.getParcelableExtra(EXTRA_DIFFICULTY);
|
GameDifficulty gameDifficulty;
|
||||||
|
try {
|
||||||
|
gameType = GameType.valueOf(intent.getExtras().getString(EXTRA_GAMETYPE, ""));
|
||||||
|
gameDifficulty = GameDifficulty.valueOf(intent.getExtras().getString(EXTRA_DIFFICULTY, ""));
|
||||||
|
} catch(IllegalArgumentException | NullPointerException e) {
|
||||||
|
gameType = null;
|
||||||
|
gameDifficulty = null;
|
||||||
|
}
|
||||||
|
|
||||||
if(gameType == null || gameDifficulty == null) {
|
if(gameType == null) {
|
||||||
generateLevels();
|
generateLevels();
|
||||||
} else {
|
} else {
|
||||||
generateLevel(gameType, gameDifficulty);
|
generateLevel(gameType, gameDifficulty);
|
||||||
|
@ -253,13 +266,6 @@ public class GeneratorService extends IntentService {
|
||||||
builder.setSmallIcon(R.drawable.splash_icon);
|
builder.setSmallIcon(R.drawable.splash_icon);
|
||||||
startForeground(50, builder.build());
|
startForeground(50, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(@Nullable Intent intent) {
|
protected void onHandleIntent(@Nullable Intent intent) {
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
|
|
|
@ -96,11 +96,8 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
|
|
||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
Object o = extras.get("gameType");
|
gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
|
||||||
if (o instanceof GameType) {
|
gameDifficulty = GameDifficulty.valueOf(extras.getString("gameDifficulty", GameDifficulty.Moderate.name()));
|
||||||
gameType = (GameType) extras.get("gameType");
|
|
||||||
}
|
|
||||||
gameDifficulty = (GameDifficulty) (extras.get("gameDifficulty"));
|
|
||||||
loadLevel = extras.getBoolean("loadLevel", false);
|
loadLevel = extras.getBoolean("loadLevel", false);
|
||||||
if (loadLevel) {
|
if (loadLevel) {
|
||||||
loadLevelID = extras.getInt("loadLevelID");
|
loadLevelID = extras.getInt("loadLevelID");
|
||||||
|
|
|
@ -215,8 +215,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||||
|
|
||||||
// send everything to game activity
|
// send everything to game activity
|
||||||
i = new Intent(this, GameActivity.class);
|
i = new Intent(this, GameActivity.class);
|
||||||
i.putExtra("gameType", (Serializable)gameType);
|
i.putExtra("gameType", gameType.name());
|
||||||
i.putExtra("gameDifficulty", (Serializable)gameDifficulty);
|
i.putExtra("gameDifficulty", gameDifficulty.name());
|
||||||
} else {
|
} else {
|
||||||
newLevelManager.checkAndRestock();
|
newLevelManager.checkAndRestock();
|
||||||
Toast t = Toast.makeText(getApplicationContext(), R.string.generating, Toast.LENGTH_SHORT);
|
Toast t = Toast.makeText(getApplicationContext(), R.string.generating, Toast.LENGTH_SHORT);
|
||||||
|
|
Loading…
Reference in a new issue