mirror of
https://github.com/bspeice/UNCCGameDay
synced 2024-11-05 07:38:13 -05:00
AlertDB being re-commited to Git
This commit is contained in:
parent
c6e0587f1d
commit
a06aa20207
@ -36,6 +36,7 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service android:name="com.uncc.gameday.alerts.AlertService"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
package com.uncc.gameday.activities;
|
package com.uncc.gameday.activities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.uncc.gameday.R;
|
import com.uncc.gameday.R;
|
||||||
|
import com.uncc.gameday.alerts.Alert;
|
||||||
|
import com.uncc.gameday.alerts.AlertDB;
|
||||||
import com.uncc.gameday.alerts.AlertService;
|
import com.uncc.gameday.alerts.AlertService;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
// TODO: Auto-generated Javadoc
|
||||||
@ -43,6 +49,28 @@ public class Home extends MenuActivity {
|
|||||||
|
|
||||||
// Double check if we need to do any first-run code
|
// Double check if we need to do any first-run code
|
||||||
this.onFirstRun();
|
this.onFirstRun();
|
||||||
|
|
||||||
|
this.displayList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void displayList()
|
||||||
|
{
|
||||||
|
|
||||||
|
List<Alert> alerts = new AlertDB(this).fetchAll();
|
||||||
|
|
||||||
|
String[] printArray = new String[alerts.size()];
|
||||||
|
|
||||||
|
//get message from each alert and put in printArray
|
||||||
|
for(int i = 0; i < alerts.size(); i++)
|
||||||
|
{
|
||||||
|
printArray[i] = alerts.get(i).getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView listView = (ListView)findViewById(R.id.alertsListView);
|
||||||
|
ArrayAdapter<String> adapter =
|
||||||
|
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, printArray);
|
||||||
|
listView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,99 +12,49 @@ import android.content.Intent;
|
|||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
|
||||||
* The Class Alert.
|
|
||||||
*/
|
|
||||||
public class Alert {
|
public class Alert {
|
||||||
|
|
||||||
/** The alarm date. */
|
|
||||||
private Date alarmDate;
|
private Date alarmDate;
|
||||||
|
|
||||||
/** The message. */
|
|
||||||
private String message;
|
private String message;
|
||||||
|
private int shown;
|
||||||
/** The shown. */
|
private String type;
|
||||||
private boolean shown;
|
|
||||||
|
|
||||||
// Default constructor
|
// Default constructor
|
||||||
/**
|
|
||||||
* Instantiates a new alert.
|
|
||||||
*/
|
|
||||||
public Alert(){}
|
public Alert(){}
|
||||||
|
|
||||||
/**
|
public Alert(Date alarmDate, String message, int shown, String type) {
|
||||||
* Instantiates a new alert.
|
|
||||||
*
|
|
||||||
* @param alarmDate the alarm date
|
|
||||||
* @param message the message
|
|
||||||
* @param shown the shown
|
|
||||||
*/
|
|
||||||
public Alert(Date alarmDate, String message, boolean shown) {
|
|
||||||
this.setAlarmDate(alarmDate);
|
this.setAlarmDate(alarmDate);
|
||||||
this.setMessage(message);
|
this.setMessage(message);
|
||||||
this.setShown(shown);
|
this.setShown(shown);
|
||||||
|
this.setType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void setType(String type) {
|
||||||
* Gets the alarm date.
|
this.type = type;
|
||||||
*
|
}
|
||||||
* @return the alarm date
|
|
||||||
*/
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
public Date getAlarmDate() {
|
public Date getAlarmDate() {
|
||||||
return alarmDate;
|
return alarmDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the alarm date.
|
|
||||||
*
|
|
||||||
* @param alarmDate the new alarm date
|
|
||||||
*/
|
|
||||||
public void setAlarmDate(Date alarmDate) {
|
public void setAlarmDate(Date alarmDate) {
|
||||||
this.alarmDate = alarmDate;
|
this.alarmDate = alarmDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the message.
|
|
||||||
*
|
|
||||||
* @return the message
|
|
||||||
*/
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the message.
|
|
||||||
*
|
|
||||||
* @param message the new message
|
|
||||||
*/
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
public int isShown() {
|
||||||
/**
|
|
||||||
* Checks if is shown.
|
|
||||||
*
|
|
||||||
* @return true, if is shown
|
|
||||||
*/
|
|
||||||
public boolean isShown() {
|
|
||||||
return shown;
|
return shown;
|
||||||
}
|
}
|
||||||
|
public void setShown(int i) {
|
||||||
/**
|
this.shown = i;
|
||||||
* Sets the shown.
|
|
||||||
*
|
|
||||||
* @param shown the new shown
|
|
||||||
*/
|
|
||||||
public void setShown(boolean shown) {
|
|
||||||
this.shown = shown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display notification.
|
|
||||||
*
|
|
||||||
* @param ctx the ctx
|
|
||||||
*/
|
|
||||||
public void displayNotification(Context ctx) {
|
public void displayNotification(Context ctx) {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
|
@ -1,72 +1,172 @@
|
|||||||
package com.uncc.gameday.alerts;
|
package com.uncc.gameday.alerts;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
/* Responsible for handling persistence/fetching of alerts */
|
/* Responsible for handling persistence/fetching of alerts */
|
||||||
|
|
||||||
/**
|
public class AlertDB extends SQLiteOpenHelper {
|
||||||
* The Class AlertDB.
|
|
||||||
*/
|
private static final int DATABASE_VERSION = 1;
|
||||||
public class AlertDB {
|
private static final String DATABASE_NAME = "AlertDataBase";
|
||||||
|
private static final String TABLE_ALERTS = "alerts";
|
||||||
|
|
||||||
/**
|
private static final String KEY_ALARM_DATE = "alarm_date";
|
||||||
* Persist.
|
private static final String KEY_MESSAGE = "message";
|
||||||
*
|
private static final String KEY_SHOWN = "shown";
|
||||||
* @param a the a
|
private static final String KEY_TYPE = "type";
|
||||||
*/
|
|
||||||
|
|
||||||
|
public AlertDB(Context context){
|
||||||
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
String CREATE_ALERTS_TABLE = "CREATE TABLE " + TABLE_ALERTS + "("
|
||||||
|
+ KEY_MESSAGE + " STRING PRIMARY KEY," + KEY_ALARM_DATE + " LONG,"
|
||||||
|
+ KEY_SHOWN + " INT," + KEY_TYPE + " STRING" + ")";
|
||||||
|
db.execSQL(CREATE_ALERTS_TABLE);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
//drop older table if it exists
|
||||||
|
db.execSQL("DROP OLDER TABLE " + TABLE_ALERTS);
|
||||||
|
|
||||||
|
//recreate tables
|
||||||
|
onCreate(db);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//persist alert into Database
|
||||||
public void persist(Alert a) {
|
public void persist(Alert a) {
|
||||||
|
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(KEY_MESSAGE, a.getMessage());
|
||||||
|
|
||||||
|
long dateValue = a.getAlarmDate().getTime();
|
||||||
|
values.put(KEY_ALARM_DATE, dateValue);
|
||||||
|
values.put(KEY_SHOWN, a.isShown());
|
||||||
|
values.put(KEY_TYPE, a.getType());
|
||||||
|
|
||||||
|
db.insert(TABLE_ALERTS, null, values);
|
||||||
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//persist list of alerts by looping through list
|
||||||
* Persist multiple.
|
//and calling persist
|
||||||
*
|
|
||||||
* @param alerts the alerts
|
|
||||||
*/
|
|
||||||
public void persistMultiple(List<Alert> alerts) {
|
public void persistMultiple(List<Alert> alerts) {
|
||||||
|
|
||||||
|
for(int i = 0; i < alerts.size(); i++)
|
||||||
|
{
|
||||||
|
persist(alerts.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch.
|
|
||||||
*
|
|
||||||
* @param d the d
|
|
||||||
* @return the alert
|
|
||||||
*/
|
|
||||||
public Alert fetch(Date d) {
|
public Alert fetch(Date d) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch multiple.
|
|
||||||
*
|
|
||||||
* @param dates the dates
|
|
||||||
* @return the list
|
|
||||||
*/
|
|
||||||
public List<Alert> fetchMultiple(List<Date> dates) {
|
public List<Alert> fetchMultiple(List<Date> dates) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch all.
|
//get all alerts from Database
|
||||||
*
|
//regardless of type, or if it has been shown
|
||||||
* @return the list
|
//update each alert in DB as being shown
|
||||||
*/
|
|
||||||
public List<Alert> fetchAll() {
|
public List<Alert> fetchAll() {
|
||||||
|
|
||||||
return null;
|
List<Alert> alertList = new ArrayList<Alert>();
|
||||||
|
|
||||||
|
String selectQuery = "SELECT * FROM " + TABLE_ALERTS;
|
||||||
|
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||||
|
|
||||||
|
//for each alert in database
|
||||||
|
//add it to alert list to be shown
|
||||||
|
//and modify it in DB to be classified as shown
|
||||||
|
if (cursor.moveToFirst())
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Alert alert = new Alert();
|
||||||
|
alert.setMessage(cursor.getString(0));
|
||||||
|
alert.setAlarmDate(new Date(cursor.getLong(1)));
|
||||||
|
alert.setShown(cursor.getInt(2));
|
||||||
|
updateAlert(alert);
|
||||||
|
|
||||||
|
alertList.add(alert);
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
|
}
|
||||||
|
db.close();
|
||||||
|
return alertList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
//fetch just unread alerts from database
|
||||||
* Fetch unread.
|
|
||||||
*
|
|
||||||
* @return the list
|
|
||||||
*/
|
|
||||||
public List<Alert> fetchUnread() {
|
public List<Alert> fetchUnread() {
|
||||||
return null;
|
|
||||||
|
List<Alert> alertList = new ArrayList<Alert>();
|
||||||
|
String selectQuery = "SELECT * FROM " + TABLE_ALERTS;
|
||||||
|
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||||
|
|
||||||
|
//for each alert in database
|
||||||
|
//given it is classified as unread
|
||||||
|
//add it to alert list to be shown
|
||||||
|
//and modify it in DB to be classified as shown
|
||||||
|
if (cursor.moveToFirst())
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
Alert alert = new Alert();
|
||||||
|
if(cursor.getInt(2) == 0)
|
||||||
|
{
|
||||||
|
alert.setMessage(cursor.getString(0));
|
||||||
|
alert.setAlarmDate(new Date(cursor.getLong(1)));
|
||||||
|
alert.setShown(cursor.getInt(2));
|
||||||
|
|
||||||
|
updateAlert(alert);
|
||||||
|
alertList.add(alert);
|
||||||
|
}
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
|
}
|
||||||
|
db.close();
|
||||||
|
return alertList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update alert in DB to be classified as shown
|
||||||
|
private int updateAlert(Alert alert) {
|
||||||
|
|
||||||
|
SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
|
||||||
|
long dateValue = alert.getAlarmDate().getTime();
|
||||||
|
values.put(KEY_ALARM_DATE, dateValue);
|
||||||
|
values.put(KEY_SHOWN, 1);
|
||||||
|
|
||||||
|
return db.update(TABLE_ALERTS, values, KEY_MESSAGE + " = ?",
|
||||||
|
new String[] { String.valueOf(alert.getMessage()) });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,109 +19,98 @@ import com.uncc.gameday.R;
|
|||||||
* The Class AlertFetcher.
|
* The Class AlertFetcher.
|
||||||
*/
|
*/
|
||||||
public class AlertFetcher {
|
public class AlertFetcher {
|
||||||
// Class responsible for fetching all alerts as necessary.
|
// Class responsible for fetching all alerts as necessary.
|
||||||
|
|
||||||
/** The max tweets. */
|
/** The max tweets. */
|
||||||
private int maxTweets = 5;
|
private int maxTweets = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch alerts.
|
* Fetch alerts.
|
||||||
*
|
*
|
||||||
* @param ctx the ctx
|
* @param ctx the ctx
|
||||||
*/
|
*/
|
||||||
public void fetchAlerts(Context ctx) {
|
public void fetchAlerts(Context ctx) {
|
||||||
// Fetch all alerts. Responsible for discovering what sources need to be fetched.
|
// Fetch all alerts. Responsible for discovering what sources need to be fetched.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Note we have to use the SharedPreferences so that we have preferences no matter what activity
|
// Note we have to use the SharedPreferences so that we have preferences no matter what activity
|
||||||
// sent us this context
|
// sent us this context
|
||||||
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
|
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
|
||||||
|
|
||||||
if (settings.getBoolean("ALERT_ORGANIZATION", false))
|
if (settings.getBoolean("ALERT_ORGANIZATION", false))
|
||||||
// Fetch organization alerts
|
// Fetch organization alerts
|
||||||
this.fetchOrganizationAlerts(ctx);
|
this.fetchOrganizationAlerts(ctx);
|
||||||
if (settings.getBoolean("ALERT_UNIVERSITY", false))
|
if (settings.getBoolean("ALERT_UNIVERSITY", false))
|
||||||
// Fetch university alerts
|
// Fetch university alerts
|
||||||
this.fetchUniversityAlerts(ctx);
|
this.fetchUniversityAlerts(ctx);
|
||||||
|
|
||||||
// And always fetch alerts made by us. Period.
|
// And always fetch alerts made by us. Period.
|
||||||
this.fetchGamedayAlerts(ctx);
|
this.fetchGamedayAlerts(ctx);
|
||||||
} catch (TwitterException e) {
|
} catch (TwitterException e) {
|
||||||
Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e);
|
Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch organization alerts.
|
* Fetch organization alerts.
|
||||||
*
|
*
|
||||||
* @param ctx the ctx
|
* @param ctx the ctx
|
||||||
* @throws TwitterException the twitter exception
|
* @throws TwitterException the twitter exception
|
||||||
*/
|
*/
|
||||||
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
|
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching organization alerts (alerts retweeted by us)
|
// Process fetching organization alerts (alerts retweeted by us)
|
||||||
// Will not necessarily fetch `maxTweets` tweets.
|
// Will not necessarily fetch `maxTweets` tweets.
|
||||||
String handle = ctx.getString(R.string.gameday_handle);
|
String handle = ctx.getString(R.string.gameday_handle);
|
||||||
Twitter twitter = TwitterFactory.getSingleton();
|
Twitter twitter = TwitterFactory.getSingleton();
|
||||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||||
|
|
||||||
// Filter for anything created by us (retweet)
|
// Filter for anything created by us (retweet)
|
||||||
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
|
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
|
||||||
// May need to switch to isRetweetByMe (documentation is awful)
|
// May need to switch to isRetweetByMe (documentation is awful)
|
||||||
if (!it.next().isRetweet())
|
if (!it.next().isRetweet())
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// List contains all valid alerts now
|
// List contains all valid alerts now
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch university alerts.
|
* Fetch university alerts.
|
||||||
*
|
*
|
||||||
* @param ctx the ctx
|
* @param ctx the ctx
|
||||||
* @throws TwitterException the twitter exception
|
* @throws TwitterException the twitter exception
|
||||||
*/
|
*/
|
||||||
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
|
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching university alerts
|
// Process fetching university alerts
|
||||||
// Guaranteed to get `maxTweets` tweets
|
// Guaranteed to get `maxTweets` tweets
|
||||||
String handle = ctx.getString(R.string.university_handle);
|
String handle = ctx.getString(R.string.university_handle);
|
||||||
Twitter twitter = TwitterFactory.getSingleton();
|
Twitter twitter = TwitterFactory.getSingleton();
|
||||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||||
|
|
||||||
// List contains all valid alerts now
|
// List contains all valid alerts now
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch gameday alerts.
|
* Fetch gameday alerts.
|
||||||
*
|
*
|
||||||
* @param ctx the ctx
|
* @param ctx the ctx
|
||||||
* @throws TwitterException the twitter exception
|
* @throws TwitterException the twitter exception
|
||||||
*/
|
*/
|
||||||
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
|
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
|
||||||
// Process fetching alerts generated by staff of UNCCGameDay
|
// Process fetching alerts generated by staff of UNCCGameDay
|
||||||
// Not guaranteed to get `maxTweets` tweets
|
// Not guaranteed to get `maxTweets` tweets
|
||||||
String handle = ctx.getString(R.string.gameday_handle);
|
String handle = ctx.getString(R.string.gameday_handle);
|
||||||
Twitter twitter = TwitterFactory.getSingleton();
|
Twitter twitter = TwitterFactory.getSingleton();
|
||||||
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
|
||||||
|
|
||||||
// Filter out anything not from us
|
// Filter out anything not from us
|
||||||
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
|
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
|
||||||
// May need to switch to isRetweetByMe (documentation is awful)
|
// May need to switch to isRetweetByMe (documentation is awful)
|
||||||
if (it.next().isRetweet())
|
if (it.next().isRetweet())
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// List contains all valid alerts now.
|
// List contains all valid alerts now.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Creates the timed alerts.
|
|
||||||
*
|
|
||||||
* @param ctx the ctx
|
|
||||||
* @return the list
|
|
||||||
*/
|
|
||||||
public static List<Alert> createTimedAlerts(Context ctx) {
|
|
||||||
// Create the timed alerts so we can add or remove them from the DB
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +1,61 @@
|
|||||||
package com.uncc.gameday.alerts;
|
package com.uncc.gameday.alerts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
// TODO: Auto-generated Javadoc
|
|
||||||
/**
|
|
||||||
* The Class AlertService.
|
|
||||||
*/
|
|
||||||
public class AlertService extends IntentService {
|
public class AlertService extends IntentService {
|
||||||
|
|
||||||
/** The Constant name. */
|
|
||||||
private static final String name = "AlertService";
|
private static final String name = "AlertService";
|
||||||
|
|
||||||
|
SharedPreferences prefs = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new alert service.
|
|
||||||
*/
|
|
||||||
public AlertService() {
|
public AlertService() {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see android.app.IntentService#onHandleIntent(android.content.Intent)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
// Go fetch all the alerts!
|
// Go fetch all the alerts!
|
||||||
new AlertFetcher().fetchAlerts(this);
|
//new AlertFetcher().fetchAlerts(this);
|
||||||
List<Alert> alerts = new AlertDB().fetchUnread();
|
|
||||||
|
//if first application run, create and store
|
||||||
|
//timed alerts into database
|
||||||
|
prefs = getSharedPreferences("com.uncc.gameday", MODE_PRIVATE);
|
||||||
|
if(prefs.getBoolean("firstrun", true)){
|
||||||
|
onFirstRun();
|
||||||
|
prefs.edit().putBoolean("firstrun", false).commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Alert> alerts = new AlertDB(this).fetchAll();
|
||||||
|
|
||||||
// And then display all of them!
|
// And then display all of them!
|
||||||
for (Alert a: alerts) {
|
for (Alert a: alerts) {
|
||||||
a.displayNotification(this);
|
a.displayNotification(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Creates timed alerts and adds them to AlertDB
|
||||||
|
//Only runs on first application startup
|
||||||
|
protected void onFirstRun()
|
||||||
|
{
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Alert a1 = new Alert(new Date(2003, 10, 10), "This is a test1", 0, AlertType.getValue(AlertType.ORGANIZATION));
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Alert b = new Alert(new Date(2003, 10, 10), "This is a test2", 0, AlertType.getValue(AlertType.GAMEDAY));
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
Alert c = new Alert(new Date(2003, 10, 10), "This is a test3", 0, AlertType.getValue(AlertType.TIMED));
|
||||||
|
|
||||||
|
AlertDB db = new AlertDB(this);
|
||||||
|
|
||||||
|
db.persist(a1);
|
||||||
|
db.persist(b);
|
||||||
|
db.persist(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
29
src/com/uncc/gameday/alerts/AlertType.java
Normal file
29
src/com/uncc/gameday/alerts/AlertType.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.uncc.gameday.alerts;
|
||||||
|
|
||||||
|
public enum AlertType {
|
||||||
|
|
||||||
|
TIMED ("TIMED"),
|
||||||
|
ORGANIZATION ("ORGANIZATION"),
|
||||||
|
UNIVERSITY ("UNIVERSITY"),
|
||||||
|
GAMEDAY ("GAMEDAY");
|
||||||
|
|
||||||
|
String type;
|
||||||
|
AlertType(String type) {this.type = type; }
|
||||||
|
public String getValue() { return type; }
|
||||||
|
|
||||||
|
|
||||||
|
public static String getValue(AlertType type)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case TIMED:
|
||||||
|
return "TIMED";
|
||||||
|
case ORGANIZATION:
|
||||||
|
return "ORGANIZATION";
|
||||||
|
case UNIVERSITY:
|
||||||
|
return "UNIVERSITY";
|
||||||
|
default:
|
||||||
|
return "GAMEDAY";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user