package com.simplenote.android;

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

import com.simplenote.android.APIBase.Response;

public class AlarmReceiver extends BroadcastReceiver {
	private static final String LOGGING_TAG = Constants.TAG + "AlarmReceiver";

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			Log.i(LOGGING_TAG, "Running Alarm!");

			Bundle bundle = intent.getExtras();
			String email = bundle.getString(Preferences.EMAIL);
			String password = bundle.getString(Preferences.PASSWORD);

			Response authResponse = APIHelper.getLoginResponse(email,password);

			if (authResponse.statusCode == 200) { // successful auth login
				Log.i(Constants.TAG, "Login auth success with API server.");
				String token = authResponse.resp.replaceAll("(\\r|\\n)", "");
				APIHelper.refreshNotes(new NotesDbAdapter(context), token, email);
			} else if (authResponse.statusCode == 401) { // failed login
				// post a notification about failed sync due to credentials
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
@@ -176,65 +176,327 @@
 oid.
-util.Log;%0A%0Aimport com.simplenote.android.APIBase.Response
+os.Handler;%0Aimport android.os.Message;%0Aimport android.util.Log;%0A%0Aimport com.simplenote.android.net.Api.Response;%0Aimport com.simplenote.android.net.HttpCallback;%0Aimport com.simplenote.android.net.SimpleNoteApi;%0Aimport com.simplenote.android.persistence.SimpleNoteDao;%0Aimport com.simplenote.android.thread.SyncNotesThread
 ;%0A%0Ap
@@ -694,16 +694,72 @@
 tent) %7B%0A
+%09%09final SimpleNoteDao dao = new SimpleNoteDao(context);%0A
 %09%09try %7B%0A
@@ -803,16 +803,22 @@
 %22);%0A%0A%09%09%09
+final 
 Bundle b
@@ -844,24 +844,30 @@
 xtras();%0A%09%09%09
+final 
 String email
@@ -909,16 +909,22 @@
 IL);%0A%09%09%09
+final 
 String p
@@ -981,73 +981,43 @@
 %0A%09%09%09
-Response authResponse = APIHelper.getLoginResponse
+SimpleNoteApi.login
 (email,
+ 
 password
 );%0A%0A
@@ -1016,82 +1016,208 @@
 word
-);%0A%0A%09%09%09if (authResponse.statusCode == 200) %7B // successful auth login
+, new HttpCallback() %7B%0A%09%09%09%09/**%0A%09%09%09%09 * @see com.simplenote.android.net.HttpCallback#on200(com.simplenote.android.net.Api.Response)%0A%09%09%09%09 */%0A%09%09%09%09@Override%0A%09%09%09%09public void on200(Response response) %7B
 %0A%09%09%09%09
+%09
 Log.
@@ -1281,205 +1281,347 @@
 %09%09%09%09
+%09
 String 
-token = authResponse.resp.replaceAll(%22(%5C%5Cr%7C%5C%5Cn)%22, %22%22
+auth = response.body;%0A%09%09%09%09%09final Thread t = new SyncNotesThread(updateNoteHandler, dao, email, auth
 );%0A%09%09%09%09
+%09
-APIHelper.refreshNotes(new NotesDbAdapter(context), token, email);%0A%09%09%09%7D else if (authResponse.statusCode == 401) %7B // failed login%0A
+t.start();%0A%09%09%09%09%7D%0A%09%09%09%09/**%0A%09%09%09%09 * @see com.simplenote.android.net.HttpCallback#onError(com.simplenote.android.net.Api.Response)%0A%09%09%09%09 */%0A%09%09%09%09@Override%0A%09%09%09%09public void onError(Response response) %7B%0A%09%09%09%09%09super.onError(response);%0A%09
 %09%09%09%09
@@ -1683,18 +1683,26 @@
 ials%0A%09%09%09
+%09
 %7D%0A
+%09%09%09%7D);%0A
 %09%09%7D catc
@@ -1750,9 +1750,405 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09/**%0A%09 * Message handler which should _____ when a message with a Note is received%0A%09 */%0A%09private Handler updateNoteHandler = new Handler() %7B%0A%09%09/**%0A%09%09 * Messages are received from SyncNotesThread when a Note is updated or retrieved from the server%0A%09%09 * @see android.os.Handler#handleMessage(android.os.Message)%0A%09%09 */%0A%09%09@Override%0A%09%09public void handleMessage(Message msg) %7B%0A%09%09%09// do nothing%0A%09%09%7D%0A%09%7D;%0A
 %7D

Update to use new classes with same functionality