Search in sources :

Example 1 with HistoryItem

use of com.nolanlawson.keepscore.data.HistoryItem 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;
}
Also used : HistoryItem(com.nolanlawson.keepscore.data.HistoryItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 2 with HistoryItem

use of com.nolanlawson.keepscore.data.HistoryItem in project KeepScore by nolanlawson.

the class HistoryRoundTableFragment method createByRoundTableLayout.

private void createByRoundTableLayout(Activity activity) {
    // i.e. not the "divider" or "row header" columns
    for (int i = 0; i < game.getPlayerScores().size(); i++) {
        byRoundTableLayout.setColumnShrinkable((i * 2) + 2, true);
        byRoundTableLayout.setColumnStretchable((i * 2) + 2, true);
    }
    // the 'by round' adapter simply needs each player name as a first
    // header row, and then after that you just go round-by-round
    // summing up the values and displaying the diff, e.g.:
    // p1, p2, p3, p4
    // 0, 0, 0, 0
    // +5, +3, -2, +10
    // 5, 3, 2, 10
    // etc.
    List<PlayerScore> playerScores = game.getPlayerScores();
    int historyItemLayoutId = playerScores.size() <= MAX_COLUMNS_FOR_WIDE_LIST_LAYOUT ? R.layout.history_item_wide : playerScores.size() <= MAX_COLUMNS_FOR_REGULAR_TALL_LIST_LAYOUT ? R.layout.history_item_tall : R.layout.history_item_extra_tall;
    // create the first row
    TableRow headerRow = new TableRow(activity);
    headerRow.addView(createListHeader(headerRow, " ", false, false));
    for (PlayerScore playerScore : playerScores) {
        headerRow.addView(createDividerView(headerRow));
        headerRow.addView(createListHeader(headerRow, playerScore.toDisplayName(activity), true, false));
    }
    // add a column to the right with an epsilon sign (for the round total
    // sum)
    headerRow.addView(createDividerView(headerRow));
    headerRow.addView(createListHeader(headerRow, getString(R.string.CONSTANT_text_epsilon), false, true));
    byRoundTableLayout.addView(headerRow);
    List<HistoryItem> collatedHistoryItems = getCollatedHistoryItems(activity);
    for (int i = 0; i < collatedHistoryItems.size(); i += playerScores.size()) {
        int rowId = (i / playerScores.size());
        TableRow tableRow = new TableRow(activity);
        // add a column for the round number
        // first
        String roundName = (i == 0) ? "" : Integer.toString(rowId);
        // row is  just
        // the starting score
        tableRow.addView(createRowHeader(tableRow, roundName));
        // add in all the history items from this round
        int sum = 0;
        for (int j = i; j < i + playerScores.size(); j++) {
            HistoryItem historyItem = collatedHistoryItems.get(j);
            View historyItemAsView = createHistoryItemView(tableRow, historyItem, historyItemLayoutId, rowId, true, activity);
            tableRow.addView(createDividerView(tableRow));
            tableRow.addView(historyItemAsView);
            sum += historyItem == null ? 0 : historyItem.getDelta();
        }
        // add in the round total (sum)
        tableRow.addView(createDividerView(tableRow));
        if (i == 0) {
            // first row is just the starting score
            HistoryItem bogusHistoryItem = new HistoryItem(0, sum, true);
            tableRow.addView(createHistoryItemView(tableRow, bogusHistoryItem, historyItemLayoutId, rowId, false, activity));
        } else {
            tableRow.addView(createSumView(tableRow, historyItemLayoutId, rowId, sum));
        }
        byRoundTableLayout.addView(tableRow);
    }
}
Also used : TableRow(android.widget.TableRow) HistoryItem(com.nolanlawson.keepscore.data.HistoryItem) TextView(android.widget.TextView) View(android.view.View) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 3 with HistoryItem

use of com.nolanlawson.keepscore.data.HistoryItem in project KeepScore by nolanlawson.

the class HistoryPlayerTableFragment method createByPlayerTableLayout.

private void createByPlayerTableLayout(Activity activity) {
    // 'by player' table is a simple 2-column table with a vertical divider
    int counter = 0;
    List<PlayerScore> playerScores = game.getPlayerScores();
    for (int i = 0; i < playerScores.size(); i += 2) {
        PlayerScore leftPlayer = playerScores.get(i);
        PlayerScore rightPlayer = i + 1 < playerScores.size() ? playerScores.get(i + 1) : null;
        // create the header
        TableRow headerRow = new TableRow(activity);
        headerRow.addView(createListHeader(headerRow, leftPlayer.toDisplayName(activity), true, false));
        headerRow.addView(createDividerView(headerRow));
        headerRow.addView(createListHeader(headerRow, rightPlayer == null ? " " : rightPlayer.toDisplayName(activity), true, false));
        byPlayerTableLayout.addView(headerRow);
        // create the body
        Iterator<HistoryItem> leftHistoryItems = HistoryItem.createFromPlayerScore(leftPlayer, activity).iterator();
        Iterator<HistoryItem> rightHistoryItems = rightPlayer == null ? Collections.<HistoryItem>emptyList().iterator() : HistoryItem.createFromPlayerScore(rightPlayer, activity).iterator();
        while (leftHistoryItems.hasNext() || rightHistoryItems.hasNext()) {
            HistoryItem leftItem = leftHistoryItems.hasNext() ? leftHistoryItems.next() : null;
            HistoryItem rightItem = rightHistoryItems.hasNext() ? rightHistoryItems.next() : null;
            TableRow tableRow = new TableRow(activity);
            tableRow.addView(createHistoryItemView(tableRow, leftItem, R.layout.history_item_wide, counter, true, activity));
            tableRow.addView(createDividerView(tableRow));
            tableRow.addView(createHistoryItemView(tableRow, rightItem, R.layout.history_item_wide, counter, true, activity));
            byPlayerTableLayout.addView(tableRow);
            counter++;
        }
    }
}
Also used : TableRow(android.widget.TableRow) HistoryItem(com.nolanlawson.keepscore.data.HistoryItem) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Aggregations

HistoryItem (com.nolanlawson.keepscore.data.HistoryItem)3 PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)3 TableRow (android.widget.TableRow)2 View (android.view.View)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1