From 229f167c2e2ff2987165527da4d4705b4a579c82 Mon Sep 17 00:00:00 2001 From: Christopher Beckmann Date: Sun, 31 Jan 2016 14:10:33 +0100 Subject: [PATCH] Fixed the Delete Button. It would not delete notes. --- .../controller/GameController.java | 7 +++-- .../privacyfriendlysudoku/game/GameBoard.java | 28 ++++++------------- .../privacyfriendlysudoku/game/GameCell.java | 10 +++++++ 3 files changed, 24 insertions(+), 21 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 8ffc158..8e60fb7 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/GameController.java @@ -160,7 +160,7 @@ public class GameController implements IModelChangedListener, Parcelable { public int[] solve() { - if(solution == null) { + if(solution == null || solution.length == 0) { solution = qqWingController.solve(gameBoard); } return solution; @@ -469,7 +469,7 @@ public class GameController implements IModelChangedListener, Parcelable { } public void deleteSelectedCellsValue() { - if(isValidCellSelected() && getSelectedCellsValue() != 0) { + if(isValidCellSelected()) { deleteValue(selectedRow, selectedCol); // add state to undo undoRedoManager.addState(gameBoard); @@ -751,6 +751,9 @@ public class GameController implements IModelChangedListener, Parcelable { undoRedoManager = in.readParcelable(UndoRedoManager.class.getClassLoader()); removeAllListeners(); + + gameBoard.removeAllListeners(); + gameBoard.registerOnModelChangeListener(this); } public void removeAllListeners() { diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameBoard.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameBoard.java index febef69..defb466 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameBoard.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameBoard.java @@ -20,7 +20,6 @@ public class GameBoard implements Cloneable, Parcelable { //private List additionalSections private int size; private GameCell[][] field; - private List modelChangedListeners = new LinkedList<>(); public GameBoard(GameType gameType) { this.gameType = gameType; @@ -223,7 +222,6 @@ public class GameBoard implements Cloneable, Parcelable { } public void registerOnModelChangeListener(final IModelChangedListener listener) { - if(!modelChangedListeners.contains(listener)) { actionOnCells(new ICellAction() { @Override public Boolean action(GameCell gc, Boolean existing) { @@ -231,22 +229,6 @@ public class GameBoard implements Cloneable, Parcelable { return existing; } }, false); - modelChangedListeners.add(listener); - } - } - - public void deleteOnModelChangeListener(final IModelChangedListener listener) { - if(modelChangedListeners.contains(listener)) { - actionOnCells(new ICellAction() { - - @Override - public Boolean action(GameCell gc, Boolean existing) { - gc.removeOnModelChangeListener(listener); - return existing; - } - }, false); - modelChangedListeners.remove(listener); - } } @Override @@ -318,7 +300,15 @@ public class GameBoard implements Cloneable, Parcelable { for(int i = 0; i < field.length; i++) { field[i] = in.createTypedArray(GameCell.CREATOR); } + } - modelChangedListeners = new LinkedList<>(); + public void removeAllListeners() { + actionOnCells(new ICellAction() { + @Override + public Boolean action(GameCell gc, Boolean existing) { + gc.removeAllListeners(); + return existing; + } + }, false); } } diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameCell.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameCell.java index 928d72d..62dbcc4 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameCell.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/game/GameCell.java @@ -2,10 +2,14 @@ package org.secuso.privacyfriendlysudoku.game; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.NonNull; import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.ListIterator; import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener; @@ -240,5 +244,11 @@ public class GameCell implements Cloneable, Parcelable { noteCount = in.readInt(); notes = new boolean[size]; in.readBooleanArray(notes); + + removeAllListeners(); + } + + public void removeAllListeners() { + modelChangedListeners = new LinkedList<>(); } }