From 7a3347718ac0163613f341050fed67c9f27e56e0 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Thu, 29 Jun 2017 14:34:08 +0200 Subject: [PATCH] Fixed #22. --- .../controller/GameController.java | 4 +-- .../controller/GeneratorService.java | 28 +++++++++++-------- .../ui/GameActivity.java | 7 ++--- .../ui/MainActivity.java | 4 +-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java index 8cb12b9..3ea8f65 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java @@ -771,7 +771,7 @@ public class GameController implements IModelChangedListener, Parcelable { out.writeParcelable(gameType, 0); out.writeParcelable(difficulty, 0); out.writeParcelable(gameBoard, 0); - out.writeParcelable(undoRedoManager, 0); + //out.writeParcelable(undoRedoManager, 0); out.writeTypedList(errorList); } @@ -809,7 +809,7 @@ public class GameController implements IModelChangedListener, Parcelable { gameType = in.readParcelable(GameType.class.getClassLoader()); difficulty = in.readParcelable(GameDifficulty.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); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GeneratorService.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GeneratorService.java index 8fb7363..32f78df 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GeneratorService.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GeneratorService.java @@ -6,6 +6,7 @@ import android.app.Service; import android.content.Intent; import android.os.Handler; import android.os.IBinder; +import android.os.Looper; import android.support.annotation.IntDef; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; @@ -26,6 +27,7 @@ import org.secuso.privacyfriendlysudoku.ui.MainActivity; import org.secuso.privacyfriendlysudoku.ui.view.R; import java.util.Date; +import java.util.IllegalFormatCodePointException; import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -50,12 +52,16 @@ public class GeneratorService extends IntentService { private final List> generationList = new LinkedList<>(); private final DatabaseHelper dbHelper = new DatabaseHelper(this); + //private Handler mHandler = new Handler(); public GeneratorService() { super("Generator Service"); } + public GeneratorService(String name) { super(name); } + + private void buildGenerationList() { generationList.clear(); @@ -80,14 +86,21 @@ public class GeneratorService extends IntentService { private void handleGenerationStop() { stopForeground(true); - stopSelf(); + //mHandler.removeCallbacksAndMessages(null); } private void handleGenerationStart(Intent intent) { - GameType gameType = intent.getParcelableExtra(EXTRA_GAMETYPE); - GameDifficulty gameDifficulty = intent.getParcelableExtra(EXTRA_DIFFICULTY); + GameType gameType; + 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(); } else { generateLevel(gameType, gameDifficulty); @@ -253,13 +266,6 @@ public class GeneratorService extends IntentService { builder.setSmallIcon(R.drawable.splash_icon); startForeground(50, builder.build()); } - - @Nullable - @Override - public IBinder onBind(Intent intent) { - return null; - } - @Override protected void onHandleIntent(@Nullable Intent intent) { if (intent != null) { diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index 4c8e125..e0f9a17 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -96,11 +96,8 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig Bundle extras = getIntent().getExtras(); if (extras != null) { - Object o = extras.get("gameType"); - if (o instanceof GameType) { - gameType = (GameType) extras.get("gameType"); - } - gameDifficulty = (GameDifficulty) (extras.get("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"); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java index 7bbc155..14dd28e 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java @@ -215,8 +215,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig // send everything to game activity i = new Intent(this, GameActivity.class); - i.putExtra("gameType", (Serializable)gameType); - i.putExtra("gameDifficulty", (Serializable)gameDifficulty); + i.putExtra("gameType", gameType.name()); + i.putExtra("gameDifficulty", gameDifficulty.name()); } else { newLevelManager.checkAndRestock(); Toast t = Toast.makeText(getApplicationContext(), R.string.generating, Toast.LENGTH_SHORT);