use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class HistoryRoundTableFragment method getCollatedHistoryItems.
private List<HistoryItem> getCollatedHistoryItems(Activity activity) {
// get all the iterators for the history items
List<Iterator<HistoryItem>> playerHistoryItems = new ArrayList<Iterator<HistoryItem>>();
for (PlayerScore playerScore : game.getPlayerScores()) {
List<HistoryItem> historyItems = HistoryItem.createFromPlayerScore(playerScore, activity);
playerHistoryItems.add(historyItems.iterator());
}
List<HistoryItem> collatedItems = new ArrayList<HistoryItem>();
// collate
while (!allIteratorsAreEmpty(playerHistoryItems)) {
for (Iterator<HistoryItem> iterator : playerHistoryItems) {
if (iterator.hasNext()) {
collatedItems.add(iterator.next());
} else {
// add an empty item
collatedItems.add(null);
}
}
}
return collatedItems;
}
use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class GameActivity method setUpWidgets.
private void setUpWidgets() {
rootLayout = (LinearLayout) findViewById(R.id.game_root_layout);
// add top and bottom spacing on the two-player game. it looks nicer
rootPadding1 = findViewById(R.id.game_root_padding_1);
rootPadding2 = findViewById(R.id.game_root_padding_2);
rootPadding1.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
rootPadding2.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
// if the round totals are enabled
try {
roundTotalViewStub = (ViewStub) findViewById(R.id.round_totals);
int versionInt = VersionHelper.getVersionSdkIntCompat();
if (versionInt > VersionHelper.VERSION_DONUT && versionInt < VersionHelper.VERSION_FROYO) {
roundTotalTextView = (TextView) roundTotalViewStub.inflate();
}
} catch (ClassCastException ignore) {
// view stub already inflated
}
playerViews = new ArrayList<PlayerView>();
boolean showOnscreenDeltaButtons = getShouldShowOnscreenDeltaButtons();
for (int i = 0; i < playerScores.size(); i++) {
PlayerScore playerScore = playerScores.get(i);
int resId = getPlayerViewResId(i);
View view = getPlayerScoreView(resId);
if (view == null) {
log.e("Null pointer exception; view for player %s is null", i);
}
PlayerView playerView = new PlayerView(this, view, playerScore, handler, showOnscreenDeltaButtons);
playerView.setChangeRecorder(new Callback<RecordedChange>() {
@Override
public void onCallback(RecordedChange recordedChange) {
undoStack.pop(recordedChange);
redoStack.clear();
}
});
playerView.setOnChangeListener(new Runnable() {
@Override
public void run() {
updateRoundTotalViewText();
updateHighlightedPlayer();
}
});
// worth saving. This only applies for newly created games.
if (game.getId() == -1 && !TextUtils.isEmpty(playerScore.getName())) {
playerView.getShouldAutosave().set(true);
}
playerViews.add(playerView);
}
hideAbsentPlayers();
}
use of com.nolanlawson.keepscore.db.PlayerScore 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.PlayerScore in project KeepScore by nolanlawson.
the class EditablePlayerAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.editable_player, parent, false);
}
final PlayerScore playerScore = getItem(position);
TextView nameTextView = (TextView) view.findViewById(R.id.text_player_name);
TextView numberTextView = (TextView) view.findViewById(R.id.text_player_number);
TextView scoreTextView = (TextView) view.findViewById(R.id.text_player_score);
PlayerColorView playerColorView = (PlayerColorView) view.findViewById(R.id.player_color_image);
playerColorView.setVisibility(PreferenceHelper.getShowColors(getContext()) ? View.VISIBLE : View.GONE);
nameTextView.setText(playerScore.toDisplayName(getContext()));
numberTextView.setText('#' + Integer.toString(playerScore.getPlayerNumber() + 1));
scoreTextView.setText(Long.toString(playerScore.getScore()));
playerColorView.setPlayerColor(playerScore.getPlayerColor());
// listen for player color clicks
playerColorView.setOnClickListener(new OnClickListener() {
private PlayerColor chosenColor;
@Override
public void onClick(View v) {
DialogHelper.showColorChooserDialog(getContext(), playerScore.getPlayerColor(), new Callback<PlayerColor>() {
@Override
public void onCallback(PlayerColor playerColor) {
// color changed
chosenColor = playerColor;
}
}, new Runnable() {
@Override
public void run() {
// color selected
if (chosenColor == null) {
return;
}
playerScore.setPlayerColor(chosenColor);
notifyDataSetChanged();
}
});
}
});
// add listener to the delete button
ImageButton deleteButton = (ImageButton) view.findViewById(R.id.button_delete_player);
deleteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// delete
remove(playerScore);
resetPlayerNumbers();
notifyDataSetChanged();
if (onDeleteListener != null) {
onDeleteListener.onCallback(playerScore);
}
}
});
// user is not allowed to delete the final 2 users
deleteButton.setEnabled(getCount() > OrganizePlayersActivity.MIN_NUM_PLAYERS);
ImageButton editButton = (ImageButton) view.findViewById(R.id.button_edit_player);
editButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// edit
DialogHelper.showPlayerNameDialog(getContext(), R.string.title_change_name, playerScore.getName(), playerScore.getPlayerNumber(), new Callback<String>() {
@Override
public void onCallback(String input) {
playerScore.setName(input);
notifyDataSetChanged();
}
});
}
});
view.setVisibility(currentlyDragging == view ? View.INVISIBLE : View.VISIBLE);
return view;
}
use of com.nolanlawson.keepscore.db.PlayerScore in project KeepScore by nolanlawson.
the class EditablePlayerAdapter method drop.
@Override
public void drop(int from, int to) {
PlayerScore temp = items.get(from);
items.remove(from);
items.add(to, temp);
resetPlayerNumbers();
notifyDataSetChanged();
}
Aggregations