Search in sources :

Example 6 with GameSummary

use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.

the class MainActivity method onPause.

@Override
public void onPause() {
    super.onPause();
    log.d("onPause()");
    // save which items were checked and where we are in the list
    lastChecked = new HashSet<GameSummary>();
    for (SavedGameAdapter subAdapter : adapter.getSubAdapters()) {
        lastChecked.addAll(subAdapter.getChecked());
    }
    lastPosition = getListView().getFirstVisiblePosition();
}
Also used : SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter) GameSummary(com.nolanlawson.keepscore.db.GameSummary)

Example 7 with GameSummary

use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.

the class MainActivity method organizeGamesByTimePeriod.

private SortedMap<TimePeriod, List<GameSummary>> organizeGamesByTimePeriod(List<GameSummary> games) {
    SortedMap<TimePeriod, List<GameSummary>> result = new TreeMap<TimePeriod, List<GameSummary>>();
    Iterator<TimePeriod> timePeriodIterator = Arrays.asList(TimePeriod.values()).iterator();
    TimePeriod timePeriod = timePeriodIterator.next();
    Date date = new Date();
    for (GameSummary game : games) {
        // them in order
        while (!timePeriodMatches(date, timePeriod, game)) {
            timePeriod = timePeriodIterator.next();
        }
        List<GameSummary> existing = result.get(timePeriod);
        if (existing == null) {
            result.put(timePeriod, new ArrayList<GameSummary>(Collections.singleton(game)));
        } else {
            existing.add(game);
        }
    }
    return result;
}
Also used : TimePeriod(com.nolanlawson.keepscore.data.TimePeriod) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) GameSummary(com.nolanlawson.keepscore.db.GameSummary) Date(java.util.Date)

Example 8 with GameSummary

use of com.nolanlawson.keepscore.db.GameSummary in project KeepScore by nolanlawson.

the class MainActivity method showDeleteSelectedDialog.

private void showDeleteSelectedDialog() {
    final Set<GameSummary> games = new HashSet<GameSummary>();
    for (SavedGameAdapter subAdapter : adapter.getSectionsMap().values()) {
        games.addAll(subAdapter.getChecked());
    }
    String message = games.size() == 1 ? getString(R.string.text_game_will_be_deleted) : String.format(getString(R.string.text_games_will_be_deleted), games.size());
    new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.title_confirm_delete).setMessage(message).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            deleteGames(games);
        }
    }).show();
}
Also used : DialogInterface(android.content.DialogInterface) SavedGameAdapter(com.nolanlawson.keepscore.data.SavedGameAdapter) OnClickListener(android.view.View.OnClickListener) GameSummary(com.nolanlawson.keepscore.db.GameSummary) HashSet(java.util.HashSet)

Aggregations

GameSummary (com.nolanlawson.keepscore.db.GameSummary)8 SavedGameAdapter (com.nolanlawson.keepscore.data.SavedGameAdapter)5 TimePeriod (com.nolanlawson.keepscore.data.TimePeriod)3 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 TextView (android.widget.TextView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1