From 6e96ee890455ee8985586c4842629953bee48718 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Wed, 3 Feb 2016 20:14:13 +0100 Subject: [PATCH] ErrorList is now updated when the field is updated. --- .../controller/GameController.java | 18 +++++++++++++----- .../game/CellConflict.java | 2 ++ .../privacyfriendlysudoku/ui/GameActivity.java | 13 ++++++++----- 3 files changed, 23 insertions(+), 10 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 34b3d00..716bd1a 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java @@ -14,7 +14,6 @@ import org.secuso.privacyfriendlysudoku.game.GameCell; import org.secuso.privacyfriendlysudoku.game.GameDifficulty; import org.secuso.privacyfriendlysudoku.game.GameType; import org.secuso.privacyfriendlysudoku.game.ICellAction; -import org.secuso.privacyfriendlysudoku.game.listener.IGameErrorListener; import org.secuso.privacyfriendlysudoku.game.listener.IGameSolvedListener; import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener; import org.secuso.privacyfriendlysudoku.game.listener.IHintListener; @@ -45,7 +44,6 @@ public class GameController implements IModelChangedListener, Parcelable { private LinkedList highlightListeners = new LinkedList<>(); private LinkedList solvedListeners = new LinkedList<>(); private LinkedList hintListener = new LinkedList<>(); - private LinkedList errorListeners = new LinkedList<>(); private boolean notifiedOnSolvedListeners = false; // Game @@ -207,7 +205,6 @@ public class GameController implements IModelChangedListener, Parcelable { public void setValue(int row, int col, int value) { GameCell cell = gameBoard.getCell(row, col); if (!cell.isFixed() && isValidNumber(value)) { - cell.deleteNotes(); cell.setValue(value); if(settings != null && settings.getBoolean("pref_automatic_note_deletion",true)) { @@ -323,7 +320,6 @@ public class GameController implements IModelChangedListener, Parcelable { if(!c.isFixed()) { c.setValue(0); //notifyListeners(); - return true; } return false; @@ -507,6 +503,9 @@ public class GameController implements IModelChangedListener, Parcelable { @Override public void onModelChange(GameCell c) { + + checkErrorList(); + if(gameBoard.isFilled()) { errorList = new CellConflictList(); if(gameBoard.isSolved(errorList)) { @@ -525,6 +524,16 @@ public class GameController implements IModelChangedListener, Parcelable { } } + public void checkErrorList() { + LinkedList toRemove = new LinkedList<>(); + for(CellConflict cc : errorList) { + if(cc.getCell1().getValue() != cc.getCell2().getValue()) { + toRemove.add(cc); + } + } + errorList.removeAll(toRemove); + } + public void resetSelects() { selectedCol = -1; selectedRow = -1; @@ -774,7 +783,6 @@ public class GameController implements IModelChangedListener, Parcelable { solvedListeners = new LinkedList<>(); hintListener = new LinkedList<>(); timerListeners = new LinkedList<>(); - errorListeners = new LinkedList<>(); } public void setContextAndSettings(Context applicationContext, SharedPreferences sharedPref) { diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/CellConflict.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/CellConflict.java index a7cb3cc..554dd55 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/CellConflict.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/CellConflict.java @@ -27,6 +27,8 @@ public class CellConflict implements Parcelable { return c2.getCol(); } + public GameCell getCell1() { return c1; } + public GameCell getCell2() { return c2; } public CellConflict(GameCell first, GameCell second) { c1 = first; 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 f34f6de..b1bf555 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -28,11 +28,8 @@ import android.widget.LinearLayout; import android.widget.RatingBar; import android.widget.TextView; -import java.util.LinkedList; -import java.util.List; - -import org.secuso.privacyfriendlysudoku.controller.GameStateManager; import org.secuso.privacyfriendlysudoku.controller.GameController; +import org.secuso.privacyfriendlysudoku.controller.GameStateManager; import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics; import org.secuso.privacyfriendlysudoku.controller.Symbol; import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer; @@ -42,11 +39,14 @@ import org.secuso.privacyfriendlysudoku.game.listener.IGameSolvedListener; import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener; import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener; import org.secuso.privacyfriendlysudoku.ui.listener.IResetDialogFragmentListener; -import org.secuso.privacyfriendlysudoku.ui.view.WinDialog; import org.secuso.privacyfriendlysudoku.ui.view.R; import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout; import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout; import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout; +import org.secuso.privacyfriendlysudoku.ui.view.WinDialog; + +import java.util.LinkedList; +import java.util.List; public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, IGameSolvedListener ,ITimerListener, IHintDialogFragmentListener, IResetDialogFragmentListener { @@ -184,6 +184,9 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On gameController.notifyHighlightChangedListeners(); gameController.notifyTimerListener(gameController.getTime()); + // run this so the error list gets build again. + gameController.onModelChange(null); + } @Override