de.palmmedia.yahtzee.data
Class DataRepository

java.lang.Object
  extended by de.palmmedia.yahtzee.data.DataRepository

public class DataRepository
extends Object

Repository encapsulating a SQLite database. Used to store player names and highscores.

Author:
Daniel Palme

Nested Class Summary
private static class DataRepository.DataOpenHelper
          SQLiteOpenHelper to create the database.
 
Field Summary
private  DataRepository.DataOpenHelper dataOpenHelper
          The DataRepository.DataOpenHelper.
private static String HIGHSCORES_COLUMN_NAME
          The name of the name column.
private static String HIGHSCORES_COLUMN_SCORE
          The name of the score column.
private static String HIGHSCORES_TABLE_NAME
          The name of the highscores table.
private static String PLAYER_COLUMN_ACTIVE
          The name of the active column.
private static String PLAYER_COLUMN_NAME
          The name of the name column.
private static String PLAYER_TABLE_NAME
          The name of the players table.
 
Constructor Summary
DataRepository(Context context)
          Constructor.
 
Method Summary
 void addHighscores(List<Result> highscores)
          Saves the highscores.
 List<Result> getHighscores()
          Get the highscores.
 List<Player> getPlayers()
          Get the saved players.
 void savePlayers(List<Player> players)
          Save the players.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLAYER_TABLE_NAME

private static final String PLAYER_TABLE_NAME
The name of the players table.

See Also:
Constant Field Values

PLAYER_COLUMN_NAME

private static final String PLAYER_COLUMN_NAME
The name of the name column.

See Also:
Constant Field Values

PLAYER_COLUMN_ACTIVE

private static final String PLAYER_COLUMN_ACTIVE
The name of the active column.

See Also:
Constant Field Values

HIGHSCORES_TABLE_NAME

private static final String HIGHSCORES_TABLE_NAME
The name of the highscores table.

See Also:
Constant Field Values

HIGHSCORES_COLUMN_NAME

private static final String HIGHSCORES_COLUMN_NAME
The name of the name column.

See Also:
Constant Field Values

HIGHSCORES_COLUMN_SCORE

private static final String HIGHSCORES_COLUMN_SCORE
The name of the score column.

See Also:
Constant Field Values

dataOpenHelper

private DataRepository.DataOpenHelper dataOpenHelper
The DataRepository.DataOpenHelper.

Constructor Detail

DataRepository

public DataRepository(Context context)
Constructor.

Parameters:
context - The context.
Method Detail

getPlayers

public List<Player> getPlayers()
Get the saved players.

Returns:
The players.

savePlayers

public void savePlayers(List<Player> players)
Save the players. Existing players are deleted.

Parameters:
players - The players.

getHighscores

public List<Result> getHighscores()
Get the highscores.

Returns:
The highscores.

addHighscores

public void addHighscores(List<Result> highscores)
Saves the highscores. Deletes all highscores that are not in TOP 10 highscores.

Parameters:
highscores - The highscores.