Send notification to Pebble on new message
This implements basic notifications to the Pebble through the app (using an intent). This simply hooks into NotificationService.notify(). This is pretty basic, but it works (I haven't tested to see how the intent is received when the Pebble app is not around, though). More fancy stuff could probably be added to avoid getting flooded, but the Pebble app already does a good job a filtering notification (e.g., screen on or quiet times). Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
parent
2723c9ccb9
commit
f1ebece866
|
@ -21,11 +21,15 @@ import android.util.Log;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
@ -65,6 +69,24 @@ public class NotificationService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notifyPebble(Message message) {
|
||||||
|
final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION");
|
||||||
|
|
||||||
|
final HashMap data = new HashMap();
|
||||||
|
final Conversation conversation = message.getConversation();
|
||||||
|
data.put("title", conversation.getName());
|
||||||
|
data.put("body", message.getBody());
|
||||||
|
final JSONObject jsonData = new JSONObject(data);
|
||||||
|
final String notificationData = new JSONArray().put(jsonData).toString();
|
||||||
|
|
||||||
|
i.putExtra("messageType", "PEBBLE_ALERT");
|
||||||
|
i.putExtra("sender", "Conversations"); /* XXX: Shouldn't be hardcoded, e.g., AbstractGenerator.APP_NAME); */
|
||||||
|
i.putExtra("notificationData", notificationData);
|
||||||
|
|
||||||
|
mXmppConnectionService.sendBroadcast(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean notificationsEnabled() {
|
public boolean notificationsEnabled() {
|
||||||
return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
|
return mXmppConnectionService.getPreferences().getBoolean("show_notification", true);
|
||||||
}
|
}
|
||||||
|
@ -110,9 +132,13 @@ public class NotificationService {
|
||||||
notifications.put(conversationUuid, mList);
|
notifications.put(conversationUuid, mList);
|
||||||
}
|
}
|
||||||
final Account account = message.getConversation().getAccount();
|
final Account account = message.getConversation().getAccount();
|
||||||
updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
|
||||||
&& !account.inGracePeriod()
|
&& !account.inGracePeriod()
|
||||||
&& !this.inMiniGracePeriod(account));
|
&& !this.inMiniGracePeriod(account);
|
||||||
|
updateNotification(doNotify);
|
||||||
|
if (doNotify) {
|
||||||
|
notifyPebble(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue