@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_team); _playerList = (LinearLayout) findViewById(R.id.playerList); findViewById(R.id.addPlayer).setOnClickListener(addPlayerListener); findViewById(R.id.editPlayer).setOnClickListener(editPlayerListener); findViewById(R.id.deletePlayer).setOnClickListener(deletePlayerListener); findViewById(R.id.confirmTeam).setOnClickListener(confirmTeamListener); String teamEditor = getIntent().getStringExtra(StaticFinalVars.CREATE_EDIT); _sportType = getIntent().getStringExtra(StaticFinalVars.SPORT_TYPE); _loggedIn = getIntent().getBooleanExtra(StaticFinalVars.LOGIN_STATUS, false); // databases if (_sportType.equals("basketball")) { _db = new BasketballDatabaseHelper(this); } else if (_sportType.equals("soccer")) { _db = new SoccerDatabaseHelper(this); } else if (_sportType.equals("hockey")) { _db = new HockeyDatabaseHelper(this); } else if (_sportType.equals("football")) { _db = new FootballDatabaseHelper(this); } if (!teamEditor.equals("")) { _editing = true; // Pull info from database and add to scroll view ArrayList<Teams> teams = (ArrayList<Teams>) _db.getAllTeams(); for (Teams t : teams) { if (t.gettname().equals(teamEditor)) { _curTeam = t; t_id = _curTeam.gettid(); break; } } // pull abbr and coach name ((EditText) findViewById(R.id.teamNameEditText)).setText(teamEditor); ((EditText) findViewById(R.id.teamAbbrEditText)).setText(_curTeam.getabbv()); ((EditText) findViewById(R.id.coachNameEditText)).setText(_curTeam.getcname()); // get List of players on curTeam from database ArrayList<Players> players = (ArrayList<Players>) _db.getPlayersTeam2(t_id); // add players names and numbers to view for (Players p : players) { _playerList.addView(newPlayerItem(p.getpname(), ((Integer) p.getpnum()).toString())); } _oldTeamName = teamEditor; } }
public void deleteAll() { List<Games> games = getAllGames(); for (Games g : games) { deleteGame(g.getgid()); deletePlayByPlayGame(g.getgid()); } List<Teams> teams = getAllTeams(); for (Teams t : teams) { deleteTeam(t.gettid()); } }
public int updateTeam(Teams team) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_T_NAME, team.gettname()); values.put(KEY_ABBV, team.getabbv()); values.put(KEY_C_NAME, team.getcname()); values.put(KEY_SPORT, team.getSport()); if (!_local) { _net.updateTeam(team); } return db.update( TABLE_TEAMS, values, KEY_T_ID + " = ?", new String[] {String.valueOf(team.gettid())}); }
@SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stats); _team = (Teams) getIntent().getSerializableExtra(StaticFinalVars.TEAM_INFO); _players = (ArrayList<Players>) getIntent().getSerializableExtra(StaticFinalVars.PLAYERS_INFO); g_id = (Long) getIntent().getSerializableExtra(StaticFinalVars.GAME_ID); _name = getIntent().getStringExtra(StaticFinalVars.PLAYER_NAME); _home = getIntent().getBooleanExtra(StaticFinalVars.HOME_OR_AWAY, true); _shots = (ArrayList<ShotChartCoords>) getIntent().getSerializableExtra(StaticFinalVars.SHOT_CHART); // NEW _hockey_db = new HockeyDatabaseHelper(HockeyIndividualStatActivity.this); _player = getIntent().getStringExtra(StaticFinalVars.PLAYER); _team2 = (Teams) getIntent().getSerializableExtra(StaticFinalVars.TEAM_INFO2); // AVE _games = (ArrayList<BasketballGames>) getIntent().getSerializableExtra(StaticFinalVars.GAMES); _average = getIntent().getBooleanExtra(StaticFinalVars.AVERAGE, false); if (_name != null) { if (_shots.isEmpty() && !_name.equals(_team.getabbv() + " Stats")) { _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(_team.gettid(), g_id); } else if (_shots.isEmpty() && !_name.equals(_team2.getabbv() + " Stats")) { _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(_team2.gettid(), g_id); } else if (_shots.isEmpty() && !_name.equals("All Players")) { Players p2 = null; for (Players p : _players) { if (p.getpname().equals(_name)) { p2 = p; break; } } long t_id = -1; if (p2.gettid() == _team.gettid()) { t_id = _team.gettid(); } else if (p2.gettid() == _team2.gettid()) { t_id = _team2.gettid(); } _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(t_id, g_id); } } if (_player != null) { if (_shots.isEmpty() && !_player.equals("All Players")) { Players p2 = null; for (Players p : _players) { if (p.getpname().equals(_player)) { p2 = p; break; } } long t_id = -1; if (p2.gettid() == _team.gettid()) { t_id = _team.gettid(); } else if (p2.gettid() == _team2.gettid()) { t_id = _team2.gettid(); } _shots = (ArrayList<ShotChartCoords>) _hockey_db.getAllTeamShotsGame(t_id, g_id); } } // END NEW _gameInfo = (GameInfo) getIntent().getSerializableExtra(StaticFinalVars.GAME_INFO); int value = getIntent().getIntExtra(StaticFinalVars.DISPLAY_TYPE, 0); _hockey_db = new HockeyDatabaseHelper(getApplicationContext()); _game = (HockeyGames) _hockey_db.getGame(g_id); _pager = (ViewPager) findViewById(R.id.statsPager); if (_average) { _pagerAdapter = new HockeyIndividualStatPageAdapter(getSupportFragmentManager(), 1); } else { _pagerAdapter = new HockeyIndividualStatPageAdapter(getSupportFragmentManager(), 2); } _pager.setAdapter(_pagerAdapter); _pager.setCurrentItem(value); }
@Override public void onClick(View view) { String teamName = ((EditText) findViewById(R.id.teamNameEditText)).getText().toString(); String teamAbbr = ((EditText) findViewById(R.id.teamAbbrEditText)).getText().toString(); String coachName = ((EditText) findViewById(R.id.coachNameEditText)).getText().toString(); long t_id = -1; if (!_editing) { t_id = _db.createTeams(new Teams(teamName, teamAbbr, coachName, _sportType)); } for (int i = 0; i < _playerList.getChildCount(); i++) { String playerName = ((TextView) ((LinearLayout) _playerList.getChildAt(i)).getChildAt(1)) .getText() .toString(); int playerNumber = Integer.parseInt( ((TextView) ((LinearLayout) _playerList.getChildAt(i)).getChildAt(0)) .getText() .toString()); if (!_editing) { if (_sportType.equals("basketball")) { ((BasketballDatabaseHelper) _db) .createPlayers(new BasketballPlayer(t_id, playerName, playerNumber)); } else if (_sportType.equals("soccer")) { ((SoccerDatabaseHelper) _db) .createPlayers(new SoccerPlayer(t_id, playerName, playerNumber)); } else if (_sportType.equals("hockey")) { ((HockeyDatabaseHelper) _db) .createPlayers(new HockeyPlayer(t_id, playerName, playerNumber)); } else if (_sportType.equals("football")) { ((FootballDatabaseHelper) _db) .createPlayers(new FootballPlayer(t_id, playerName, playerNumber)); } // else if(other sports that could be added)... } } if (_editing) { ArrayList<Teams> teams = (ArrayList<Teams>) _db.getAllTeams(); Teams cur = null; for (Teams team : teams) { if (team.gettname().equals(_oldTeamName)) { cur = team; break; } } t_id = cur.gettid(); _db.updateTeam(new Teams(t_id, teamName, teamAbbr, coachName, _sportType)); } _editing = false; int num = _playerList.getChildCount(); if (_sportType.equals("basketball") && num < 5) { for (int i = num + 1; i <= 5; i++) { String pname = "Player " + i; for (int j = 0; j < _playerList.getChildCount(); j++) { String playerName = ((TextView) ((LinearLayout) _playerList.getChildAt(j)).getChildAt(1)) .getText() .toString(); if (pname.equals(playerName)) { pname += "a"; } } BasketballPlayer p = new BasketballPlayer(t_id, pname, 0); ((BasketballDatabaseHelper) _db).createPlayers(p); } } else if (_sportType.equals("hockey") && num < 6) { for (int i = num + 1; i <= 6; i++) { String pname = "Player " + i; for (int j = 0; j < _playerList.getChildCount(); j++) { String playerName = ((TextView) ((LinearLayout) _playerList.getChildAt(j)).getChildAt(1)) .getText() .toString(); if (pname.equals(playerName)) { pname += "a"; } } HockeyPlayer p = new HockeyPlayer(t_id, pname, 0); ((HockeyDatabaseHelper) _db).createPlayers(p); } } else if (_sportType.equals("soccer") && num < 11) { for (int i = num + 1; i <= 11; i++) { String pname = "Player " + i; for (int j = 0; j < _playerList.getChildCount(); j++) { String playerName = ((TextView) ((LinearLayout) _playerList.getChildAt(j)).getChildAt(1)) .getText() .toString(); if (pname.equals(playerName)) { pname += "a"; } } SoccerPlayer p = new SoccerPlayer(t_id, pname, 0); ((SoccerDatabaseHelper) _db).createPlayers(p); } } else if (_sportType.equals("football") && num < 11) { for (int i = num + 1; i <= 11; i++) { String pname = "Player " + i; for (int j = 0; j < _playerList.getChildCount(); j++) { String playerName = ((TextView) ((LinearLayout) _playerList.getChildAt(j)).getChildAt(1)) .getText() .toString(); if (pname.equals(playerName)) { pname += "a"; } } FootballPlayer p = new FootballPlayer(t_id, pname, 0); ((FootballDatabaseHelper) _db).createPlayers(p); } } Intent intent = new Intent(); intent.putExtra(StaticFinalVars.TEAM_NAME, teamName); intent.putExtra(StaticFinalVars.OLD_TEAM_NAME, _oldTeamName); setResult(Activity.RESULT_OK, intent); finish(); }