Commit cd10e967 authored by Ralph Morelli's avatar Ralph Morelli

Address issue #279 by putting MessageReceived back to a 2-argument event handler.

Change-Id: I17cf994329931142a714ac52ade4fe70aa96d48d
parent d8823ae7
...@@ -123,6 +123,7 @@ import android.widget.Toast; ...@@ -123,6 +123,7 @@ import android.widget.Toast;
private static final int SERVER_TIMEOUT_MS = 30000; private static final int SERVER_TIMEOUT_MS = 30000;
private static final String SENT = "SMS_SENT"; private static final String SENT = "SMS_SENT";
private static final String UTF8 = "UTF-8"; private static final String UTF8 = "UTF-8";
private static final String MESSAGE_DELIMITER = "\u0001";
// Google Voice oauth helper // Google Voice oauth helper
private GoogleVoiceUtil gvHelper; private GoogleVoiceUtil gvHelper;
...@@ -252,7 +253,7 @@ import android.widget.Toast; ...@@ -252,7 +253,7 @@ import android.widget.Toast;
* @param messageText the text of the message. * @param messageText the text of the message.
*/ */
@SimpleEvent @SimpleEvent
public static void MessageReceived(Context context, String number, String messageText) { public static void MessageReceived(String number, String messageText) {
if (receivingEnabled) { if (receivingEnabled) {
Log.i(TAG, "MessageReceived from " + number + ":" + messageText); Log.i(TAG, "MessageReceived from " + number + ":" + messageText);
if (EventDispatcher.dispatchEvent(component, "MessageReceived", number, messageText)) { if (EventDispatcher.dispatchEvent(component, "MessageReceived", number, messageText)) {
...@@ -260,7 +261,7 @@ import android.widget.Toast; ...@@ -260,7 +261,7 @@ import android.widget.Toast;
} else { } else {
Log.i(TAG, "Dispatch failed, caching"); Log.i(TAG, "Dispatch failed, caching");
synchronized (cacheLock) { synchronized (cacheLock) {
addMessageToCache(context, number, messageText); addMessageToCache(activity, number, messageText);
} }
} }
} }
...@@ -368,7 +369,7 @@ import android.widget.Toast; ...@@ -368,7 +369,7 @@ import android.widget.Toast;
// If receiving is not enabled, messages are not dispatched // If receiving is not enabled, messages are not dispatched
if (receivingEnabled && delim != -1) { if (receivingEnabled && delim != -1) {
MessageReceived(activity, phoneAndMessage.substring(0,delim), MessageReceived(phoneAndMessage.substring(0,delim),
phoneAndMessage.substring(delim+1)); phoneAndMessage.substring(delim+1));
} }
} }
...@@ -405,7 +406,7 @@ import android.widget.Toast; ...@@ -405,7 +406,7 @@ import android.widget.Toast;
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
String messagelist[] = cache.split("\n"); String messagelist[] = cache.split(MESSAGE_DELIMITER);
return messagelist; return messagelist;
} }
...@@ -455,7 +456,7 @@ import android.widget.Toast; ...@@ -455,7 +456,7 @@ import android.widget.Toast;
*/ */
public static void handledReceivedMessage(Context context, String phone, String msg) { public static void handledReceivedMessage(Context context, String phone, String msg) {
if (isRunning) { if (isRunning) {
MessageReceived(context, phone, msg); MessageReceived(phone, msg);
} else { } else {
synchronized (cacheLock) { synchronized (cacheLock) {
addMessageToCache(context, phone, msg); addMessageToCache(context, phone, msg);
...@@ -471,7 +472,7 @@ import android.widget.Toast; ...@@ -471,7 +472,7 @@ import android.widget.Toast;
*/ */
private static void addMessageToCache(Context context, String phone, String msg) { private static void addMessageToCache(Context context, String phone, String msg) {
try { try {
String cachedMsg = phone + ":" + msg + "\n"; String cachedMsg = phone + ":" + msg + MESSAGE_DELIMITER;
Log.i(TAG, "Caching " + cachedMsg); Log.i(TAG, "Caching " + cachedMsg);
FileOutputStream fos = context.openFileOutput(CACHE_FILE, Context.MODE_APPEND); FileOutputStream fos = context.openFileOutput(CACHE_FILE, Context.MODE_APPEND);
fos.write(cachedMsg.getBytes()); fos.write(cachedMsg.getBytes());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment