use of com.nolanlawson.keepscore.data.SavedGameAdapter 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.data.SavedGameAdapter 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.data.SavedGameAdapter 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.data.SavedGameAdapter in project KeepScore by nolanlawson.
the class MainActivity method deselectAll.
private void deselectAll() {
for (SavedGameAdapter subAdapter : adapter.getSectionsMap().values()) {
subAdapter.getChecked().clear();
}
adapter.notifyDataSetChanged();
selectedMode = false;
hideButtonRow();
supportInvalidateOptionsMenu();
}
use of com.nolanlawson.keepscore.data.SavedGameAdapter in project KeepScore by nolanlawson.
the class MainActivity method onGameDeleted.
private void onGameDeleted(GameSummary game) {
for (Entry<String, SavedGameAdapter> entry : new HashMap<String, SavedGameAdapter>(adapter.getSectionsMap()).entrySet()) {
SavedGameAdapter subAdapter = (SavedGameAdapter) entry.getValue();
if (subAdapter.getCount() == 1 && subAdapter.getItem(0).equals(game)) {
// special case where there's only one item left - don't want
// the adapter to be left empty
// So delete the entire section
adapter.removeSection(entry.getKey());
} else {
subAdapter.remove(game);
}
// remove from the checked
subAdapter.getChecked().remove(game);
// list
}
adapter.notifyDataSetChanged();
adapter.refreshSections();
fastScrollView.listItemsChanged();
showOrHideButtonRow();
}
Aggregations