mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-11-05 07:38:13 -05:00
Further Alert cleanup >AGK
This commit is contained in:
parent
33afb534bd
commit
06f7c7933f
@ -1,7 +1,10 @@
|
||||
package com.uncc.gameday.alerts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.ContentValues;
|
||||
@ -84,8 +87,8 @@ public class AlertDB extends SQLiteOpenHelper {
|
||||
ContentValues values = new ContentValues();
|
||||
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_TYPE, a.getType());
|
||||
|
||||
@ -108,6 +111,7 @@ public class AlertDB extends SQLiteOpenHelper {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch an alert by date
|
||||
* 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
|
||||
*/
|
||||
@ -164,21 +166,41 @@ public class AlertDB extends SQLiteOpenHelper {
|
||||
//for each alert in database
|
||||
//add it to alert list to be shown
|
||||
//and modify it in DB to be classified as shown
|
||||
int i = 0;
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
|
||||
GregorianCalendar todayDate = new GregorianCalendar();
|
||||
long currentDate = todayDate.getTimeInMillis();
|
||||
|
||||
do
|
||||
{
|
||||
if(currentDate >= cursor.getLong(1))
|
||||
{
|
||||
Alert alert = new Alert();
|
||||
alert.setMessage(cursor.getString(0));
|
||||
alert.setAlarmDate(new Date(cursor.getLong(1)));
|
||||
alert.setAlarmDate(cursor.getLong(1));
|
||||
alert.setShown(cursor.getInt(2));
|
||||
updateAlert(alert);
|
||||
|
||||
alertList.add(alert);
|
||||
} while (cursor.moveToNext());
|
||||
i++;
|
||||
}
|
||||
} while (cursor.moveToNext() && i < 10);
|
||||
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -199,24 +221,40 @@ public class AlertDB extends SQLiteOpenHelper {
|
||||
//given it is classified as unread
|
||||
//add it to alert list to be shown
|
||||
//and modify it in DB to be classified as shown
|
||||
int i = 0;
|
||||
if (cursor.moveToFirst())
|
||||
{
|
||||
|
||||
GregorianCalendar todayDate = new GregorianCalendar();
|
||||
long currentDate = todayDate.getTimeInMillis();
|
||||
do
|
||||
{
|
||||
Alert alert = new Alert();
|
||||
if(cursor.getInt(2) == 0)
|
||||
if(cursor.getInt(2) == 0 && currentDate >= cursor.getLong(1))
|
||||
{
|
||||
Alert alert = new Alert();
|
||||
alert.setMessage(cursor.getString(0));
|
||||
alert.setAlarmDate(new Date(cursor.getLong(1)));
|
||||
alert.setAlarmDate(cursor.getLong(1));
|
||||
alert.setShown(cursor.getInt(2));
|
||||
|
||||
updateAlert(alert);
|
||||
alertList.add(alert);
|
||||
i++;
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
|
||||
} while (cursor.moveToNext() && i < 1);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -232,8 +270,7 @@ public class AlertDB extends SQLiteOpenHelper {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
long dateValue = alert.getAlarmDate().getTime();
|
||||
values.put(KEY_ALARM_DATE, dateValue);
|
||||
values.put(KEY_ALARM_DATE, alert.getAlarmDate());
|
||||
values.put(KEY_SHOWN, 1);
|
||||
|
||||
return db.update(TABLE_ALERTS, values, KEY_MESSAGE + " = ?",
|
||||
|
Loading…
Reference in New Issue
Block a user