Search in sources :

Example 1 with SavedGameAdapter

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();
}
Also used : SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter) GameSummary(com.nolanlawson.keepscore.db.GameSummary)

Example 2 with SavedGameAdapter

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;
}
Also used : TimePeriod(com.nolanlawson.keepscore.data.TimePeriod) SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter) List(java.util.List) ArrayList(java.util.ArrayList) GameSummary(com.nolanlawson.keepscore.db.GameSummary)

Example 3 with SavedGameAdapter

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();
}
Also used : HashMap(java.util.HashMap) TimePeriod(com.nolanlawson.keepscore.data.TimePeriod) SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter) GameSummary(com.nolanlawson.keepscore.db.GameSummary) Date(java.util.Date)

Example 4 with SavedGameAdapter

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();
}
Also used : SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter)

Example 5 with SavedGameAdapter

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();
}
Also used : SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter)

Aggregations

SavedGameAdapter (com.nolanlawson.keepscore.data.SavedGameAdapter)7 GameSummary (com.nolanlawson.keepscore.db.GameSummary)5 TimePeriod (com.nolanlawson.keepscore.data.TimePeriod)2 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.view.View.OnClickListener)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1