use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.
the class MainActivity method selectAll.
private void selectAll() {
for (SavedGameAdapter subAdapter : adapter.getSectionsMap().values()) {
for (int i = 0; i < subAdapter.getCount(); i++) {
GameSummary game = subAdapter.getItem(i);
subAdapter.getChecked().add(game);
}
}
adapter.notifyDataSetChanged();
}
use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.
the class MainActivity method onResume.
@Override
public void onResume() {
super.onResume();
log.d("onResume()");
List<GameSummary> games = getAllGames();
Collections.sort(games, GameSummary.byRecentlySaved());
log.d("loaded games %s", games);
SortedMap<TimePeriod, List<GameSummary>> organizedGames = organizeGamesByTimePeriod(games);
adapter = new SeparatedListAdapter<SavedGameAdapter>(this);
for (Entry<TimePeriod, List<GameSummary>> entry : organizedGames.entrySet()) {
TimePeriod timePeriod = entry.getKey();
List<GameSummary> gamesSection = entry.getValue();
SavedGameAdapter subAdapter = new SavedGameAdapter(this, gamesSection);
if (lastChecked != null) {
// reload the checked items from when the user last quit
subAdapter.setChecked(lastChecked);
}
subAdapter.setOnCheckChangedRunnable(new Runnable() {
@Override
public void run() {
showOrHideButtonRow();
}
});
adapter.addSection(getString(timePeriod.getTitleResId()), subAdapter);
}
setListAdapter(adapter);
if (lastPosition != null) {
// scroll to the user's last position when they quit
getListView().setSelection(lastPosition);
}
lastPosition = null;
lastChecked = null;
}
use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.
the class MainActivity method onListItemClick.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
GameSummary game = (GameSummary) adapter.getItem(position);
GameActivityHelper.openGame(this, game);
}
use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.
the class MainActivity method onNewGameCreated.
private void onNewGameCreated(Game newGame) {
GameSummary newGameSummary = GameSummary.fromGame(newGame);
// if the appropriate section doesn't exist, need to create it
TimePeriod timePeriodForThisGame = getTimePeriod(new Date(), newGameSummary);
String sectionForThisGame = getString(timePeriodForThisGame.getTitleResId());
if (adapter.getCount() == 0 || !adapter.getSectionsMap().keySet().contains(sectionForThisGame)) {
SavedGameAdapter subAdapter = new SavedGameAdapter(MainActivity.this, new ArrayList<GameSummary>(Collections.singleton(newGameSummary)));
subAdapter.setOnCheckChangedRunnable(new Runnable() {
@Override
public void run() {
showOrHideButtonRow();
}
});
Map<String, Integer> sectionsToOrder = new HashMap<String, Integer>();
for (TimePeriod timePeriod : TimePeriod.values()) {
sectionsToOrder.put(getString(timePeriod.getTitleResId()), timePeriod.ordinal());
}
int index = 0;
for (int i = 0; i < adapter.getSectionHeaders().getCount(); i++) {
String section = adapter.getSectionHeaders().getItem(i);
if (sectionsToOrder.get(sectionForThisGame) < sectionsToOrder.get(section)) {
break;
}
index++;
}
adapter.insertSection(sectionForThisGame, index, subAdapter);
} else {
// just insert it into the proper section
SavedGameAdapter subAdapter = adapter.getSectionsMap().get(sectionForThisGame);
subAdapter.add(newGameSummary);
subAdapter.sort(GameSummary.byRecentlySaved());
}
adapter.notifyDataSetChanged();
adapter.refreshSections();
fastScrollView.listItemsChanged();
}
use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.
the class SavedGameAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
// view wrapper optimization per Romain Guy
final Context context = parent.getContext();
ViewWrapper viewWrapper;
if (view == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.saved_game_item, parent, false);
viewWrapper = new ViewWrapper(view);
view.setTag(viewWrapper);
} else {
viewWrapper = (ViewWrapper) view.getTag();
}
TextView titleTextView = viewWrapper.getTitleTextView();
TextView numPlayersTextView = viewWrapper.getNumPlayersTextView();
TextView subtitleTextView = viewWrapper.getSubtitleTextView();
TextView savedTextView = viewWrapper.getSavedTextView();
CheckBox checkBox = viewWrapper.getCheckBox();
final GameSummary game = getItem(position);
StringBuilder gameTitle = new StringBuilder();
if (!TextUtils.isEmpty(game.getName())) {
gameTitle.append(game.getName()).append(" ").append(context.getString(R.string.text_game_name_separator)).append(" ");
}
// Player 1, Player 2, Player3 etc.
gameTitle.append(TextUtils.join(", ", CollectionUtil.transformWithIndices(game.getPlayerNames(), new FunctionWithIndex<String, CharSequence>() {
@Override
public CharSequence apply(String playerName, int index) {
return PlayerScore.toDisplayName(playerName, index, context);
}
})));
titleTextView.setText(gameTitle);
numPlayersTextView.setText(Integer.toString(game.getPlayerNames().size()));
numPlayersTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimensionPixelSize(// two
game.getPlayerNames().size() >= 10 ? // digit
R.dimen.saved_game_num_players_text_size_two_digits : R.dimen.saved_game_num_players_text_size_one_digit));
int numRounds = game.getNumRounds();
int roundsResId = numRounds == 1 ? R.string.text_format_rounds_singular : R.string.text_format_rounds;
String rounds = String.format(context.getString(roundsResId), numRounds);
subtitleTextView.setText(rounds);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(getContext().getString(R.string.date_format), Locale.getDefault());
savedTextView.setText(simpleDateFormat.format(new Date(game.getDateSaved())));
checkBox.setOnCheckedChangeListener(null);
checkBox.setChecked(checked.contains(game));
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
checked.add(game);
} else {
checked.remove(game);
}
if (onCheckChangedRunnable != null) {
onCheckChangedRunnable.run();
}
}
});
log.d("saved long is: %s", game.getDateSaved());
return view;
}
Aggregations