Corrected Parceable Implementation. Wasn't aware that my code was not called. Had to force it to clear the app out of the memory.
This commit is contained in:
parent
54bf935685
commit
a4e7a693f9
5 changed files with 20 additions and 14 deletions
|
@ -54,7 +54,7 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
private int sectionWidth;
|
||||
private int usedHints = 0;
|
||||
private GameBoard gameBoard;
|
||||
private int[] solution;
|
||||
private int[] solution = new int[0];
|
||||
private GameType gameType;
|
||||
private GameDifficulty difficulty;
|
||||
private CellConflictList errorList = new CellConflictList();
|
||||
|
@ -699,6 +699,7 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
out.writeInt(usedHints);
|
||||
out.writeInt(time);
|
||||
|
||||
out.writeInt(solution.length);
|
||||
out.writeIntArray(solution);
|
||||
|
||||
out.writeInt(noteStatus ? 1 : 0);
|
||||
|
@ -738,18 +739,18 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
usedHints = in.readInt();
|
||||
time = in.readInt();
|
||||
|
||||
solution = new int[in.readInt()];
|
||||
in.readIntArray(solution);
|
||||
|
||||
noteStatus = in.readInt() == 1;
|
||||
notifiedOnSolvedListeners = in.readInt() == 1;
|
||||
|
||||
gameType = in.readParcelable(null);
|
||||
difficulty = in.readParcelable(null);
|
||||
gameBoard = in.readParcelable(null);
|
||||
undoRedoManager = in.readParcelable(null);
|
||||
gameType = in.readParcelable(GameType.class.getClassLoader());
|
||||
difficulty = in.readParcelable(GameDifficulty.class.getClassLoader());
|
||||
gameBoard = in.readParcelable(GameBoard.class.getClassLoader());
|
||||
undoRedoManager = in.readParcelable(UndoRedoManager.class.getClassLoader());
|
||||
|
||||
removeAllListeners();
|
||||
|
||||
}
|
||||
|
||||
public void removeAllListeners() {
|
||||
|
@ -758,4 +759,9 @@ public class GameController implements IModelChangedListener, Parcelable {
|
|||
hintListener = new LinkedList<>();
|
||||
timerListeners = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void setContextAndSettings(Context applicationContext, SharedPreferences sharedPref) {
|
||||
context = applicationContext;
|
||||
setSettings(sharedPref);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -290,7 +290,7 @@ public class GameBoard implements Cloneable, Parcelable {
|
|||
dest.writeInt(size);
|
||||
|
||||
for(int i = 0; i < field.length; i++) {
|
||||
dest.writeParcelableArray(field[i], 0);
|
||||
dest.writeTypedArray(field[i], 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public class GameBoard implements Cloneable, Parcelable {
|
|||
/** recreate object from parcel */
|
||||
private GameBoard(Parcel in) {
|
||||
//private int id;
|
||||
gameType = in.readParcelable(null);
|
||||
gameType = in.readParcelable(GameType.class.getClassLoader());
|
||||
sectionHeight = in.readInt();
|
||||
sectionWidth = in.readInt();
|
||||
size = in.readInt();
|
||||
|
@ -316,8 +316,7 @@ public class GameBoard implements Cloneable, Parcelable {
|
|||
field = new GameCell[size][size];
|
||||
|
||||
for(int i = 0; i < field.length; i++) {
|
||||
// TODO: does this work?!
|
||||
field[i] = (GameCell[]) in.readParcelableArray(null);
|
||||
field[i] = in.createTypedArray(GameCell.CREATOR);
|
||||
}
|
||||
|
||||
modelChangedListeners = new LinkedList<>();
|
||||
|
|
|
@ -213,10 +213,10 @@ public class GameCell implements Cloneable, Parcelable {
|
|||
dest.writeInt(row);
|
||||
dest.writeInt(col);
|
||||
dest.writeInt(value);
|
||||
dest.writeInt(size);
|
||||
dest.writeInt(fixed ? 1 : 0);
|
||||
dest.writeInt(noteCount);
|
||||
dest.writeBooleanArray(notes);
|
||||
dest.writeInt(size);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GameCell> CREATOR
|
||||
|
@ -235,9 +235,10 @@ public class GameCell implements Cloneable, Parcelable {
|
|||
row = in.readInt();
|
||||
col = in.readInt();
|
||||
value = in.readInt();
|
||||
size = in.readInt();
|
||||
fixed = in.readInt() == 1;
|
||||
noteCount = in.readInt();
|
||||
notes = new boolean[size];
|
||||
in.readBooleanArray(notes);
|
||||
size = in.readInt();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,7 @@ public enum GameType implements Parcelable{
|
|||
dest.writeInt(resIDImage);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GameType> CREATOR
|
||||
= new Parcelable.Creator<GameType>() {
|
||||
public static final Parcelable.Creator<GameType> CREATOR = new Parcelable.Creator<GameType>() {
|
||||
public GameType createFromParcel(Parcel in) {
|
||||
GameType g = GameType.values()[in.readInt()];
|
||||
g.resIDString = in.readInt();
|
||||
|
|
|
@ -103,6 +103,7 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On
|
|||
// in case we get the same object back
|
||||
// because parceling the Object does not always parcel it. Only if needed.
|
||||
gameController.removeAllListeners();
|
||||
gameController.setContextAndSettings(getApplicationContext(), sharedPref);
|
||||
gameSolved = savedInstanceState.getInt("gameSolved") == 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue