Search in sources :

Example 11 with PlayerScore

use of com.nolanlawson.keepscore.db.PlayerScore 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) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 12 with PlayerScore

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

the class GameActivity method setUpWidgets.

private void setUpWidgets() {
    rootLayout = (LinearLayout) findViewById(R.id.game_root_layout);
    // add top and bottom spacing on the two-player game. it looks nicer
    rootPadding1 = findViewById(R.id.game_root_padding_1);
    rootPadding2 = findViewById(R.id.game_root_padding_2);
    rootPadding1.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
    rootPadding2.setVisibility(playerScores.size() <= 2 ? View.VISIBLE : View.GONE);
    // if the round totals are enabled
    try {
        roundTotalViewStub = (ViewStub) findViewById(R.id.round_totals);
        int versionInt = VersionHelper.getVersionSdkIntCompat();
        if (versionInt > VersionHelper.VERSION_DONUT && versionInt < VersionHelper.VERSION_FROYO) {
            roundTotalTextView = (TextView) roundTotalViewStub.inflate();
        }
    } catch (ClassCastException ignore) {
    // view stub already inflated
    }
    playerViews = new ArrayList<PlayerView>();
    boolean showOnscreenDeltaButtons = getShouldShowOnscreenDeltaButtons();
    for (int i = 0; i < playerScores.size(); i++) {
        PlayerScore playerScore = playerScores.get(i);
        int resId = getPlayerViewResId(i);
        View view = getPlayerScoreView(resId);
        if (view == null) {
            log.e("Null pointer exception; view for player %s is null", i);
        }
        PlayerView playerView = new PlayerView(this, view, playerScore, handler, showOnscreenDeltaButtons);
        playerView.setChangeRecorder(new Callback<RecordedChange>() {

            @Override
            public void onCallback(RecordedChange recordedChange) {
                undoStack.pop(recordedChange);
                redoStack.clear();
            }
        });
        playerView.setOnChangeListener(new Runnable() {

            @Override
            public void run() {
                updateRoundTotalViewText();
                updateHighlightedPlayer();
            }
        });
        // worth saving. This only applies for newly created games.
        if (game.getId() == -1 && !TextUtils.isEmpty(playerScore.getName())) {
            playerView.getShouldAutosave().set(true);
        }
        playerViews.add(playerView);
    }
    hideAbsentPlayers();
}
Also used : PlayerView(com.nolanlawson.keepscore.widget.PlayerView) RecordedChange(com.nolanlawson.keepscore.data.RecordedChange) PlayerView(com.nolanlawson.keepscore.widget.PlayerView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 13 with PlayerScore

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

the class MainActivity method copyGame.

private void copyGame(Game game, final boolean resetScores) {
    final Game newGame = game.makeCleanCopy();
    if (resetScores) {
        for (PlayerScore playerScore : newGame.getPlayerScores()) {
            playerScore.setScore(PreferenceHelper.getIntPreference(R.string.CONSTANT_pref_initial_score, R.string.CONSTANT_pref_initial_score_default, this));
            playerScore.setHistory(new ArrayList<Delta>());
        }
    }
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            GameDBHelper dbHelper = null;
            try {
                dbHelper = new GameDBHelper(MainActivity.this);
                dbHelper.saveGame(newGame);
            } finally {
                if (dbHelper != null) {
                    dbHelper.close();
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            onNewGameCreated(newGame);
            ToastHelper.showShort(MainActivity.this, resetScores ? R.string.toast_rematch_created : R.string.toast_game_copied);
        }
    }.execute((Void) null);
}
Also used : Game(com.nolanlawson.keepscore.db.Game) Delta(com.nolanlawson.keepscore.db.Delta) GameDBHelper(com.nolanlawson.keepscore.db.GameDBHelper) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 14 with PlayerScore

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

the class EditablePlayerAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.editable_player, parent, false);
    }
    final PlayerScore playerScore = getItem(position);
    TextView nameTextView = (TextView) view.findViewById(R.id.text_player_name);
    TextView numberTextView = (TextView) view.findViewById(R.id.text_player_number);
    TextView scoreTextView = (TextView) view.findViewById(R.id.text_player_score);
    PlayerColorView playerColorView = (PlayerColorView) view.findViewById(R.id.player_color_image);
    playerColorView.setVisibility(PreferenceHelper.getShowColors(getContext()) ? View.VISIBLE : View.GONE);
    nameTextView.setText(playerScore.toDisplayName(getContext()));
    numberTextView.setText('#' + Integer.toString(playerScore.getPlayerNumber() + 1));
    scoreTextView.setText(Long.toString(playerScore.getScore()));
    playerColorView.setPlayerColor(playerScore.getPlayerColor());
    // listen for player color clicks
    playerColorView.setOnClickListener(new OnClickListener() {

        private PlayerColor chosenColor;

        @Override
        public void onClick(View v) {
            DialogHelper.showColorChooserDialog(getContext(), playerScore.getPlayerColor(), new Callback<PlayerColor>() {

                @Override
                public void onCallback(PlayerColor playerColor) {
                    // color changed
                    chosenColor = playerColor;
                }
            }, new Runnable() {

                @Override
                public void run() {
                    // color selected
                    if (chosenColor == null) {
                        return;
                    }
                    playerScore.setPlayerColor(chosenColor);
                    notifyDataSetChanged();
                }
            });
        }
    });
    // add listener to the delete button
    ImageButton deleteButton = (ImageButton) view.findViewById(R.id.button_delete_player);
    deleteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // delete
            remove(playerScore);
            resetPlayerNumbers();
            notifyDataSetChanged();
            if (onDeleteListener != null) {
                onDeleteListener.onCallback(playerScore);
            }
        }
    });
    // user is not allowed to delete the final 2 users
    deleteButton.setEnabled(getCount() > OrganizePlayersActivity.MIN_NUM_PLAYERS);
    ImageButton editButton = (ImageButton) view.findViewById(R.id.button_edit_player);
    editButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // edit
            DialogHelper.showPlayerNameDialog(getContext(), R.string.title_change_name, playerScore.getName(), playerScore.getPlayerNumber(), new Callback<String>() {

                @Override
                public void onCallback(String input) {
                    playerScore.setName(input);
                    notifyDataSetChanged();
                }
            });
        }
    });
    view.setVisibility(currentlyDragging == view ? View.INVISIBLE : View.VISIBLE);
    return view;
}
Also used : ImageButton(android.widget.ImageButton) PlayerColor(com.nolanlawson.keepscore.helper.PlayerColor) Callback(com.nolanlawson.keepscore.util.Callback) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) PlayerColorView(com.nolanlawson.keepscore.widget.PlayerColorView) PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Example 15 with PlayerScore

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

the class EditablePlayerAdapter method drop.

@Override
public void drop(int from, int to) {
    PlayerScore temp = items.get(from);
    items.remove(from);
    items.add(to, temp);
    resetPlayerNumbers();
    notifyDataSetChanged();
}
Also used : PlayerScore(com.nolanlawson.keepscore.db.PlayerScore)

Aggregations

PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)19 Delta (com.nolanlawson.keepscore.db.Delta)5 Game (com.nolanlawson.keepscore.db.Game)5 ArrayList (java.util.ArrayList)5 View (android.view.View)3 TextView (android.widget.TextView)3 HistoryItem (com.nolanlawson.keepscore.data.HistoryItem)3 IOException (java.io.IOException)3 SparseArray (android.util.SparseArray)2 ImageView (android.widget.ImageView)2 TableRow (android.widget.TableRow)2 PlayerView (com.nolanlawson.keepscore.widget.PlayerView)2 LineChartLine (com.nolanlawson.keepscore.widget.chart.LineChartLine)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 Intent (android.content.Intent)1 LayoutInflater (android.view.LayoutInflater)1 OnClickListener (android.view.View.OnClickListener)1 ImageButton (android.widget.ImageButton)1 EditablePlayerAdapter (com.nolanlawson.keepscore.data.EditablePlayerAdapter)1 RecordedChange (com.nolanlawson.keepscore.data.RecordedChange)1