//if this entry is score, update views && activate next round
@Override
        public void onClick(DialogInterface dialog, int which) {
            // User clicked OK button
            int[] inputs = new int[playerManager.getSelectedPlayerCount()];
            //starts at STARTINGPLAYER, since input list starts at STARTINGPLAYER
            for (int i = STARTINGPLAYER; i < playerManager.getSelectedPlayerCount() + STARTINGPLAYER; i++) {
                int index = getPlayerIndex(i);
                EditText editText = (EditText) ((LinearLayout) linearLayout.getChildAt(i - STARTINGPLAYER)).getChildAt(3);
                //verify input
                int input;
                try {
                    input = Integer.parseInt(editText.getText().toString());
                } catch (NumberFormatException nfe) {
                    Toast toast = Toast.makeText(CONTEXT, "Invalid input", Toast.LENGTH_SHORT);
                    toast.show();
                    return;
                }
                inputs[index] = input;
            }
            //validate results
            int totalValue = 0;
            for (int value : inputs) {
                if (value < 0) {
                    Toast toast = Toast.makeText(CONTEXT, CONTEXT.getResources().getString(R.string.invalid_number), Toast.LENGTH_SHORT);
                    toast.show();
                    return;
                }
                totalValue += value;
            }
            if (gameScoreManager.getNextEntryType() == ReadOnlyGameScoreManager.EntryType.SCORE && totalValue != gameScoreManager.getCardCount(gameScoreManager.getRound())) {
                Toast toast = Toast.makeText(CONTEXT, CONTEXT.getResources().getString(R.string.invalid_score), Toast.LENGTH_LONG);
                toast.show();
                return;
            }
            //save results
            //todo: save playerID with input field for better code quality
            Map<Long, Integer> inputMap = new HashMap<>();
            for (int i = 0; i < playerManager.getSelectedPlayerCount(); i++) {
                inputMap.put(playerManager.getSelectedPlayers()[i], inputs[i]);
            }
            //if this entry is score, update views && activate next round
            if (gameScoreManager.getNextEntryType() == GameScoreManager.EntryType.SCORE) {
                gameScoreManager.enterScores(inputMap);
                PersistenceManager.getInstance().saveGame(gameScoreManager);
                headerManager.updateScores();
                rowManager.updateScores();
                changeButtonVisibility(ButtonVisible.NONE);
                if (gameScoreManager.getRound() != gameScoreManager.getAmountOfRounds()) {
                    nextRound.changeButtonVisibility(ButtonVisible.PREDICT);
                }
            } else {
                gameScoreManager.enterPredictions(inputMap);
                PersistenceManager.getInstance().saveGame(gameScoreManager);
                rowManager.updatePredictions();
                changeButtonVisibility(ButtonVisible.SCORE);
            }
            //change buttons
            changeButtonVisibility(gameScoreManager.getNextEntryType() == ReadOnlyGameScoreManager.EntryType.SCORE ? ButtonVisible.SCORE : ButtonVisible.NONE);
        }
inputMap.put(playerManager.getSelectedPlayers()[i], inputs[i]);
}
//if this entry is score, update views && activate next round
if (gameScoreManager.getNextEntryType() == GameScoreManager.EntryType.SCORE) {
gameScoreManager.enterScores(inputMap);
Toast toast = Toast.makeText(CONTEXT, CONTEXT.getResources().getString(R.string.invalid_score), Toast.LENGTH_LONG);
toast.show();
return;
}
//save results
//todo: save playerID with input field for better code quality
Map<Long, Integer> inputMap = new HashMap<>();
for (int i = 0; i < playerManager.getSelectedPlayerCount(); i++) {
inputMap.put(playerManager.getSelectedPlayers()[i], inputs[i]);
}
//if this entry is score, update views && activate next round
if (gameScoreManager.getNextEntryType() == GameScoreManager.EntryType.SCORE) {
gameScoreManager.enterScores(inputMap);
PersistenceManager.getInstance().saveGame(gameScoreManager);
headerManager.updateScores();
rowManager.updateScores();
changeButtonVisibility(ButtonVisible.NONE);
if (gameScoreManager.getRound() != gameScoreManager.getAmountOfRounds()) {
nextRound.changeButtonVisibility(ButtonVisible.PREDICT);
}
} else {
int totalValue = 0;
for (int value : inputs) {
if (value < 0) {
Toast toast = Toast.makeText(CONTEXT, CONTEXT.getResources().getString(R.string.invalid_number), Toast.LENGTH_SHORT);
toast.show();
return;
}
totalValue += value;
}
if (gameScoreManager.getNextEntryType() == ReadOnlyGameScoreManager.EntryType.SCORE && totalValue != gameScoreManager.getCardCount(gameScoreManager.getRound())) {
Toast toast = Toast.makeText(CONTEXT, CONTEXT.getResources().getString(R.string.invalid_score), Toast.LENGTH_LONG);
toast.show();
return;
}
//save results
//todo: save playerID with input field for better code quality
Map<Long, Integer> inputMap = new HashMap<>();
for (int i = 0; i < playerManager.getSelectedPlayerCount(); i++) {
inputMap.put(playerManager.getSelectedPlayers()[i], inputs[i]);
}
//if this entry is score, update views && activate next round
if (gameScoreManager.getNextEntryType() == GameScoreManager.EntryType.SCORE) {
gameScoreManager.enterScores(inputMap);
PersistenceManager.getInstance().saveGame(gameScoreManager);
headerManager.updateScores();
rowManager.updateScores();
changeButtonVisibility(ButtonVisible.NONE);
if (gameScoreManager.getRound() != gameScoreManager.getAmountOfRounds()) {
nextRound.changeButtonVisibility(ButtonVisible.PREDICT);
}
} else {
gameScoreManager.enterPredictions(inputMap);
PersistenceManager.getInstance().saveGame(gameScoreManager);
rowManager.updatePredictions();
changeButtonVisibility(ButtonVisible.SCORE);
}
//change buttons
changeButtonVisibility(gameScoreManager.getNextEntryType() == ReadOnlyGameScoreManager.EntryType.SCORE ? ButtonVisible.SCORE : ButtonVisible.NONE);
}