Permalink
Browse files

tried to make it show overtime, broke everything

  • Loading branch information...
lsiegert committed Dec 1, 2011
1 parent da19f29 commit d13512620cff2747417fbfa07f51fdd77b912546
View
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lsiegert"
android:versionCode="2"
- android:versionName="2.5">
+ android:versionName="2.6">
<application android:icon="@drawable/icon_terrible" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".NUHockey"
android:label="@string/app_name"
View
@@ -10,5 +10,5 @@
<string name="info_text">Check off the games you\'ve been to on the Schedule tab.</string>
<string name="changeseason">Change Season</string>
<string name="sort">Sort</string>
- <item type="string" name="databaseVersion" format="integer">5</item>
+ <item type="string" name="databaseVersion" format="integer">6</item>
</resources>
@@ -79,13 +79,14 @@ private void checkForGameUpdates() throws Exception {
int nuscore = parseOrInvalid(game.get("nuscore"));
int oppscore = parseOrInvalid(game.get("oppscore"));
String location = game.get("location");
+ boolean overtime = Boolean.parseBoolean(game.get("overtime"));
if (op.equalsIgnoreCase("NEW")) {
Log.d(TAG, "Creating game: " + id);
- gamesDba.createGame(id, date, season, opponent, nuscore, oppscore, location);
+ gamesDba.createGame(id, date, season, opponent, nuscore, oppscore, location, overtime);
} else if (op.equalsIgnoreCase("UPDATED")) {
Log.d(TAG, "Updating game: " + id);
- gamesDba.updateGame(id, date, season, opponent, nuscore, oppscore, location);
+ gamesDba.updateGame(id, date, season, opponent, nuscore, oppscore, location, overtime);
} else if (op.equalsIgnoreCase("DELETED")) {
Log.d(TAG, "Deleting game: " + id);
gamesDba.deleteGame(id);
@@ -133,7 +134,7 @@ private int parseOrInvalid(String s) {
Log.d(TAG, "Parsing line: " + line);
Map<String,String> m = new HashMap<String,String>();
String[] parts = line.split(",");
- if (parts.length == 8) {
+ if (parts.length == 9) {
m.put("operation", parts[0]);
m.put("id", parts[1]);
m.put("date", parts[2]);
@@ -142,9 +143,10 @@ private int parseOrInvalid(String s) {
m.put("nuscore", parts[5]);
m.put("oppscore", parts[6]);
m.put("location", parts[7]);
+ m.put("overtime", parts[8]);
updates.add(m);
} else {
- Log.e(TAG, "Line doesn't have 8 parts");
+ Log.e(TAG, "Line doesn't have 9 parts");
}
}
// Return a list of Maps that can be used by the methods of gamesDba
@@ -21,6 +21,7 @@
public static final String OPPONENT = "opponent";
public static final String SEASON = "season";
public static final String NUSCORE = "nuscore";
+ public static final String OVERTIME = "overtime";
public static final String DATE = "date";
public static final String UPDATED = "updated";
public static final String ATTENDED = "attended";
@@ -47,7 +48,7 @@ public void close() {
}
public long createGame(int id, String date, String season, String opponent,
- int nuscore, int oppscore, String location) {
+ int nuscore, int oppscore, String location, boolean overtime) {
ContentValues initialValues = new ContentValues();
initialValues.put(ID, id);
initialValues.put(DATE, date);
@@ -56,12 +57,13 @@ public long createGame(int id, String date, String season, String opponent,
initialValues.put(NUSCORE, nuscore);
initialValues.put(OPPSCORE, oppscore);
initialValues.put(LOCATION, location);
+ initialValues.put(OVERTIME, overtime);
return mDb.insert("games", null, initialValues);
}
public boolean updateGame(int id, String date, String season,
- String opponent, int nuscore, int oppscore, String location) {
+ String opponent, int nuscore, int oppscore, String location, boolean overtime) {
ContentValues values = new ContentValues();
values.put(ID, id);
values.put(DATE, date);
@@ -70,6 +72,7 @@ public boolean updateGame(int id, String date, String season,
values.put(NUSCORE, nuscore);
values.put(OPPSCORE, oppscore);
values.put(LOCATION, location);
+ values.put(OVERTIME, overtime);
return mDb.update("games", values, ID + "=" + id, null) > 0;
}
@@ -153,7 +156,7 @@ public Cursor getGamesByOpponent(String opponent) {
return mDb.rawQuery(query, new String[] { opponent });
}
- // W-L-T record across all completed games in the given season
+ // W-L-T record across all games in the given season
public String getRecordBySeason(String season) {
String wins = "select games._id from games where nuscore > oppscore and season=?";
String losses = "select games._id from games where nuscore < oppscore and season=?";
@@ -164,8 +167,9 @@ public String getRecordBySeason(String season) {
int t = mDb.rawQuery(ties, seasons).getCount();
return w + "-" + l + "-" + t;
}
+
- // W-L-T record across all completed games against the given opponent
+ // W-L-T record across all games against the given opponent
public String getRecordByOpponent(String opponent) {
String wins = "select games._id from games where nuscore > oppscore and opponent=?";
String losses = "select games._id from games where nuscore < oppscore and opponent=?";
@@ -200,6 +204,18 @@ public String getRecordByLocation(String location) {
return w + "-" + l + "-" + t;
}
+ // W-L-T record across overtime games the user has attended
+ public String getOvertimeRecord(String overtime) {
+ String wins = "select games._id from games, attended where nuscore > oppscore and games._id=attended.attended and overtime=?";
+ String losses = "select games._id from games, attended where nuscore < oppscore and games._id=attended.attended and overtime=?";
+ String ties = "select games._id from games, attended where nuscore = oppscore and games._id=attended.attended and overtime=?";
+ String[] args = new String[] { overtime };
+ int w = mDb.rawQuery(wins, args).getCount();
+ int l = mDb.rawQuery(losses, args).getCount();
+ int t = mDb.rawQuery(ties, args).getCount();
+ return w + "-" + l + "-" + t;
+ }
+
public int getNumOfTeams() {
String query = "select distinct opponent from games, attended where games._id=attended.attended";
return mDb.rawQuery(query, null).getCount();
@@ -231,21 +247,21 @@ public int getNumOfWinsAtagganis() {
private static class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "gamedata";
- private static final int DATABASE_VERSION = 1;
+ private static final int DATABASE_VERSION = 2;
private static final String GAMES_TABLE_CREATE = "create table games("
+ ID + " integer primary key, " + DATE + " text not null,"
+ SEASON + " text not null," + OPPONENT + " text not null,"
+ NUSCORE + " integer," + OPPSCORE + " integer," + LOCATION
- + " text not null" + ");";
+ + " text not null," + OVERTIME + " boolean" + ");";
private static final String UPDATED_TABLE_CREATE = "create table updated("
+ ID
+ " integer primary key autoincrement, "
+ UPDATED
+ " text not null" + ");";
- private static final String ATTENDED_TABLE_CREATE = "create table attended("
+ private static final String ATTENDED_TABLE_CREATE = "create table if not exists attended("
+ ID
+ " integer primary key autoincrement, "
+ ATTENDED
@@ -266,7 +282,7 @@ public void onCreate(SQLiteDatabase db) {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS games");
db.execSQL("DROP TABLE IF EXISTS updated");
- db.execSQL("DROP TABLE IF EXISTS attended");
+ //db.execSQL("DROP TABLE IF EXISTS attended");
onCreate(db);
}
@@ -10,7 +10,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;
-import android.widget.Toast;
public class ScheduleActivity extends ListActivity {
private GamesDbAdapter dbHelper = null;
@@ -122,7 +121,6 @@ private void sort() {
builder.setTitle("View games by");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
- //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
String s = items[item].toString();
if (s.equalsIgnoreCase("Season")) {
showGamesBySeason("2011-12");
@@ -143,7 +141,6 @@ private void changeSeason() {
builder.setTitle("Choose a season");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
- //Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
showGamesBySeason(items[item].toString());
listView.requestLayout();
}
@@ -64,11 +64,18 @@ else if (location.contains("away")) {
TextView gameScore = (TextView) convertView.findViewById(R.id.score);
int nuscore = games.getInt(games.getColumnIndex("nuscore"));
int oppscore = games.getInt(games.getColumnIndex("oppscore"));
+ boolean overtime = Boolean.parseBoolean(games.getString(games.getColumnIndex("overtime")));
if (nuscore < 0 || oppscore < 0) {
gameScore.setText("");
} else {
- gameScore.setText(nuscore + "-" + oppscore);
+ String score = nuscore + "-" + oppscore;
+
+ if (overtime) {
+ score = score + " (OT)";
+ }
+
+ gameScore.setText(score);
if (nuscore > oppscore) {
gameScore.setTextColor(Color.GREEN);

0 comments on commit d135126

Please sign in to comment.