-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Minsky/mvvm
Added handling of activity recreation. For instance on screen rotation
- Loading branch information
Showing
7 changed files
with
165 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
package com.acme.tictactoe.model; | ||
|
||
public enum Player { X , O } | ||
import android.util.SparseArray; | ||
|
||
public enum Player { | ||
X(0), | ||
O(1), | ||
NO(2); | ||
|
||
int id; | ||
|
||
Player(int id) | ||
{ | ||
this.id = id; | ||
} | ||
|
||
static SparseArray<Player> cache; | ||
|
||
static Player fromInt(int id) { | ||
if (cache == null) { | ||
cache = new SparseArray<>(); | ||
Player[] players = Player.values(); | ||
for (Player value : players) { | ||
cache.put(value.id, value); | ||
} | ||
} | ||
return cache.get(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/acme/tictactoe/viewmodel/ViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
package com.acme.tictactoe.viewmodel; | ||
|
||
import android.os.Bundle; | ||
|
||
public interface ViewModel { | ||
|
||
void onCreate(); | ||
void onPause(); | ||
void onResume(); | ||
|
||
void onSaveInstanceState(Bundle bundle); | ||
|
||
void loadFromSavedInstanceState(Bundle bundle); | ||
|
||
void onDestroy(); | ||
|
||
} |