use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.
the class PlayerView method addZero.
private void addZero() {
// with no points for a particular player
synchronized (lock) {
Delta delta = new Delta(System.currentTimeMillis(), 0);
changeRecorder.onCallback(new RecordedChange(playerScore.getPlayerNumber(), Type.AddNew, delta));
playerScore.getHistory().add(delta);
}
// reset last incremented
lastIncremented.set(0);
shouldAutosave.set(true);
updateViews();
}
use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.
the class MainActivity method copyGame.
private void copyGame(Game game, final boolean resetScores) {
final Game newGame = game.makeCleanCopy();
if (resetScores) {
for (PlayerScore playerScore : newGame.getPlayerScores()) {
playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
playerScore.setHistory(new ArrayList<Delta>());
}
}
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
GameDBHelper dbHelper = null;
try {
dbHelper = new GameDBHelper(MainActivity.this);
dbHelper.saveGame(newGame);
} finally {
if (dbHelper != null) {
dbHelper.close();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
onNewGameCreated(newGame);
ToastHelper.showShort(MainActivity.this, resetScores ? R.string.toast_rematch_created : R.string.toast_game_copied);
}
}.execute((Void) null);
}
use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.
the class HistoryItem method createFromPlayerScore.
/**
* Create a list of displayable history items given a PlayerScore. Entries should be listed from past to future.
* @param playerScore
* @return
*/
public static List<HistoryItem> createFromPlayerScore(PlayerScore playerScore, Context context) {
List<Delta> history = playerScore.getHistory();
long runningScore = getStartingScore(playerScore);
List<HistoryItem> historyItems = new ArrayList<HistoryItem>();
// add an initial one to just show the starting score
historyItems.add(new HistoryItem(0, runningScore, true));
for (Delta historyDelta : history) {
runningScore += historyDelta.getValue();
historyItems.add(new HistoryItem(historyDelta.getValue(), runningScore, false));
}
return historyItems;
}
use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.
the class OrganizePlayersActivity method addNewPlayer.
private void addNewPlayer(CharSequence name) {
PlayerScore playerScore = new PlayerScore();
playerScore.setId(-1);
playerScore.setName(StringUtil.nullToEmpty(name));
playerScore.setPlayerNumber(adapter.getCount());
playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
playerScore.setHistory(new ArrayList<Delta>());
playerScore.setPlayerColor(PlayerColor.BUILT_INS[playerScore.getPlayerNumber() % PlayerColor.BUILT_INS.length]);
adapter.add(playerScore);
adapter.notifyDataSetChanged();
}
use of com.nolanlawson.keepscore.db.Delta in project KeepScore by nolanlawson.
the class PlayerView method updateViews.
public void updateViews() {
log.d("updateViews()");
long currentTime = System.currentTimeMillis();
if (borderDrawable == null) {
borderDrawable = context.getResources().getDrawable(borderDrawableResId);
}
view.setBackgroundDrawable(borderDrawable);
CharSequence playerName = playerScore.toDisplayName(context);
nameTextView.setText(playerName);
playerColorView.setPlayerColor(playerScore.getPlayerColor());
playerColorView.setVisibility(PreferenceHelper.getShowColors(context) ? View.VISIBLE : View.GONE);
scoreTextView.setText(Long.toString(playerScore.getScore()));
scoreTextView.resizeText();
if (currentTime < (lastIncremented.get() + getUpdateDelayInMs()) && !playerScore.getHistory().isEmpty()) {
log.d("showing badge");
// still
// modifiable
// show badge (blibbet)
makeBadgeVisible();
Delta lastDelta = playerScore.getHistory().get(playerScore.getHistory().size() - 1);
badgeTextView.setText(IntegerUtil.toCharSequenceWithSign(lastDelta.getValue()));
badgeLinearLayout.setBackgroundResource(lastDelta.getValue() >= 0 ? getPositiveBadge() : R.drawable.badge_red_fade_out);
// update history text view now rather than later
setHistoryTextLazily(playerScore.getHistory(), currentTime);
} else {
log.d("hiding badge");
// hide badge (blibbet)
// update history text view later
final Spannable newText = fromHistory(playerScore.getHistory(), currentTime);
final Integer newHash = historyHash(playerScore.getHistory(), currentTime);
Runnable updateHistoryRunnable = new Runnable() {
@Override
public void run() {
historyTextView.setText(newText);
historyTextView.setTag(newHash);
}
};
fadeOutBadge(updateHistoryRunnable);
}
// set values for delta buttons
if (this.showOnscreenDeltaButtons) {
for (int i = 0; i < deltaButtons.length; i++) {
Button button = deltaButtons[i];
button.setText(IntegerUtil.toCharSequenceWithSign(PreferenceHelper.getTwoPlayerDeltaButtonValue(i, context)));
}
}
}
Aggregations