package com.simplenote.android;

import com.simplenote.android.APIBase.Response;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			if (Constants.LOGGING) { Log.i(Constants.TAG, "Running Alarm!"); }

			APIHelper apiHelper = new APIHelper();
			Bundle bundle = intent.getExtras();
			String email = bundle.getString("email");
			String password = bundle.getString("password");

			String authBody = APIBase.encode( "email=" + email + "&password=" + password, true );
			Response authResponse = APIBase.HTTPPost( Constants.API_LOGIN_URL, authBody );

			if (authResponse.statusCode == 200) { // successful auth login
				if ( Constants.LOGGING ) { Log.i(Constants.TAG, "Login auth success with API server."); }
				String logInToken = authResponse.resp.replaceAll("(\\r|\\n)", "");
				apiHelper.refreshNotes(new NotesDbAdapter(context), logInToken, email);
			}
		} catch (Exception e) {
			Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_LONG).show();
			e.printStackTrace();
		}
	}
}
@@ -316,17 +316,16 @@
 eiver %7B%0A
-%0A
 %09@Overri
@@ -583,15 +583,25 @@
 ing(
-%22email%22
+Preferences.EMAIL
 );%0A%09
@@ -641,18 +641,28 @@
 ing(
-%22password%22
+Preferences.PASSWORD
 );%0A%0A
@@ -697,17 +697,16 @@
 .encode(
- 
 %22email=%22
@@ -745,17 +745,16 @@
 rd, true
- 
 );%0A%09%09%09Re
@@ -792,17 +792,16 @@
 TTPPost(
- 
 Constant
@@ -825,17 +825,16 @@
 authBody
- 
 );%0A%0A%09%09%09i
@@ -899,102 +899,8 @@
 gin%0A
-%09%09%09%09if ( Constants.LOGGING ) %7B Log.i(Constants.TAG, %22Login auth success with API server.%22); %7D%0A
 %09%09%09%09
@@ -1042,16 +1042,81 @@
 email);%0A
+%09%09%09%09Log.i(Constants.TAG, %22Login auth success with API server.%22);%0A
 %09%09%09%7D%0A%09%09%7D

Update AlarmReceiver to use constants in Preferences