mirror of
				https://github.com/bspeice/UNCCGameDay
				synced 2025-11-03 18:00:43 -05:00 
			
		
		
		
	Refactor, don't use the application context
This commit is contained in:
		@ -10,11 +10,8 @@ import com.uncc.gameday.R;
 | 
			
		||||
 | 
			
		||||
public class Alerts extends MenuActivity {
 | 
			
		||||
	
 | 
			
		||||
	Context ctx;
 | 
			
		||||
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
		this.ctx = getApplicationContext();
 | 
			
		||||
		setContentView(R.layout.activity_alerts);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@ -22,29 +19,29 @@ public class Alerts extends MenuActivity {
 | 
			
		||||
		int toastDuration = Toast.LENGTH_SHORT;
 | 
			
		||||
		if (((CheckBox) view).isChecked())
 | 
			
		||||
			// Enable Timed alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "Timed alerts enabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "Timed alerts enabled.", toastDuration).show();
 | 
			
		||||
		else
 | 
			
		||||
			// Disable Timed alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "Timed alerts disabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "Timed alerts disabled.", toastDuration).show();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onClickOrganizationAlerts(View view) {
 | 
			
		||||
		int toastDuration = Toast.LENGTH_SHORT;
 | 
			
		||||
		if (((CheckBox) view).isChecked())
 | 
			
		||||
			// Enable Organization alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "Organization alerts enabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "Organization alerts enabled.", toastDuration).show();
 | 
			
		||||
		else
 | 
			
		||||
			// Disable Organization alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "Organization alerts disabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "Organization alerts disabled.", toastDuration).show();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void onClickUniversityAlerts(View view) {
 | 
			
		||||
		int toastDuration = Toast.LENGTH_SHORT;
 | 
			
		||||
		if (((CheckBox) view).isChecked())
 | 
			
		||||
			// Enable University alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "University alerts enabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "University alerts enabled.", toastDuration).show();
 | 
			
		||||
		else
 | 
			
		||||
			// Disable University alerts
 | 
			
		||||
			Toast.makeText(this.ctx, "University alerts disabled.", toastDuration).show();
 | 
			
		||||
			Toast.makeText(this, "University alerts disabled.", toastDuration).show();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,22 +22,20 @@ public class Home extends MenuActivity {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
		setContentView(R.layout.activity_home);
 | 
			
		||||
		
 | 
			
		||||
		Context ctx = getApplicationContext();
 | 
			
		||||
		
 | 
			
		||||
		// 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);
 | 
			
		||||
		PendingIntent pendingAlertFetcher = PendingIntent.getService(this, 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
 | 
			
		||||
		this.onFirstRun(ctx);
 | 
			
		||||
		this.onFirstRun();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	protected void onFirstRun(Context ctx) {
 | 
			
		||||
	protected void onFirstRun() {
 | 
			
		||||
		SharedPreferences settings = this.getPreferences(MODE_PRIVATE);
 | 
			
		||||
		if (settings.getBoolean("FIRST_RUN", true)) {
 | 
			
		||||
			// First run code
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user