Add lots more skeleton

This commit is contained in:
bspeice 2013-10-09 19:39:20 -04:00
parent e0f029f387
commit 9fc974402b
4 changed files with 89 additions and 91 deletions

View File

@ -1,13 +1,8 @@
package com.uncc.gameday.activities;
import java.util.List;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import com.uncc.gameday.R;
@ -20,12 +15,23 @@ public class Home extends MenuActivity {
setContentView(R.layout.activity_home);
Context ctx = getApplicationContext();
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();
}
}
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.
new AlertFetcher().fetchAlerts();
}
}

View File

@ -24,10 +24,11 @@ public class AlertDB {
// Add multiple new dates to the database
}
public List<Alert> fetchUnreadAlerts() {
// Get a list of all currently unread alerts
return null;
public void deleteAlert(Alert alert) {
// Remove a date from the database
}
public void deleteAlerts(List<Alert> alerts) {
// Remove multiple dates from the database
}
}

View File

@ -10,7 +10,7 @@ import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;
import android.util.Log;
import com.uncc.gameday.R;
@ -22,96 +22,69 @@ public class AlertFetcher {
public void fetchAlerts(Context ctx) {
// Fetch all alerts. Responsible for discovering what sources need to be fetched.
// Note we have to use the SharedPreferences so that we have preferences no matter what activity
// sent us this context
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
if (settings.getBoolean("ALERT_TIMED", false))
// Fetch timed alerts
this.fetchTimedAlerts(ctx);
else if (settings.getBoolean("ALERT_ORGANIZATION", false))
// Fetch organization alerts
this.fetchOrganizationAlerts(ctx);
else if (settings.getBoolean("ALERT_UNIVERSITY", false))
// Fetch university alerts
this.fetchUniversityAlerts(ctx);
// And always fetch alerts made by us. Period.
this.fetchGamedayAlerts(ctx);
try {
// Note we have to use the SharedPreferences so that we have preferences no matter what activity
// sent us this context
SharedPreferences settings = ctx.getSharedPreferences(ctx.getString(R.string.preferences_file), 0); // MODE_PRIVATE
if (settings.getBoolean("ALERT_ORGANIZATION", false))
// Fetch organization alerts
this.fetchOrganizationAlerts(ctx);
if (settings.getBoolean("ALERT_UNIVERSITY", false))
// Fetch university alerts
this.fetchUniversityAlerts(ctx);
// And always fetch alerts made by us. Period.
this.fetchGamedayAlerts(ctx);
} catch (TwitterException e) {
Log.w("AlertFetcher", "Unable to fetch alerts from Twitter...", e);
}
}
private void fetchTimedAlerts(Context ctx) {
// Process the rules for all timed alerts.
}
private void fetchOrganizationAlerts(Context ctx) {
private void fetchOrganizationAlerts(Context ctx) throws TwitterException {
// Process fetching organization alerts (alerts retweeted by us)
int duration = Toast.LENGTH_SHORT;
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
try {
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter for anything created by us (retweet)
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
// May need to switch to isRetweetByMe (documentation is awful)
if (!it.next().isRetweet())
it.remove();
}
// List contains all valid alerts now
} catch (TwitterException e) {
Toast.makeText(ctx,
"Unable to fetch alerts for organizations!\nAre you connected to the internet?",
duration).show();
e.printStackTrace();
// Filter for anything created by us (retweet)
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
// May need to switch to isRetweetByMe (documentation is awful)
if (!it.next().isRetweet())
it.remove();
}
// List contains all valid alerts now
}
private void fetchUniversityAlerts(Context ctx) {
private void fetchUniversityAlerts(Context ctx) throws TwitterException {
// Process fetching university alerts
int duration = Toast.LENGTH_SHORT;
String handle = ctx.getString(R.string.university_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
try {
String handle = ctx.getString(R.string.university_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// List contains all valid alerts now
} catch (TwitterException e) {
Toast.makeText(ctx,
"Unable to fetch alerts for the University!\nAre you connected to the internet?",
duration).show();
e.printStackTrace();
}
// List contains all valid alerts now
}
private void fetchGamedayAlerts(Context ctx) {
private void fetchGamedayAlerts(Context ctx) throws TwitterException {
// Process fetching alerts generated by staff of UNCCGameDay
int duration = Toast.LENGTH_SHORT;
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
try {
String handle = ctx.getString(R.string.gameday_handle);
Twitter twitter = TwitterFactory.getSingleton();
List<Status> statuses = twitter.getUserTimeline(handle, new Paging(1, maxTweets));
// Filter out anything not from us
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
// May need to switch to isRetweetByMe (documentation is awful)
if (it.next().isRetweet())
it.remove();
}
// List contains all valid alerts now.
} catch (TwitterException e) {
Toast.makeText(ctx,
"Unable to fetch alerts from Gameday!\nAre you connected to the internet?",
duration).show();
e.printStackTrace();
// Filter out anything not from us
for (Iterator<Status> it = statuses.iterator(); it.hasNext();){
// May need to switch to isRetweetByMe (documentation is awful)
if (it.next().isRetweet())
it.remove();
}
// List contains all valid alerts now.
}
public static List<Alert> createTimedAlerts(Context ctx) {
// Create the timed alerts so we can add or remove them from the DB
return null;
}
}

View File

@ -0,0 +1,18 @@
package com.uncc.gameday.alerts;
import android.app.IntentService;
import android.content.Intent;
public class AlertService extends IntentService {
private static final String name = "AlertService";
public AlertService() {
super(name);
}
@Override
protected void onHandleIntent(Intent intent) {
// Go fetch all the alerts!
}
}