UNCCGameDay/src/com/uncc/gameday/alerts/AlertService.java

62 lines
1.6 KiB
Java
Raw Normal View History

2013-10-09 19:39:20 -04:00
package com.uncc.gameday.alerts;
2013-11-21 14:03:23 -05:00
import java.util.Date;
2013-10-09 20:20:04 -04:00
import java.util.List;
2013-10-09 19:39:20 -04:00
import android.app.IntentService;
import android.content.Intent;
2013-11-21 14:03:23 -05:00
import android.content.SharedPreferences;
2013-10-09 19:39:20 -04:00
public class AlertService extends IntentService {
private static final String name = "AlertService";
2013-11-21 14:03:23 -05:00
SharedPreferences prefs = null;
2013-10-09 19:39:20 -04:00
public AlertService() {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
// Go fetch all the alerts!
new AlertFetcher().fetchAlerts(this);
2013-11-21 14:03:23 -05:00
//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();
2013-10-09 20:20:04 -04:00
// And then display all of them!
for (Alert a: alerts) {
2013-10-09 20:42:44 -04:00
a.displayNotification(this);
2013-10-09 20:20:04 -04:00
}
2013-11-21 14:03:23 -05:00
2013-10-09 19:39:20 -04:00
}
2013-11-21 14:03:23 -05:00
//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);
}
2013-10-09 19:39:20 -04:00
}