Further Alert cleanup >AGK

This commit is contained in:
agk512 2013-12-02 03:35:22 -05:00
parent 33afb534bd
commit 06f7c7933f

View File

@ -1,7 +1,10 @@
package com.uncc.gameday.alerts; package com.uncc.gameday.alerts;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import android.content.ContentValues; import android.content.ContentValues;
@ -84,8 +87,8 @@ public class AlertDB extends SQLiteOpenHelper {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(KEY_MESSAGE, a.getMessage()); values.put(KEY_MESSAGE, a.getMessage());
long dateValue = a.getAlarmDate().getTime();
values.put(KEY_ALARM_DATE, dateValue); values.put(KEY_ALARM_DATE, a.getAlarmDate());
values.put(KEY_SHOWN, a.isShown()); values.put(KEY_SHOWN, a.isShown());
values.put(KEY_TYPE, a.getType()); values.put(KEY_TYPE, a.getType());
@ -108,6 +111,7 @@ public class AlertDB extends SQLiteOpenHelper {
} }
/** /**
* Fetch an alert by date * Fetch an alert by date
* TODO: Unused. Remove? * TODO: Unused. Remove?
@ -145,10 +149,8 @@ public class AlertDB extends SQLiteOpenHelper {
} }
/** /**
* Fetch all alerts from the Database, and mark as read * Fetch all alerts from the Database
* *
* @return the list * @return the list
*/ */
@ -164,21 +166,41 @@ public class AlertDB extends SQLiteOpenHelper {
//for each alert in database //for each alert in database
//add it to alert list to be shown //add it to alert list to be shown
//and modify it in DB to be classified as shown //and modify it in DB to be classified as shown
int i = 0;
if (cursor.moveToFirst()) if (cursor.moveToFirst())
{ {
GregorianCalendar todayDate = new GregorianCalendar();
long currentDate = todayDate.getTimeInMillis();
do do
{
if(currentDate >= cursor.getLong(1))
{ {
Alert alert = new Alert(); Alert alert = new Alert();
alert.setMessage(cursor.getString(0)); alert.setMessage(cursor.getString(0));
alert.setAlarmDate(new Date(cursor.getLong(1))); alert.setAlarmDate(cursor.getLong(1));
alert.setShown(cursor.getInt(2)); alert.setShown(cursor.getInt(2));
updateAlert(alert);
alertList.add(alert); alertList.add(alert);
} while (cursor.moveToNext()); i++;
}
} while (cursor.moveToNext() && i < 10);
} }
db.close(); db.close();
//sorts alerts by Date
Collections.sort(alertList, new Comparator<Alert>() {
@Override
public int compare(Alert a1, Alert a2) {
String compareDate = Long.toString(a1.getAlarmDate());
String thisDate = Long.toString(a2.getAlarmDate());
return thisDate.compareTo(compareDate);
}
});
return alertList; return alertList;
} }
@ -199,24 +221,40 @@ public class AlertDB extends SQLiteOpenHelper {
//given it is classified as unread //given it is classified as unread
//add it to alert list to be shown //add it to alert list to be shown
//and modify it in DB to be classified as shown //and modify it in DB to be classified as shown
int i = 0;
if (cursor.moveToFirst()) if (cursor.moveToFirst())
{ {
GregorianCalendar todayDate = new GregorianCalendar();
long currentDate = todayDate.getTimeInMillis();
do do
{ {
Alert alert = new Alert(); if(cursor.getInt(2) == 0 && currentDate >= cursor.getLong(1))
if(cursor.getInt(2) == 0)
{ {
Alert alert = new Alert();
alert.setMessage(cursor.getString(0)); alert.setMessage(cursor.getString(0));
alert.setAlarmDate(new Date(cursor.getLong(1))); alert.setAlarmDate(cursor.getLong(1));
alert.setShown(cursor.getInt(2)); alert.setShown(cursor.getInt(2));
updateAlert(alert); updateAlert(alert);
alertList.add(alert); alertList.add(alert);
i++;
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext() && i < 1);
} }
db.close(); db.close();
//sorts alerts by Date
Collections.sort(alertList, new Comparator<Alert>() {
@Override
public int compare(Alert a1, Alert a2) {
String compareDate = Long.toString(a1.getAlarmDate());
String thisDate = Long.toString(a2.getAlarmDate());
return thisDate.compareTo(compareDate);
}
});
return alertList; return alertList;
} }
@ -232,8 +270,7 @@ public class AlertDB extends SQLiteOpenHelper {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
long dateValue = alert.getAlarmDate().getTime(); values.put(KEY_ALARM_DATE, alert.getAlarmDate());
values.put(KEY_ALARM_DATE, dateValue);
values.put(KEY_SHOWN, 1); values.put(KEY_SHOWN, 1);
return db.update(TABLE_ALERTS, values, KEY_MESSAGE + " = ?", return db.update(TABLE_ALERTS, values, KEY_MESSAGE + " = ?",