Fixed the Delete Button. It would not delete notes.
This commit is contained in:
parent
a4e7a693f9
commit
229f167c2e
3 changed files with 24 additions and 21 deletions
|
@ -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() {
|
||||
|
|
|
@ -20,7 +20,6 @@ public class GameBoard implements Cloneable, Parcelable {
|
|||
//private List additionalSections
|
||||
private int size;
|
||||
private GameCell[][] field;
|
||||
private List<IModelChangedListener> 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<Boolean>() {
|
||||
@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<Boolean>() {
|
||||
|
||||
@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<Boolean>() {
|
||||
@Override
|
||||
public Boolean action(GameCell gc, Boolean existing) {
|
||||
gc.removeAllListeners();
|
||||
return existing;
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue