2013-10-01 19:39:20 -04:00
|
|
|
package com.uncc.gameday.activities;
|
|
|
|
|
2013-10-09 20:20:04 -04:00
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.PendingIntent;
|
2013-10-04 21:17:50 -04:00
|
|
|
import android.content.Context;
|
2013-10-09 20:20:04 -04:00
|
|
|
import android.content.Intent;
|
2013-10-09 19:39:20 -04:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.SharedPreferences.Editor;
|
2013-10-04 21:17:50 -04:00
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
|
|
import com.uncc.gameday.R;
|
2013-10-07 14:20:20 -04:00
|
|
|
import com.uncc.gameday.alerts.AlertFetcher;
|
2013-10-09 20:20:04 -04:00
|
|
|
import com.uncc.gameday.alerts.AlertService;
|
2013-10-01 19:39:20 -04:00
|
|
|
|
2013-10-04 21:17:50 -04:00
|
|
|
public class Home extends MenuActivity {
|
|
|
|
|
2013-10-09 20:20:04 -04:00
|
|
|
private final long alarmRate = 300000; // 5 Minutes
|
|
|
|
|
2013-10-04 21:17:50 -04:00
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_home);
|
|
|
|
|
|
|
|
Context ctx = getApplicationContext();
|
2013-10-09 20:20:04 -04:00
|
|
|
|
|
|
|
// Start up the AlarmManager to fetch alerts in the background
|
|
|
|
AlarmManager am = (AlarmManager) this.getSystemService(ALARM_SERVICE);
|
|
|
|
Intent alertFetcher = new Intent(this, AlertService.class);
|
|
|
|
PendingIntent pendingAlertFetcher = PendingIntent.getService(ctx, 0, alertFetcher, 0);
|
|
|
|
|
|
|
|
// Cancel any previous alarm managers, and start the new one
|
|
|
|
am.cancel(pendingAlertFetcher);
|
|
|
|
am.setRepeating(0, this.alarmRate, this.alarmRate, pendingAlertFetcher);
|
|
|
|
|
|
|
|
// Double check if we need to do any first-run code
|
2013-10-09 19:39:20 -04:00
|
|
|
this.onFirstRun(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void onFirstRun(Context ctx) {
|
|
|
|
SharedPreferences settings = this.getPreferences(MODE_PRIVATE);
|
|
|
|
if (settings.getBoolean("FIRST_RUN", true)) {
|
|
|
|
// First run code
|
|
|
|
|
|
|
|
Editor editor = settings.edit();
|
|
|
|
editor.putBoolean("FIRST_RUN", false);
|
|
|
|
editor.commit();
|
|
|
|
}
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void getRecentAlerts() {
|
|
|
|
// Responsible for discovering what the most recent alerts are and showing them.
|
|
|
|
// Likely should be implemented by querying a local DB of alerts, grabbing recent 20.
|
2013-10-09 19:39:20 -04:00
|
|
|
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
2013-10-01 19:39:20 -04:00
|
|
|
}
|