Fixed the Delete Button. It would not delete notes.

This commit is contained in:
Christopher Beckmann 2016-01-31 14:10:33 +01:00
parent a4e7a693f9
commit 229f167c2e
3 changed files with 24 additions and 21 deletions

View file

@ -160,7 +160,7 @@ public class GameController implements IModelChangedListener, Parcelable {
public int[] solve() { public int[] solve() {
if(solution == null) { if(solution == null || solution.length == 0) {
solution = qqWingController.solve(gameBoard); solution = qqWingController.solve(gameBoard);
} }
return solution; return solution;
@ -469,7 +469,7 @@ public class GameController implements IModelChangedListener, Parcelable {
} }
public void deleteSelectedCellsValue() { public void deleteSelectedCellsValue() {
if(isValidCellSelected() && getSelectedCellsValue() != 0) { if(isValidCellSelected()) {
deleteValue(selectedRow, selectedCol); deleteValue(selectedRow, selectedCol);
// add state to undo // add state to undo
undoRedoManager.addState(gameBoard); undoRedoManager.addState(gameBoard);
@ -751,6 +751,9 @@ public class GameController implements IModelChangedListener, Parcelable {
undoRedoManager = in.readParcelable(UndoRedoManager.class.getClassLoader()); undoRedoManager = in.readParcelable(UndoRedoManager.class.getClassLoader());
removeAllListeners(); removeAllListeners();
gameBoard.removeAllListeners();
gameBoard.registerOnModelChangeListener(this);
} }
public void removeAllListeners() { public void removeAllListeners() {

View file

@ -20,7 +20,6 @@ public class GameBoard implements Cloneable, Parcelable {
//private List additionalSections //private List additionalSections
private int size; private int size;
private GameCell[][] field; private GameCell[][] field;
private List<IModelChangedListener> modelChangedListeners = new LinkedList<>();
public GameBoard(GameType gameType) { public GameBoard(GameType gameType) {
this.gameType = gameType; this.gameType = gameType;
@ -223,7 +222,6 @@ public class GameBoard implements Cloneable, Parcelable {
} }
public void registerOnModelChangeListener(final IModelChangedListener listener) { public void registerOnModelChangeListener(final IModelChangedListener listener) {
if(!modelChangedListeners.contains(listener)) {
actionOnCells(new ICellAction<Boolean>() { actionOnCells(new ICellAction<Boolean>() {
@Override @Override
public Boolean action(GameCell gc, Boolean existing) { public Boolean action(GameCell gc, Boolean existing) {
@ -231,22 +229,6 @@ public class GameBoard implements Cloneable, Parcelable {
return existing; return existing;
} }
}, false); }, false);
modelChangedListeners.add(listener);
}
}
public void deleteOnModelChangeListener(final IModelChangedListener listener) {
if(modelChangedListeners.contains(listener)) {
actionOnCells(new ICellAction<Boolean>() {
@Override
public Boolean action(GameCell gc, Boolean existing) {
gc.removeOnModelChangeListener(listener);
return existing;
}
}, false);
modelChangedListeners.remove(listener);
}
} }
@Override @Override
@ -318,7 +300,15 @@ public class GameBoard implements Cloneable, Parcelable {
for(int i = 0; i < field.length; i++) { for(int i = 0; i < field.length; i++) {
field[i] = in.createTypedArray(GameCell.CREATOR); field[i] = in.createTypedArray(GameCell.CREATOR);
} }
}
modelChangedListeners = new LinkedList<>(); public void removeAllListeners() {
actionOnCells(new ICellAction<Boolean>() {
@Override
public Boolean action(GameCell gc, Boolean existing) {
gc.removeAllListeners();
return existing;
}
}, false);
} }
} }

View file

@ -2,10 +2,14 @@ package org.secuso.privacyfriendlysudoku.game;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator;
import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener; import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener;
@ -240,5 +244,11 @@ public class GameCell implements Cloneable, Parcelable {
noteCount = in.readInt(); noteCount = in.readInt();
notes = new boolean[size]; notes = new boolean[size];
in.readBooleanArray(notes); in.readBooleanArray(notes);
removeAllListeners();
}
public void removeAllListeners() {
modelChangedListeners = new LinkedList<>();
} }
} }