· 7 years ago · Sep 25, 2018, 05:22 PM
1public class League {
2
3 public static final String TABLE_NAME = "league";
4
5 public static final String COLUMN_ID = "_id";
6 public static final String COLUMN_NAME = "name";
7 public static final String COLUMN_BASE_SCORE = "basescore";
8 public static final String COLUMN_BASE_SCORE_PERCENTAGE = "basescorepercentage";
9 public static final String COLUMN_WINS = "wins";
10 public static final String COLUMN_LOSSES = "losses";
11 public static final String COLUMN_TIMESTAMP = "timestamp";
12
13 private int id;
14 private String name;
15 private String basescore;
16 private String basescorepercentage;
17 private String wins;
18 private String losses;
19 private String timestamp;
20
21
22 // Create table SQL query
23 public static final String CREATE_TABLE =
24 "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "("
25 + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
26 + COLUMN_NAME + " TEXT,"
27 + COLUMN_BASE_SCORE + " TEXT,"
28 + COLUMN_BASE_SCORE_PERCENTAGE + " TEXT,"
29 + COLUMN_WINS + " TEXT,"
30 + COLUMN_LOSSES + " TEXT,"
31 + COLUMN_TIMESTAMP + " DATETIME DEFAULT CURRENT_TIMESTAMP"
32 + ")";
33
34 public League() {
35 }
36
37 public League(int id, String name, String basescore, String basescorepercentage, String wins, String losses, String timestamp) {
38 this.id = id;
39 this.name = name;
40 this.basescore = basescore;
41 this.basescorepercentage = basescorepercentage;
42 this.wins = wins;
43 this.losses = losses;
44 this.timestamp = timestamp;
45 }
46
47 public int getId() {
48 return id;
49 }
50
51 public String getName() {
52 return name;
53 }
54
55 public void setName(String name) {
56 this.name = name;
57 }
58
59 public String getBaseScore() {
60 return basescore;
61 }
62
63 public void setBaseScore(String basescore) {
64 this.basescore = basescore;
65 }
66
67 public String getBaseScorePercentage() {
68 return basescorepercentage;
69 }
70
71 public void setBaseScorePercentage(String basescorepercentage) {
72 this.basescorepercentage = basescorepercentage;
73 }
74
75 public String getWins() {
76 return wins;
77 }
78
79 public void setWins(String wins) {
80 this.wins = wins;
81 }
82
83 public String getLosses() {
84 return losses;
85 }
86
87 public void setLosses(String losses) {
88 this.losses = losses;
89 }
90
91 public String getTimestamp() {
92 return timestamp;
93 }
94
95 public void setId(int id) {
96 this.id = id;
97 }
98
99 public void setTimestamp(String timestamp) {
100 this.timestamp = timestamp;
101 }
102}
103
104public class LeagueProfileViewActivity extends AppCompatActivity {
105
106 League league;
107
108 private DatabaseHelper db;
109
110 private static final String PREFS_NAME = "prefs";
111 private static final String PREF_BLUE_THEME = "blue_theme";
112 private static final String PREF_GREEN_THEME = "green_theme";
113 private static final String PREF_ORANGE_THEME = "purple_theme";
114 private static final String PREF_RED_THEME = "red_theme";
115 private static final String PREF_YELLOW_THEME = "yellow_theme";
116
117
118 @Override
119 protected void onResume() {
120 super.onResume();
121 db = new DatabaseHelper(this);
122 //mAdapter.notifyDatasetChanged(db.getAllLeagues());
123 }
124
125 @Override
126 protected void onCreate(Bundle savedInstanceState) {
127
128 //Use Chosen Theme
129 SharedPreferences preferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
130 boolean useBlueTheme = preferences.getBoolean(PREF_BLUE_THEME, false);
131 if (useBlueTheme) {
132 setTheme(R.style.AppTheme_Blue_NoActionBar);
133 }
134 boolean useGreenTheme = preferences.getBoolean(PREF_GREEN_THEME, false);
135 if (useGreenTheme) {
136 setTheme(R.style.AppTheme_Green_NoActionBar);
137 }
138 boolean useOrangeTheme = preferences.getBoolean(PREF_ORANGE_THEME, false);
139 if (useOrangeTheme) {
140 setTheme(R.style.AppTheme_Orange_NoActionBar);
141 }
142 boolean useRedTheme = preferences.getBoolean(PREF_RED_THEME, false);
143 if (useRedTheme) {
144 setTheme(R.style.AppTheme_Red_NoActionBar);
145 }
146 boolean useYellowTheme = preferences.getBoolean(PREF_YELLOW_THEME, false);
147 if (useYellowTheme) {
148 setTheme(R.style.AppTheme_Yellow_NoActionBar);
149 }
150
151 super.onCreate(savedInstanceState);
152 setContentView(R.layout.activity_league_profile_view);
153 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
154 setSupportActionBar(toolbar);
155
156 Objects.requireNonNull( getSupportActionBar() ).setDisplayHomeAsUpEnabled(true);
157 getSupportActionBar().setDisplayShowHomeEnabled(true);
158
159 toolbar.setNavigationOnClickListener(new View.OnClickListener() {
160 @Override
161 public void onClick(View v) {
162 startActivity(new Intent(getApplicationContext(),MainActivity.class));
163 finish();
164 overridePendingTransition(0, 0);
165
166 }
167 });
168
169 String savedLeagueId = String.valueOf(getIntent().getIntExtra("leagueId",2));
170 int leagueId = Integer.valueOf(savedLeagueId);
171
172 getLeagueProfile(null, leagueId);
173
174 TextView leagueName = findViewById(R.id.tvLeagueName);
175 TextView basisScore = findViewById(R.id.tvBasisScore);
176 TextView basisScorePercentage = findViewById(R.id.tvBasisScorePercentage);
177 TextView leagueWins = findViewById(R.id.tvLeagueWins);
178 TextView leagueLosses = findViewById(R.id.tvLeagueLosses);
179
180 if (league != null) {
181 leagueName.setText(league.getName());
182 basisScore.setText(league.getBaseScore());
183 basisScorePercentage.setText(league.getBaseScorePercentage());
184 leagueWins.setText(league.getWins());
185 leagueLosses.setText(league.getLosses());
186 }
187 }
188
189 public League getLeagueProfile(League league, int position) {
190
191 SQLiteOpenHelper database = new DatabaseHelper(this);
192 SQLiteDatabase db = database.getReadableDatabase();
193
194 Cursor cursor = db.query(League.TABLE_NAME,
195 new String[]{League.COLUMN_ID, League.COLUMN_NAME, League.COLUMN_BASE_SCORE, League.COLUMN_BASE_SCORE_PERCENTAGE, League.COLUMN_WINS, League.COLUMN_LOSSES, League.COLUMN_TIMESTAMP},
196 League.COLUMN_ID + "=?",
197 new String[]{String.valueOf(position)}, null, null, null, null);
198
199 if (cursor.moveToFirst()) {
200
201 //Prepare League Object
202 league = new League(
203 cursor.getInt(cursor.getColumnIndex(League.COLUMN_ID)),
204 cursor.getString(cursor.getColumnIndex(League.COLUMN_NAME)),
205 cursor.getString(cursor.getColumnIndex(League.COLUMN_BASE_SCORE)),
206 cursor.getString(cursor.getColumnIndex(League.COLUMN_BASE_SCORE_PERCENTAGE)),
207 cursor.getString(cursor.getColumnIndex(League.COLUMN_WINS)),
208 cursor.getString(cursor.getColumnIndex(League.COLUMN_LOSSES)),
209 cursor.getString(cursor.getColumnIndex(League.COLUMN_TIMESTAMP)));
210
211 Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor));
212 Log.e("values : ", League.COLUMN_NAME + ", " + League.COLUMN_BASE_SCORE + ", " + League.COLUMN_BASE_SCORE_PERCENTAGE+ ", " +League.COLUMN_ID);
213
214 //Close Database Connection
215 cursor.close();
216 return league;
217 } else {
218 return null;
219 }
220 }
221}