2013-09-30 14:39:15 -04:00
|
|
|
package com.uncc.gameday.activities;
|
|
|
|
|
2013-10-04 21:43:36 -04:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import twitter4j.Paging;
|
|
|
|
import twitter4j.Status;
|
|
|
|
import twitter4j.Twitter;
|
|
|
|
import twitter4j.TwitterException;
|
|
|
|
import twitter4j.TwitterFactory;
|
|
|
|
|
2013-10-04 20:22:54 -04:00
|
|
|
import com.uncc.gameday.R;
|
|
|
|
|
2013-10-04 20:37:33 -04:00
|
|
|
import android.content.Context;
|
2013-10-04 20:22:54 -04:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.CheckBox;
|
2013-10-04 20:37:33 -04:00
|
|
|
import android.widget.Toast;
|
2013-09-30 14:23:13 -04:00
|
|
|
|
2013-10-03 18:35:39 -04:00
|
|
|
public class Alerts extends MenuActivity {
|
2013-10-04 20:37:33 -04:00
|
|
|
|
|
|
|
Context ctx;
|
2013-10-04 21:43:36 -04:00
|
|
|
int maxTweets = 5; // Most tweets at a time from any source
|
2013-09-30 14:23:13 -04:00
|
|
|
|
2013-10-04 20:22:54 -04:00
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2013-10-04 20:37:33 -04:00
|
|
|
this.ctx = getApplicationContext();
|
2013-10-04 20:22:54 -04:00
|
|
|
setContentView(R.layout.activity_alerts);
|
|
|
|
}
|
|
|
|
|
2013-10-04 21:17:50 -04:00
|
|
|
public void fetchAlerts() {
|
|
|
|
// Fetch all alerts. Responsible for discovering what sources need to be fetched.
|
|
|
|
|
|
|
|
if (((CheckBox)findViewById(R.id.alerts_check_timed)).isChecked())
|
|
|
|
// Fetch timed alerts
|
|
|
|
this.fetchTimedAlerts();
|
|
|
|
else if (((CheckBox)findViewById(R.id.alerts_check_organizations)).isChecked())
|
|
|
|
// Fetch organization alerts
|
|
|
|
this.fetchOrganizationAlerts();
|
|
|
|
else if (((CheckBox)findViewById(R.id.alerts_check_university)).isChecked())
|
|
|
|
// Fetch university alerts
|
|
|
|
this.fetchUniversityAlerts();
|
|
|
|
|
|
|
|
// And always fetch alerts made by us. Period.
|
|
|
|
this.fetchGamedayAlerts();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchTimedAlerts() {
|
|
|
|
// Process the rules for all timed alerts.
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchOrganizationAlerts() {
|
2013-10-04 21:43:36 -04:00
|
|
|
// Process fetching organization alerts (alerts retweeted by us)
|
|
|
|
int duration = Toast.LENGTH_SHORT;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String handle = 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(this.ctx, "Unable to fetch alerts for organizations!\nAre you connected to the internet?", duration).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchUniversityAlerts() {
|
|
|
|
// Process fetching university alerts
|
2013-10-04 21:43:36 -04:00
|
|
|
int duration = Toast.LENGTH_SHORT;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String handle = 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(this.ctx, "Unable to fetch alerts for the University!\nAre you connected to the internet?", duration).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchGamedayAlerts() {
|
|
|
|
// Process fetching alerts generated by staff of UNCCGameDay
|
2013-10-04 21:43:36 -04:00
|
|
|
int duration = Toast.LENGTH_SHORT;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String handle = 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(this.ctx, "Unable to fetch alerts from Gameday!\nAre you connected to the internet?", duration).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-04 21:17:50 -04:00
|
|
|
}
|
|
|
|
|
2013-10-04 20:22:54 -04:00
|
|
|
public void onClickTimedAlerts(View view) {
|
2013-10-04 20:37:33 -04:00
|
|
|
int toastDuration = Toast.LENGTH_SHORT;
|
2013-10-04 20:22:54 -04:00
|
|
|
if (((CheckBox) view).isChecked())
|
|
|
|
// Enable Timed alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "Timed alerts enabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
else
|
|
|
|
// Disable Timed alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "Timed alerts disabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onClickOrganizationAlerts(View view) {
|
2013-10-04 20:37:33 -04:00
|
|
|
int toastDuration = Toast.LENGTH_SHORT;
|
2013-10-04 20:22:54 -04:00
|
|
|
if (((CheckBox) view).isChecked())
|
|
|
|
// Enable Organization alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "Organization alerts enabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
else
|
|
|
|
// Disable Organization alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "Organization alerts disabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onClickUniversityAlerts(View view) {
|
2013-10-04 20:37:33 -04:00
|
|
|
int toastDuration = Toast.LENGTH_SHORT;
|
2013-10-04 20:22:54 -04:00
|
|
|
if (((CheckBox) view).isChecked())
|
|
|
|
// Enable University alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "University alerts enabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
else
|
|
|
|
// Disable University alerts
|
2013-10-04 20:37:33 -04:00
|
|
|
Toast.makeText(this.ctx, "University alerts disabled.", toastDuration).show();
|
2013-10-04 20:22:54 -04:00
|
|
|
}
|
2013-09-30 14:23:13 -04:00
|
|
|
}
|