new notification service. first draft
This commit is contained in:
parent
1ae9338fc9
commit
bff23c2e23
|
@ -81,7 +81,7 @@ public class Conversation extends AbstractEntity {
|
||||||
int mode) {
|
int mode) {
|
||||||
this(java.util.UUID.randomUUID().toString(), name, null, account
|
this(java.util.UUID.randomUUID().toString(), name, null, account
|
||||||
.getUuid(), contactJid, System.currentTimeMillis(),
|
.getUuid(), contactJid, System.currentTimeMillis(),
|
||||||
STATUS_AVAILABLE, mode,"");
|
STATUS_AVAILABLE, mode, "");
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public class Conversation extends AbstractEntity {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
try {
|
try {
|
||||||
if (attributes==null) {
|
if (attributes == null) {
|
||||||
attributes = new String();
|
attributes = new String();
|
||||||
}
|
}
|
||||||
this.attributes = new JSONObject(attributes);
|
this.attributes = new JSONObject(attributes);
|
||||||
|
@ -214,7 +214,7 @@ public class Conversation extends AbstractEntity {
|
||||||
values.put(CREATED, created);
|
values.put(CREATED, created);
|
||||||
values.put(STATUS, status);
|
values.put(STATUS, status);
|
||||||
values.put(MODE, mode);
|
values.put(MODE, mode);
|
||||||
values.put(ATTRIBUTES,attributes.toString());
|
values.put(ATTRIBUTES, attributes.toString());
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +247,8 @@ public class Conversation extends AbstractEntity {
|
||||||
if (this.otrSession != null) {
|
if (this.otrSession != null) {
|
||||||
return this.otrSession;
|
return this.otrSession;
|
||||||
} else {
|
} else {
|
||||||
SessionID sessionId = new SessionID(
|
SessionID sessionId = new SessionID(this.getContactJid().split("/",
|
||||||
this.getContactJid().split("/",2)[0], presence, "xmpp");
|
2)[0], presence, "xmpp");
|
||||||
this.otrSession = new SessionImpl(sessionId, getAccount()
|
this.otrSession = new SessionImpl(sessionId, getAccount()
|
||||||
.getOtrEngine(service));
|
.getOtrEngine(service));
|
||||||
try {
|
try {
|
||||||
|
@ -479,7 +479,7 @@ public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
public int getIntAttribute(String key, int defaultValue) {
|
public int getIntAttribute(String key, int defaultValue) {
|
||||||
String value = this.getAttribute(key);
|
String value = this.getAttribute(key);
|
||||||
if (value==null) {
|
if (value == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPacket(PresencePacket packet, PgpEngine pgp) {
|
public void processPacket(PresencePacket packet, PgpEngine pgp) {
|
||||||
String[] fromParts = packet.getFrom().split("/",2);
|
String[] fromParts = packet.getFrom().split("/", 2);
|
||||||
if (fromParts.length >= 2) {
|
if (fromParts.length >= 2) {
|
||||||
String name = fromParts[1];
|
String name = fromParts[1];
|
||||||
String type = packet.getAttribute("type");
|
String type = packet.getAttribute("type");
|
||||||
|
@ -180,7 +180,7 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (type.equals("unavailable")) {
|
} else if (type.equals("unavailable")) {
|
||||||
deleteUser(packet.getAttribute("from").split("/",2)[1]);
|
deleteUser(packet.getAttribute("from").split("/", 2)[1]);
|
||||||
} else if (type.equals("error")) {
|
} else if (type.equals("error")) {
|
||||||
Element error = packet.findChild("error");
|
Element error = packet.findChild("error");
|
||||||
if (error.hasChild("conflict")) {
|
if (error.hasChild("conflict")) {
|
||||||
|
@ -209,7 +209,7 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProposedNick() {
|
public String getProposedNick() {
|
||||||
String[] mucParts = conversation.getContactJid().split("/",2);
|
String[] mucParts = conversation.getContactJid().split("/", 2);
|
||||||
if (conversation.getBookmark() != null
|
if (conversation.getBookmark() != null
|
||||||
&& conversation.getBookmark().getNick() != null) {
|
&& conversation.getBookmark().getNick() != null) {
|
||||||
return conversation.getBookmark().getNick();
|
return conversation.getBookmark().getNick();
|
||||||
|
@ -309,7 +309,7 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJoinJid() {
|
public String getJoinJid() {
|
||||||
return this.conversation.getContactJid().split("/",2)[0] + "/"
|
return this.conversation.getContactJid().split("/", 2)[0] + "/"
|
||||||
+ this.joinnick;
|
+ this.joinnick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,8 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
this.password = conversation.getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD);
|
this.password = conversation
|
||||||
|
.getAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD);
|
||||||
if (this.password == null && conversation.getBookmark() != null
|
if (this.password == null && conversation.getBookmark() != null
|
||||||
&& conversation.getBookmark().getPassword() != null) {
|
&& conversation.getBookmark().getPassword() != null) {
|
||||||
return conversation.getBookmark().getPassword();
|
return conversation.getBookmark().getPassword();
|
||||||
|
@ -339,7 +340,8 @@ public class MucOptions {
|
||||||
} else {
|
} else {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
conversation.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
|
conversation
|
||||||
|
.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPasswordChanged() {
|
public boolean isPasswordChanged() {
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
packet.setTo(message.getCounterpart());
|
packet.setTo(message.getCounterpart());
|
||||||
packet.setType(MessagePacket.TYPE_CHAT);
|
packet.setType(MessagePacket.TYPE_CHAT);
|
||||||
} else {
|
} else {
|
||||||
packet.setTo(message.getCounterpart().split("/",2)[0]);
|
packet.setTo(message.getCounterpart().split("/", 2)[0]);
|
||||||
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
||||||
}
|
}
|
||||||
packet.setFrom(account.getFullJid());
|
packet.setFrom(account.getFullJid());
|
||||||
|
@ -134,7 +134,7 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
String subject) {
|
String subject) {
|
||||||
MessagePacket packet = new MessagePacket();
|
MessagePacket packet = new MessagePacket();
|
||||||
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
packet.setType(MessagePacket.TYPE_GROUPCHAT);
|
||||||
packet.setTo(conversation.getContactJid().split("/",2)[0]);
|
packet.setTo(conversation.getContactJid().split("/", 2)[0]);
|
||||||
Element subjectChild = new Element("subject");
|
Element subjectChild = new Element("subject");
|
||||||
subjectChild.setContent(subject);
|
subjectChild.setContent(subject);
|
||||||
packet.addChild(subjectChild);
|
packet.addChild(subjectChild);
|
||||||
|
@ -148,13 +148,13 @@ public class MessageGenerator extends AbstractGenerator {
|
||||||
packet.setTo(contact);
|
packet.setTo(contact);
|
||||||
packet.setFrom(conversation.getAccount().getFullJid());
|
packet.setFrom(conversation.getAccount().getFullJid());
|
||||||
Element x = packet.addChild("x", "jabber:x:conference");
|
Element x = packet.addChild("x", "jabber:x:conference");
|
||||||
x.setAttribute("jid", conversation.getContactJid().split("/",2)[0]);
|
x.setAttribute("jid", conversation.getContactJid().split("/", 2)[0]);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagePacket invite(Conversation conversation, String contact) {
|
public MessagePacket invite(Conversation conversation, String contact) {
|
||||||
MessagePacket packet = new MessagePacket();
|
MessagePacket packet = new MessagePacket();
|
||||||
packet.setTo(conversation.getContactJid().split("/",2)[0]);
|
packet.setTo(conversation.getContactJid().split("/", 2)[0]);
|
||||||
packet.setFrom(conversation.getAccount().getFullJid());
|
packet.setFrom(conversation.getAccount().getFullJid());
|
||||||
Element x = new Element("x");
|
Element x = new Element("x");
|
||||||
x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");
|
x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user");
|
||||||
|
|
|
@ -60,7 +60,7 @@ public abstract class AbstractParser {
|
||||||
|
|
||||||
protected void updateLastseen(Element packet, Account account,
|
protected void updateLastseen(Element packet, Account account,
|
||||||
boolean presenceOverwrite) {
|
boolean presenceOverwrite) {
|
||||||
String[] fromParts = packet.getAttribute("from").split("/",2);
|
String[] fromParts = packet.getAttribute("from").split("/", 2);
|
||||||
String from = fromParts[0];
|
String from = fromParts[0];
|
||||||
String presence = null;
|
String presence = null;
|
||||||
if (fromParts.length >= 2) {
|
if (fromParts.length >= 2) {
|
||||||
|
|
|
@ -298,7 +298,8 @@ public class MessageParser extends AbstractParser implements
|
||||||
Element password = x.findChild("password");
|
Element password = x.findChild("password");
|
||||||
conversation.getMucOptions().setPassword(
|
conversation.getMucOptions().setPassword(
|
||||||
password.getContent());
|
password.getContent());
|
||||||
mXmppConnectionService.databaseBackend.updateConversation(conversation);
|
mXmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
}
|
}
|
||||||
mXmppConnectionService.joinMuc(conversation);
|
mXmppConnectionService.joinMuc(conversation);
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
|
@ -314,7 +315,8 @@ public class MessageParser extends AbstractParser implements
|
||||||
if (!conversation.getMucOptions().online()) {
|
if (!conversation.getMucOptions().online()) {
|
||||||
if (password != null) {
|
if (password != null) {
|
||||||
conversation.getMucOptions().setPassword(password);
|
conversation.getMucOptions().setPassword(password);
|
||||||
mXmppConnectionService.databaseBackend.updateConversation(conversation);
|
mXmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
}
|
}
|
||||||
mXmppConnectionService.joinMuc(conversation);
|
mXmppConnectionService.joinMuc(conversation);
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
|
@ -465,7 +467,10 @@ public class MessageParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notify = notify && !conversation.isMuted();
|
notify = notify && !conversation.isMuted();
|
||||||
mXmppConnectionService.notifyUi(conversation, notify);
|
if (notify) {
|
||||||
|
mXmppConnectionService.pushNotification(message);
|
||||||
|
}
|
||||||
|
mXmppConnectionService.updateConversationUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseHeadline(MessagePacket packet, Account account) {
|
private void parseHeadline(MessagePacket packet, Account account) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class PresenceParser extends AbstractParser implements
|
||||||
PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine();
|
PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine();
|
||||||
if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) {
|
if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) {
|
||||||
Conversation muc = mXmppConnectionService.find(account, packet
|
Conversation muc = mXmppConnectionService.find(account, packet
|
||||||
.getAttribute("from").split("/",2)[0]);
|
.getAttribute("from").split("/", 2)[0]);
|
||||||
if (muc != null) {
|
if (muc != null) {
|
||||||
boolean before = muc.getMucOptions().online();
|
boolean before = muc.getMucOptions().online();
|
||||||
muc.getMucOptions().processPacket(packet, mPgpEngine);
|
muc.getMucOptions().processPacket(packet, mPgpEngine);
|
||||||
|
@ -32,7 +32,7 @@ public class PresenceParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
|
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
|
||||||
Conversation muc = mXmppConnectionService.find(account, packet
|
Conversation muc = mXmppConnectionService.find(account, packet
|
||||||
.getAttribute("from").split("/",2)[0]);
|
.getAttribute("from").split("/", 2)[0]);
|
||||||
if (muc != null) {
|
if (muc != null) {
|
||||||
boolean before = muc.getMucOptions().online();
|
boolean before = muc.getMucOptions().online();
|
||||||
muc.getMucOptions().processPacket(packet, mPgpEngine);
|
muc.getMucOptions().processPacket(packet, mPgpEngine);
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
+ Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID
|
+ Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID
|
||||||
+ " TEXT, " + Conversation.CREATED + " NUMBER, "
|
+ " TEXT, " + Conversation.CREATED + " NUMBER, "
|
||||||
+ Conversation.STATUS + " NUMBER, " + Conversation.MODE
|
+ Conversation.STATUS + " NUMBER, " + Conversation.MODE
|
||||||
+ " NUMBER, "+Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY(" + Conversation.ACCOUNT
|
+ " NUMBER, " + Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY("
|
||||||
+ ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID
|
+ Conversation.ACCOUNT + ") REFERENCES " + Account.TABLENAME
|
||||||
+ ") ON DELETE CASCADE);");
|
+ "(" + Account.UUID + ") ON DELETE CASCADE);");
|
||||||
db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID
|
db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID
|
||||||
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
|
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
|
||||||
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
|
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
|
||||||
|
@ -228,10 +228,11 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public boolean hasEnabledAccounts() {
|
public boolean hasEnabledAccounts() {
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
Cursor cursor= db.rawQuery("select count("+Account.UUID+") from "+Account.TABLENAME+" where not options & (1 <<1)", null);
|
Cursor cursor = db.rawQuery("select count(" + Account.UUID + ") from "
|
||||||
|
+ Account.TABLENAME + " where not options & (1 <<1)", null);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
int count = cursor.getInt(0);
|
int count = cursor.getInt(0);
|
||||||
return (count>0);
|
return (count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,7 +15,8 @@ public class EventReceiver extends BroadcastReceiver {
|
||||||
} else {
|
} else {
|
||||||
mIntentForService.setAction("other");
|
mIntentForService.setAction("other");
|
||||||
}
|
}
|
||||||
if (intent.getAction().equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
|
if (intent.getAction().equals("ui")
|
||||||
|
|| DatabaseBackend.getInstance(context).hasEnabledAccounts()) {
|
||||||
context.startService(mIntentForService);
|
context.startService(mIntentForService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ImageProvider extends ContentProvider {
|
||||||
if (uuids == null) {
|
if (uuids == null) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
String[] uuidsSplited = uuids.split("/",2);
|
String[] uuidsSplited = uuids.split("/", 2);
|
||||||
if (uuidsSplited.length != 3) {
|
if (uuidsSplited.length != 3) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
165
src/eu/siacs/conversations/services/NotificationService.java
Normal file
165
src/eu/siacs/conversations/services/NotificationService.java
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
import android.text.Html;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.R;
|
||||||
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
import eu.siacs.conversations.ui.ConversationActivity;
|
||||||
|
|
||||||
|
public class NotificationService {
|
||||||
|
|
||||||
|
private XmppConnectionService mXmppConnectionService;
|
||||||
|
private NotificationManager mNotificationManager;
|
||||||
|
|
||||||
|
private LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<String, ArrayList<Message>>();
|
||||||
|
|
||||||
|
public int NOTIFICATION_ID = 0x2342;
|
||||||
|
|
||||||
|
public NotificationService(XmppConnectionService service) {
|
||||||
|
this.mXmppConnectionService = service;
|
||||||
|
this.mNotificationManager = (NotificationManager) service
|
||||||
|
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void push(Message message) {
|
||||||
|
String conversationUuid = message.getConversationUuid();
|
||||||
|
if (notifications.containsKey(conversationUuid)) {
|
||||||
|
notifications.get(conversationUuid).add(message);
|
||||||
|
} else {
|
||||||
|
ArrayList<Message> mList = new ArrayList<Message>();
|
||||||
|
mList.add(message);
|
||||||
|
notifications.put(conversationUuid, mList);
|
||||||
|
}
|
||||||
|
updateNotification(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
notifications.clear();
|
||||||
|
updateNotification(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(Conversation conversation) {
|
||||||
|
notifications.remove(conversation.getUuid());
|
||||||
|
updateNotification(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNotification(boolean notify) {
|
||||||
|
SharedPreferences preferences = mXmppConnectionService.getPreferences();
|
||||||
|
|
||||||
|
String ringtone = preferences.getString("notification_ringtone", null);
|
||||||
|
boolean vibrate = preferences.getBoolean("vibrate_on_notification",
|
||||||
|
true);
|
||||||
|
|
||||||
|
if (notifications.size() == 0) {
|
||||||
|
mNotificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
} else {
|
||||||
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
||||||
|
mXmppConnectionService);
|
||||||
|
mBuilder.setSmallIcon(R.drawable.ic_notification);
|
||||||
|
if (notifications.size() == 1) {
|
||||||
|
ArrayList<Message> messages = notifications.values().iterator()
|
||||||
|
.next();
|
||||||
|
if (messages.size() >= 1) {
|
||||||
|
Conversation conversation = messages.get(0)
|
||||||
|
.getConversation();
|
||||||
|
mBuilder.setLargeIcon(conversation.getImage(
|
||||||
|
mXmppConnectionService, 64));
|
||||||
|
mBuilder.setContentTitle(conversation.getName());
|
||||||
|
StringBuilder text = new StringBuilder();
|
||||||
|
for (int i = 0; i < messages.size(); ++i) {
|
||||||
|
text.append(messages.get(i).getReadableBody(
|
||||||
|
mXmppConnectionService));
|
||||||
|
if (i != messages.size() - 1) {
|
||||||
|
text.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mBuilder.setStyle(new NotificationCompat.BigTextStyle()
|
||||||
|
.bigText(text.toString()));
|
||||||
|
mBuilder.setContentText(messages.get(0).getReadableBody(
|
||||||
|
mXmppConnectionService));
|
||||||
|
mBuilder.setTicker(messages.get(messages.size() - 1)
|
||||||
|
.getReadableBody(mXmppConnectionService));
|
||||||
|
mBuilder.setContentIntent(createContentIntent(conversation
|
||||||
|
.getUuid()));
|
||||||
|
} else {
|
||||||
|
mNotificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
|
||||||
|
style.setBigContentTitle(notifications.size()
|
||||||
|
+ " "
|
||||||
|
+ mXmppConnectionService
|
||||||
|
.getString(R.string.unread_conversations));
|
||||||
|
StringBuilder names = new StringBuilder();
|
||||||
|
for (ArrayList<Message> messages : notifications.values()) {
|
||||||
|
if (messages.size() > 0) {
|
||||||
|
String name = messages.get(0).getConversation()
|
||||||
|
.getName();
|
||||||
|
style.addLine(Html.fromHtml("<b>"
|
||||||
|
+ name
|
||||||
|
+ "</b> "
|
||||||
|
+ messages.get(0).getReadableBody(
|
||||||
|
mXmppConnectionService)));
|
||||||
|
names.append(name);
|
||||||
|
names.append(", ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (names.length() >= 2) {
|
||||||
|
names.delete(names.length() - 2, names.length());
|
||||||
|
}
|
||||||
|
mBuilder.setContentTitle(notifications.size()
|
||||||
|
+ " "
|
||||||
|
+ mXmppConnectionService
|
||||||
|
.getString(R.string.unread_conversations));
|
||||||
|
mBuilder.setContentText(names.toString());
|
||||||
|
mBuilder.setStyle(style);
|
||||||
|
}
|
||||||
|
if (notify) {
|
||||||
|
if (vibrate) {
|
||||||
|
int dat = 70;
|
||||||
|
long[] pattern = { 0, 3 * dat, dat, dat };
|
||||||
|
mBuilder.setVibrate(pattern);
|
||||||
|
}
|
||||||
|
mBuilder.setLights(0xffffffff, 2000, 4000);
|
||||||
|
if (ringtone != null) {
|
||||||
|
mBuilder.setSound(Uri.parse(ringtone));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Notification notification = mBuilder.build();
|
||||||
|
mNotificationManager.notify(NOTIFICATION_ID, notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private PendingIntent createContentIntent(String conversationUuid) {
|
||||||
|
TaskStackBuilder stackBuilder = TaskStackBuilder
|
||||||
|
.create(mXmppConnectionService);
|
||||||
|
stackBuilder.addParentStack(ConversationActivity.class);
|
||||||
|
|
||||||
|
Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
||||||
|
ConversationActivity.class);
|
||||||
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
||||||
|
conversationUuid);
|
||||||
|
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
|
||||||
|
stackBuilder.addNextIntent(viewConversationIntent);
|
||||||
|
|
||||||
|
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
return resultPendingIntent;
|
||||||
|
}
|
||||||
|
}
|
|
@ -93,6 +93,8 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
private MemorizingTrustManager mMemorizingTrustManager;
|
private MemorizingTrustManager mMemorizingTrustManager;
|
||||||
|
|
||||||
|
private NotificationService mNotificationService;
|
||||||
|
|
||||||
private MessageParser mMessageParser = new MessageParser(this);
|
private MessageParser mMessageParser = new MessageParser(this);
|
||||||
private PresenceParser mPresenceParser = new PresenceParser(this);
|
private PresenceParser mPresenceParser = new PresenceParser(this);
|
||||||
private IqParser mIqParser = new IqParser(this);
|
private IqParser mIqParser = new IqParser(this);
|
||||||
|
@ -401,6 +403,7 @@ public class XmppConnectionService extends Service {
|
||||||
this.mRandom = new SecureRandom();
|
this.mRandom = new SecureRandom();
|
||||||
this.mMemorizingTrustManager = new MemorizingTrustManager(
|
this.mMemorizingTrustManager = new MemorizingTrustManager(
|
||||||
getApplicationContext());
|
getApplicationContext());
|
||||||
|
this.mNotificationService = new NotificationService(this);
|
||||||
this.databaseBackend = DatabaseBackend
|
this.databaseBackend = DatabaseBackend
|
||||||
.getInstance(getApplicationContext());
|
.getInstance(getApplicationContext());
|
||||||
this.fileBackend = new FileBackend(getApplicationContext());
|
this.fileBackend = new FileBackend(getApplicationContext());
|
||||||
|
@ -1268,7 +1271,7 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyUi(conversation, false);
|
updateConversationUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean renewSymmetricKey(Conversation conversation) {
|
public boolean renewSymmetricKey(Conversation conversation) {
|
||||||
|
@ -1577,15 +1580,6 @@ public class XmppConnectionService extends Service {
|
||||||
return getPreferences().getBoolean("indicate_received", false);
|
return getPreferences().getBoolean("indicate_received", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyUi(Conversation conversation, boolean notify) {
|
|
||||||
if (mOnConversationUpdate != null) {
|
|
||||||
mOnConversationUpdate.onConversationUpdate();
|
|
||||||
} else {
|
|
||||||
UIHelper.updateNotification(getApplicationContext(),
|
|
||||||
getConversations(), conversation, notify);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateConversationUi() {
|
public void updateConversationUi() {
|
||||||
if (mOnConversationUpdate != null) {
|
if (mOnConversationUpdate != null) {
|
||||||
mOnConversationUpdate.onConversationUpdate();
|
mOnConversationUpdate.onConversationUpdate();
|
||||||
|
@ -1624,6 +1618,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public void markRead(Conversation conversation) {
|
public void markRead(Conversation conversation) {
|
||||||
conversation.markRead();
|
conversation.markRead();
|
||||||
|
mNotificationService.clear(conversation);
|
||||||
String id = conversation.popLatestMarkableMessageId();
|
String id = conversation.popLatestMarkableMessageId();
|
||||||
if (confirmMessages() && id != null) {
|
if (confirmMessages() && id != null) {
|
||||||
Account account = conversation.getAccount();
|
Account account = conversation.getAccount();
|
||||||
|
@ -1758,4 +1753,8 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pushNotification(Message message) {
|
||||||
|
this.mNotificationService.push(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
|
||||||
private void populateView() {
|
private void populateView() {
|
||||||
mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48));
|
mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48));
|
||||||
setTitle(conversation.getName());
|
setTitle(conversation.getName());
|
||||||
mFullJid.setText(conversation.getContactJid().split("/",2)[0]);
|
mFullJid.setText(conversation.getContactJid().split("/", 2)[0]);
|
||||||
mYourNick.setText(conversation.getMucOptions().getActualNick());
|
mYourNick.setText(conversation.getMucOptions().getActualNick());
|
||||||
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
|
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);
|
||||||
if (conversation.getMucOptions().online()) {
|
if (conversation.getMucOptions().online()) {
|
||||||
|
|
|
@ -167,8 +167,6 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
if (!getSelectedConversation().isRead()) {
|
if (!getSelectedConversation().isRead()) {
|
||||||
xmppConnectionService
|
xmppConnectionService
|
||||||
.markRead(getSelectedConversation());
|
.markRead(getSelectedConversation());
|
||||||
UIHelper.updateNotification(getApplicationContext(),
|
|
||||||
getConversationList(), null, false);
|
|
||||||
listView.invalidateViews();
|
listView.invalidateViews();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +295,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
int which) {
|
int which) {
|
||||||
conversation
|
conversation
|
||||||
.setNextEncryption(Message.ENCRYPTION_NONE);
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
xmppConnectionService.databaseBackend.updateConversation(conversation);
|
xmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
selectPresenceToAttachFile(attachmentChoice);
|
selectPresenceToAttachFile(attachmentChoice);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -473,7 +472,8 @@ public class ConversationActivity extends XmppActivity implements
|
||||||
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xmppConnectionService.databaseBackend.updateConversation(conversation);
|
xmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
fragment.updateChatMsgHint();
|
fragment.updateChatMsgHint();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,10 +381,12 @@ public class ConversationFragment extends Fragment {
|
||||||
activity.getSlidingPaneLayout().closePane();
|
activity.getSlidingPaneLayout().closePane();
|
||||||
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
activity.getActionBar().setHomeButtonEnabled(true);
|
activity.getActionBar().setHomeButtonEnabled(true);
|
||||||
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
|
if (conversation.getMode() == Conversation.MODE_SINGLE
|
||||||
|
|| activity.useSubjectToIdentifyConference()) {
|
||||||
activity.getActionBar().setTitle(conversation.getName());
|
activity.getActionBar().setTitle(conversation.getName());
|
||||||
} else {
|
} else {
|
||||||
activity.getActionBar().setTitle(conversation.getContactJid().split("/")[0]);
|
activity.getActionBar().setTitle(
|
||||||
|
conversation.getContactJid().split("/")[0]);
|
||||||
}
|
}
|
||||||
activity.invalidateOptionsMenu();
|
activity.invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
@ -502,8 +504,6 @@ public class ConversationFragment extends Fragment {
|
||||||
updateChatMsgHint();
|
updateChatMsgHint();
|
||||||
if (!activity.shouldPaneBeOpen()) {
|
if (!activity.shouldPaneBeOpen()) {
|
||||||
activity.xmppConnectionService.markRead(conversation);
|
activity.xmppConnectionService.markRead(conversation);
|
||||||
UIHelper.updateNotification(getActivity(),
|
|
||||||
activity.getConversationList(), null, false);
|
|
||||||
activity.updateConversationList();
|
activity.updateConversationList();
|
||||||
}
|
}
|
||||||
this.updateSendButton();
|
this.updateSendButton();
|
||||||
|
@ -668,7 +668,8 @@ public class ConversationFragment extends Fragment {
|
||||||
int which) {
|
int which) {
|
||||||
conversation
|
conversation
|
||||||
.setNextEncryption(Message.ENCRYPTION_NONE);
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
xmppService.databaseBackend.updateConversation(conversation);
|
xmppService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
message.setEncryption(Message.ENCRYPTION_NONE);
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
xmppService.sendMessage(message);
|
xmppService.sendMessage(message);
|
||||||
messageSent();
|
messageSent();
|
||||||
|
@ -697,7 +698,8 @@ public class ConversationFragment extends Fragment {
|
||||||
conversation
|
conversation
|
||||||
.setNextEncryption(Message.ENCRYPTION_NONE);
|
.setNextEncryption(Message.ENCRYPTION_NONE);
|
||||||
message.setEncryption(Message.ENCRYPTION_NONE);
|
message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
xmppService.databaseBackend.updateConversation(conversation);
|
xmppService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
xmppService.sendMessage(message);
|
xmppService.sendMessage(message);
|
||||||
messageSent();
|
messageSent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class SettingsActivity extends XmppActivity implements
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mSettingsFragment = new SettingsFragment();
|
mSettingsFragment = new SettingsFragment();
|
||||||
getFragmentManager().beginTransaction()
|
getFragmentManager().beginTransaction()
|
||||||
.replace(android.R.id.content,mSettingsFragment).commit();
|
.replace(android.R.id.content, mSettingsFragment).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,12 +34,16 @@ public class SettingsActivity extends XmppActivity implements
|
||||||
super.onStart();
|
super.onStart();
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
.registerOnSharedPreferenceChangeListener(this);
|
.registerOnSharedPreferenceChangeListener(this);
|
||||||
ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource");
|
ListPreference resources = (ListPreference) mSettingsFragment
|
||||||
if (resources!=null) {
|
.findPreference("resource");
|
||||||
ArrayList<CharSequence> entries = new ArrayList<CharSequence>(Arrays.asList(resources.getEntries()));
|
if (resources != null) {
|
||||||
entries.add(0,Build.MODEL);
|
ArrayList<CharSequence> entries = new ArrayList<CharSequence>(
|
||||||
resources.setEntries(entries.toArray(new CharSequence[entries.size()]));
|
Arrays.asList(resources.getEntries()));
|
||||||
resources.setEntryValues(entries.toArray(new CharSequence[entries.size()]));
|
entries.add(0, Build.MODEL);
|
||||||
|
resources.setEntries(entries.toArray(new CharSequence[entries
|
||||||
|
.size()]));
|
||||||
|
resources.setEntryValues(entries.toArray(new CharSequence[entries
|
||||||
|
.size()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,7 +326,7 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
.findViewById(R.id.jid);
|
.findViewById(R.id.jid);
|
||||||
jid.setAdapter(new KnownHostsAdapter(this,
|
jid.setAdapter(new KnownHostsAdapter(this,
|
||||||
android.R.layout.simple_list_item_1, mKnownHosts));
|
android.R.layout.simple_list_item_1, mKnownHosts));
|
||||||
if (prefilledJid!=null) {
|
if (prefilledJid != null) {
|
||||||
jid.append(prefilledJid);
|
jid.append(prefilledJid);
|
||||||
}
|
}
|
||||||
populateAccountSpinner(spinner);
|
populateAccountSpinner(spinner);
|
||||||
|
@ -536,7 +536,8 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
setIntent(null);
|
setIntent(null);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) {
|
} else if (getIntent() != null
|
||||||
|
&& Intent.ACTION_VIEW.equals(getIntent().getAction())) {
|
||||||
Uri uri = getIntent().getData();
|
Uri uri = getIntent().getData();
|
||||||
String jid = uri.getSchemeSpecificPart().split("\\?")[0];
|
String jid = uri.getSchemeSpecificPart().split("\\?")[0];
|
||||||
return handleJid(jid);
|
return handleJid(jid);
|
||||||
|
@ -545,8 +546,7 @@ public class StartConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleJid(String jid) {
|
private boolean handleJid(String jid) {
|
||||||
List<Contact> contacts = xmppConnectionService
|
List<Contact> contacts = xmppConnectionService.findContacts(jid);
|
||||||
.findContacts(jid);
|
|
||||||
if (contacts.size() == 0) {
|
if (contacts.size() == 0) {
|
||||||
showCreateContactDialog(jid);
|
showCreateContactDialog(jid);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -294,7 +294,8 @@ public abstract class XmppActivity extends Activity {
|
||||||
if (conversation != null) {
|
if (conversation != null) {
|
||||||
conversation
|
conversation
|
||||||
.setNextEncryption(Message.ENCRYPTION_PGP);
|
.setNextEncryption(Message.ENCRYPTION_PGP);
|
||||||
xmppConnectionService.databaseBackend.updateConversation(conversation);
|
xmppConnectionService.databaseBackend
|
||||||
|
.updateConversation(conversation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
|
||||||
}
|
}
|
||||||
TextView convName = (TextView) view
|
TextView convName = (TextView) view
|
||||||
.findViewById(R.id.conversation_name);
|
.findViewById(R.id.conversation_name);
|
||||||
if (conv.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
|
if (conv.getMode() == Conversation.MODE_SINGLE
|
||||||
|
|| activity.useSubjectToIdentifyConference()) {
|
||||||
convName.setText(conv.getName());
|
convName.setText(conv.getName());
|
||||||
} else {
|
} else {
|
||||||
convName.setText(conv.getContactJid().split("/")[0]);
|
convName.setText(conv.getContactJid().split("/")[0]);
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class UIHelper {
|
||||||
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
|
Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updateNotification(Context context,
|
private static void updateNotification(Context context,
|
||||||
List<Conversation> conversations, Conversation currentCon,
|
List<Conversation> conversations, Conversation currentCon,
|
||||||
boolean notify) {
|
boolean notify) {
|
||||||
NotificationManager mNotificationManager = (NotificationManager) context
|
NotificationManager mNotificationManager = (NotificationManager) context
|
||||||
|
|
|
@ -657,7 +657,7 @@ public class XmppConnection implements Runnable {
|
||||||
if (bind != null) {
|
if (bind != null) {
|
||||||
Element jid = bind.findChild("jid");
|
Element jid = bind.findChild("jid");
|
||||||
if (jid != null && jid.getContent() != null) {
|
if (jid != null && jid.getContent() != null) {
|
||||||
account.setResource(jid.getContent().split("/",2)[1]);
|
account.setResource(jid.getContent().split("/", 2)[1]);
|
||||||
if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) {
|
if (streamFeatures.hasChild("sm", "urn:xmpp:sm:3")) {
|
||||||
smVersion = 3;
|
smVersion = 3;
|
||||||
EnablePacket enable = new EnablePacket(smVersion);
|
EnablePacket enable = new EnablePacket(smVersion);
|
||||||
|
|
|
@ -88,8 +88,8 @@ public class JingleConnection implements Downloadable {
|
||||||
sendSuccess();
|
sendSuccess();
|
||||||
if (acceptedAutomatically) {
|
if (acceptedAutomatically) {
|
||||||
message.markUnread();
|
message.markUnread();
|
||||||
JingleConnection.this.mXmppConnectionService.notifyUi(
|
JingleConnection.this.mXmppConnectionService
|
||||||
message.getConversation(), true);
|
.pushNotification(message);
|
||||||
}
|
}
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
|
@ -256,12 +256,12 @@ public class JingleConnection implements Downloadable {
|
||||||
this.status = STATUS_INITIATED;
|
this.status = STATUS_INITIATED;
|
||||||
Conversation conversation = this.mXmppConnectionService
|
Conversation conversation = this.mXmppConnectionService
|
||||||
.findOrCreateConversation(account,
|
.findOrCreateConversation(account,
|
||||||
packet.getFrom().split("/",2)[0], false);
|
packet.getFrom().split("/", 2)[0], false);
|
||||||
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
|
this.message = new Message(conversation, "", Message.ENCRYPTION_NONE);
|
||||||
this.message.setType(Message.TYPE_IMAGE);
|
this.message.setType(Message.TYPE_IMAGE);
|
||||||
this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
|
this.message.setStatus(Message.STATUS_RECEIVED_OFFER);
|
||||||
this.message.setDownloadable(this);
|
this.message.setDownloadable(this);
|
||||||
String[] fromParts = packet.getFrom().split("/",2);
|
String[] fromParts = packet.getFrom().split("/", 2);
|
||||||
this.message.setPresence(fromParts[1]);
|
this.message.setPresence(fromParts[1]);
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.initiator = packet.getFrom();
|
this.initiator = packet.getFrom();
|
||||||
|
@ -319,8 +319,7 @@ public class JingleConnection implements Downloadable {
|
||||||
+ " allowed size:"
|
+ " allowed size:"
|
||||||
+ this.mJingleConnectionManager
|
+ this.mJingleConnectionManager
|
||||||
.getAutoAcceptFileSize());
|
.getAutoAcceptFileSize());
|
||||||
this.mXmppConnectionService
|
this.mXmppConnectionService.pushNotification(message);
|
||||||
.notifyUi(conversation, true);
|
|
||||||
}
|
}
|
||||||
this.file = this.mXmppConnectionService.getFileBackend()
|
this.file = this.mXmppConnectionService.getFileBackend()
|
||||||
.getJingleFile(message, false);
|
.getJingleFile(message, false);
|
||||||
|
|
Loading…
Reference in a new issue