diff options
27 files changed, 369 insertions, 323 deletions
diff --git a/res/layout/message_received.xml b/res/layout/message_received.xml index 28c04a707..730d00d53 100644 --- a/res/layout/message_received.xml +++ b/res/layout/message_received.xml @@ -54,7 +54,7 @@ android:text="@string/download_image" android:visibility="gone" /> - <LinearLayout + <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" @@ -65,12 +65,10 @@ android:layout_width="?attr/TextSizeInfo" android:layout_height="?attr/TextSizeInfo" android:layout_gravity="center_vertical" - android:gravity="center_vertical" - android:src="@drawable/ic_secure_indicator" android:layout_marginRight="4sp" - android:alpha="0.54"/> - - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_secure_indicator" /> <TextView android:id="@+id/message_time" diff --git a/res/layout/message_sent.xml b/res/layout/message_sent.xml index 9167012a7..28f3ddc63 100644 --- a/res/layout/message_sent.xml +++ b/res/layout/message_sent.xml @@ -63,27 +63,25 @@ android:textColor="@color/secondarytext" android:textSize="?attr/TextSizeInfo" /> - <ImageView + <ImageView android:id="@+id/security_indicator" android:layout_width="?attr/TextSizeInfo" android:layout_height="?attr/TextSizeInfo" android:layout_gravity="center_vertical" - android:gravity="center_vertical" - android:src="@drawable/ic_secure_indicator" android:layout_marginLeft="4sp" - android:alpha="0.54"/> - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_secure_indicator" /> + <ImageView android:id="@+id/indicator_received" android:layout_width="?attr/TextSizeInfo" android:layout_height="?attr/TextSizeInfo" android:layout_gravity="center_vertical" - android:gravity="center_vertical" - android:src="@drawable/ic_received_indicator" android:layout_marginLeft="4sp" - android:alpha="0.54"/> - - + android:alpha="0.54" + android:gravity="center_vertical" + android:src="@drawable/ic_received_indicator" /> </LinearLayout> </LinearLayout> </LinearLayout> @@ -99,4 +97,4 @@ android:scaleType="fitXY" android:src="@drawable/ic_profile" /> -</RelativeLayout> +</RelativeLayout>
\ No newline at end of file diff --git a/res/values-eu/arrays.xml b/res/values-eu/arrays.xml index cb1c20fd7..a34d3c6a9 100644 --- a/res/values-eu/arrays.xml +++ b/res/values-eu/arrays.xml @@ -26,8 +26,9 @@ <item>2 ordu</item> <item>8 ordu</item> <item>abisatu arte</item> - </string-array> - <integer-array name="mute_options_durations"> + </string-array> + + <integer-array name="mute_options_durations"> <item>1800</item> <item>3600</item> <item>7200</item> @@ -35,4 +36,4 @@ <item>-1</item> </integer-array> -</resources> +</resources>
\ No newline at end of file diff --git a/res/values-eu/strings.xml b/res/values-eu/strings.xml index 727372849..4d3522fd4 100644 --- a/res/values-eu/strings.xml +++ b/res/values-eu/strings.xml @@ -256,5 +256,5 @@ <string name="pref_use_larger_font_summary">Letra tamaina handiagoa erabili aplikazio osoan zehar</string> <string name="pref_use_send_button_to_indicate_status">Bidaltze botoiak egoera adierazten du</string> <string name="pref_use_send_button_to_indicate_status_summary">Bidaltze botoia koloreztatu kontaktu baten egoera adierazteko</string> - -</resources> + +</resources>
\ No newline at end of file diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 024335f15..eccc8baea 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -52,15 +52,9 @@ <CheckBoxPreference android:dependency="show_notification" - android:key="notify_in_conversation_when_highlighted" + android:key="always_notify_in_conference" android:summary="@string/pref_conference_notifications_summary" android:title="@string/pref_conference_notifications" /> - <CheckBoxPreference - android:defaultValue="true" - android:dependency="show_notification" - android:key="notification_grace_period_after_carbon_received" - android:summary="@string/pref_notification_grace_period_summary" - android:title="@string/pref_notification_grace_period" /> </PreferenceCategory> <PreferenceCategory android:title="@string/pref_ui_options" > <CheckBoxPreference @@ -95,13 +89,13 @@ android:summary="@string/pref_dont_save_encrypted_summary" android:title="@string/pref_dont_save_encrypted" /> </PreferenceCategory> - <PreferenceCategory android:title="@string/pref_expert_options_other" > - <CheckBoxPreference - android:defaultValue="false" - android:key="indicate_received" - android:summary="@string/pref_use_indicate_received_summary" - android:title="@string/pref_use_indicate_received" /> - </PreferenceCategory> + <PreferenceCategory android:title="@string/pref_expert_options_other" > + <CheckBoxPreference + android:defaultValue="false" + android:key="indicate_received" + android:summary="@string/pref_use_indicate_received_summary" + android:title="@string/pref_use_indicate_received" /> + </PreferenceCategory> </PreferenceScreen> <CheckBoxPreference @@ -111,4 +105,4 @@ android:title="@string/pref_never_send_crash" /> </PreferenceCategory> -</PreferenceScreen> +</PreferenceScreen>
\ No newline at end of file diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index b8d375860..fedb0893a 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -40,7 +40,7 @@ public class Conversation extends AbstractEntity { public static final String CREATED = "created"; public static final String MODE = "mode"; public static final String ATTRIBUTES = "attributes"; - + public static final String ATTRIBUTE_NEXT_ENCRYPTION = "next_encryption"; public static final String ATTRIBUTE_MUC_PASSWORD = "muc_password"; @@ -51,7 +51,7 @@ public class Conversation extends AbstractEntity { private int status; private long created; private int mode; - + private JSONObject attributes = new JSONObject(); private long mutedTill = 0; @@ -81,7 +81,7 @@ public class Conversation extends AbstractEntity { int mode) { this(java.util.UUID.randomUUID().toString(), name, null, account .getUuid(), contactJid, System.currentTimeMillis(), - STATUS_AVAILABLE, mode,""); + STATUS_AVAILABLE, mode, ""); this.account = account; } @@ -97,7 +97,7 @@ public class Conversation extends AbstractEntity { this.status = status; this.mode = mode; try { - if (attributes==null) { + if (attributes == null) { attributes = new String(); } this.attributes = new JSONObject(attributes); @@ -214,7 +214,7 @@ public class Conversation extends AbstractEntity { values.put(CREATED, created); values.put(STATUS, status); values.put(MODE, mode); - values.put(ATTRIBUTES,attributes.toString()); + values.put(ATTRIBUTES, attributes.toString()); return values; } @@ -247,8 +247,8 @@ public class Conversation extends AbstractEntity { if (this.otrSession != null) { return this.otrSession; } else { - SessionID sessionId = new SessionID( - this.getContactJid().split("/",2)[0], presence, "xmpp"); + SessionID sessionId = new SessionID(this.getContactJid().split("/", + 2)[0], presence, "xmpp"); this.otrSession = new SessionImpl(sessionId, getAccount() .getOtrEngine(service)); try { @@ -459,7 +459,7 @@ public class Conversation extends AbstractEntity { public boolean isMuted() { return SystemClock.elapsedRealtime() < this.mutedTill; } - + public boolean setAttribute(String key, String value) { try { this.attributes.put(key, value); @@ -468,7 +468,7 @@ public class Conversation extends AbstractEntity { return false; } } - + public String getAttribute(String key) { try { return this.attributes.getString(key); @@ -476,10 +476,10 @@ public class Conversation extends AbstractEntity { return null; } } - + public int getIntAttribute(String key, int defaultValue) { String value = this.getAttribute(key); - if (value==null) { + if (value == null) { return defaultValue; } else { try { diff --git a/src/eu/siacs/conversations/entities/MucOptions.java b/src/eu/siacs/conversations/entities/MucOptions.java index 91a3d260a..0294c8aae 100644 --- a/src/eu/siacs/conversations/entities/MucOptions.java +++ b/src/eu/siacs/conversations/entities/MucOptions.java @@ -134,7 +134,7 @@ public class MucOptions { } public void processPacket(PresencePacket packet, PgpEngine pgp) { - String[] fromParts = packet.getFrom().split("/",2); + String[] fromParts = packet.getFrom().split("/", 2); if (fromParts.length >= 2) { String name = fromParts[1]; String type = packet.getAttribute("type"); @@ -180,7 +180,7 @@ public class MucOptions { } } } else if (type.equals("unavailable")) { - deleteUser(packet.getAttribute("from").split("/",2)[1]); + deleteUser(packet.getAttribute("from").split("/", 2)[1]); } else if (type.equals("error")) { Element error = packet.findChild("error"); if (error.hasChild("conflict")) { @@ -209,7 +209,7 @@ public class MucOptions { } public String getProposedNick() { - String[] mucParts = conversation.getContactJid().split("/",2); + String[] mucParts = conversation.getContactJid().split("/", 2); if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) { return conversation.getBookmark().getNick(); @@ -309,7 +309,7 @@ public class MucOptions { } public String getJoinJid() { - return this.conversation.getContactJid().split("/",2)[0] + "/" + return this.conversation.getContactJid().split("/", 2)[0] + "/" + this.joinnick; } @@ -323,7 +323,8 @@ public class MucOptions { } 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 && conversation.getBookmark().getPassword() != null) { return conversation.getBookmark().getPassword(); @@ -339,7 +340,8 @@ public class MucOptions { } else { this.password = password; } - conversation.setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password); + conversation + .setAttribute(Conversation.ATTRIBUTE_MUC_PASSWORD, password); } public boolean isPasswordChanged() { diff --git a/src/eu/siacs/conversations/generator/AbstractGenerator.java b/src/eu/siacs/conversations/generator/AbstractGenerator.java index 61f290e4a..c96d116d0 100644 --- a/src/eu/siacs/conversations/generator/AbstractGenerator.java +++ b/src/eu/siacs/conversations/generator/AbstractGenerator.java @@ -21,9 +21,9 @@ public abstract class AbstractGenerator { "urn:xmpp:avatar:metadata+notify" }; public final String IDENTITY_NAME = "Conversations 0.7"; public final String IDENTITY_TYPE = "phone"; - + protected XmppConnectionService mXmppConnectionService; - + protected AbstractGenerator(XmppConnectionService service) { this.mXmppConnectionService = service; } diff --git a/src/eu/siacs/conversations/generator/MessageGenerator.java b/src/eu/siacs/conversations/generator/MessageGenerator.java index d4cab3edd..dd833e56c 100644 --- a/src/eu/siacs/conversations/generator/MessageGenerator.java +++ b/src/eu/siacs/conversations/generator/MessageGenerator.java @@ -34,7 +34,7 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(message.getCounterpart()); packet.setType(MessagePacket.TYPE_CHAT); } else { - packet.setTo(message.getCounterpart().split("/",2)[0]); + packet.setTo(message.getCounterpart().split("/", 2)[0]); packet.setType(MessagePacket.TYPE_GROUPCHAT); } packet.setFrom(account.getFullJid()); @@ -134,7 +134,7 @@ public class MessageGenerator extends AbstractGenerator { String subject) { MessagePacket packet = new MessagePacket(); packet.setType(MessagePacket.TYPE_GROUPCHAT); - packet.setTo(conversation.getContactJid().split("/",2)[0]); + packet.setTo(conversation.getContactJid().split("/", 2)[0]); Element subjectChild = new Element("subject"); subjectChild.setContent(subject); packet.addChild(subjectChild); @@ -148,13 +148,13 @@ public class MessageGenerator extends AbstractGenerator { packet.setTo(contact); packet.setFrom(conversation.getAccount().getFullJid()); 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; } public MessagePacket invite(Conversation conversation, String contact) { MessagePacket packet = new MessagePacket(); - packet.setTo(conversation.getContactJid().split("/",2)[0]); + packet.setTo(conversation.getContactJid().split("/", 2)[0]); packet.setFrom(conversation.getAccount().getFullJid()); Element x = new Element("x"); x.setAttribute("xmlns", "http://jabber.org/protocol/muc#user"); diff --git a/src/eu/siacs/conversations/parser/AbstractParser.java b/src/eu/siacs/conversations/parser/AbstractParser.java index efbf5aef1..5541c1c61 100644 --- a/src/eu/siacs/conversations/parser/AbstractParser.java +++ b/src/eu/siacs/conversations/parser/AbstractParser.java @@ -60,7 +60,7 @@ public abstract class AbstractParser { protected void updateLastseen(Element packet, Account account, boolean presenceOverwrite) { - String[] fromParts = packet.getAttribute("from").split("/",2); + String[] fromParts = packet.getAttribute("from").split("/", 2); String from = fromParts[0]; String presence = null; if (fromParts.length >= 2) { diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java index 27627e525..c8718edb0 100644 --- a/src/eu/siacs/conversations/parser/MessageParser.java +++ b/src/eu/siacs/conversations/parser/MessageParser.java @@ -8,6 +8,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.xml.Element; @@ -298,7 +299,8 @@ public class MessageParser extends AbstractParser implements Element password = x.findChild("password"); conversation.getMucOptions().setPassword( password.getContent()); - mXmppConnectionService.databaseBackend.updateConversation(conversation); + mXmppConnectionService.databaseBackend + .updateConversation(conversation); } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); @@ -314,7 +316,8 @@ public class MessageParser extends AbstractParser implements if (!conversation.getMucOptions().online()) { if (password != null) { conversation.getMucOptions().setPassword(password); - mXmppConnectionService.databaseBackend.updateConversation(conversation); + mXmppConnectionService.databaseBackend + .updateConversation(conversation); } mXmppConnectionService.joinMuc(conversation); mXmppConnectionService.updateConversationUi(); @@ -384,11 +387,13 @@ public class MessageParser extends AbstractParser implements @Override public void onMessagePacketReceived(Account account, MessagePacket packet) { Message message = null; - boolean notify = true; - if (mXmppConnectionService.getPreferences().getBoolean( - "notification_grace_period_after_carbon_received", true)) { - notify = (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000); - } + boolean notify = mXmppConnectionService.getPreferences().getBoolean( + "show_notification", true); + notify = notify + && (SystemClock.elapsedRealtime() - lastCarbonMessageReceived) > (Config.CARBON_GRACE_PERIOD * 1000); + boolean alwaysNotifyInConference = notify + && mXmppConnectionService.getPreferences().getBoolean( + "always_notify_in_conference", false); this.parseNick(packet, account); @@ -414,7 +419,7 @@ public class MessageParser extends AbstractParser implements lastCarbonMessageReceived = SystemClock .elapsedRealtime(); notify = false; - message.getConversation().markRead(); + mXmppConnectionService.markRead(message.getConversation()); } else { message.markUnread(); } @@ -427,8 +432,11 @@ public class MessageParser extends AbstractParser implements if (message != null) { if (message.getStatus() == Message.STATUS_RECEIVED) { message.markUnread(); + notify = alwaysNotifyInConference + || NotificationService + .wasHighlightedOrPrivate(message); } else { - message.getConversation().markRead(); + mXmppConnectionService.markRead(message.getConversation()); lastCarbonMessageReceived = SystemClock.elapsedRealtime(); notify = false; } @@ -467,7 +475,10 @@ public class MessageParser extends AbstractParser implements } } notify = notify && !conversation.isMuted(); - mXmppConnectionService.notifyUi(conversation, notify); + if (notify) { + mXmppConnectionService.getNotificationService().push(message); + } + mXmppConnectionService.updateConversationUi(); } private void parseHeadline(MessagePacket packet, Account account) { diff --git a/src/eu/siacs/conversations/parser/PresenceParser.java b/src/eu/siacs/conversations/parser/PresenceParser.java index e240a8581..507ebbd2b 100644 --- a/src/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/eu/siacs/conversations/parser/PresenceParser.java @@ -22,7 +22,7 @@ public class PresenceParser extends AbstractParser implements PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/",2)[0]); + .getAttribute("from").split("/", 2)[0]); if (muc != null) { boolean before = muc.getMucOptions().online(); 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")) { Conversation muc = mXmppConnectionService.find(account, packet - .getAttribute("from").split("/",2)[0]); + .getAttribute("from").split("/", 2)[0]); if (muc != null) { boolean before = muc.getMucOptions().online(); muc.getMucOptions().processPacket(packet, mPgpEngine); diff --git a/src/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/eu/siacs/conversations/persistance/DatabaseBackend.java index 7afe387e4..0231c0e7e 100644 --- a/src/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -51,9 +51,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { + Conversation.ACCOUNT + " TEXT, " + Conversation.CONTACTJID + " TEXT, " + Conversation.CREATED + " NUMBER, " + Conversation.STATUS + " NUMBER, " + Conversation.MODE - + " NUMBER, "+Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY(" + Conversation.ACCOUNT - + ") REFERENCES " + Account.TABLENAME + "(" + Account.UUID - + ") ON DELETE CASCADE);"); + + " NUMBER, " + Conversation.ATTRIBUTES + " TEXT, FOREIGN KEY(" + + Conversation.ACCOUNT + ") REFERENCES " + Account.TABLENAME + + "(" + Account.UUID + ") ON DELETE CASCADE);"); db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID + " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, " + Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART @@ -225,13 +225,14 @@ public class DatabaseBackend extends SQLiteOpenHelper { String[] args = { account.getUuid() }; db.delete(Account.TABLENAME, Account.UUID + "=?", args); } - + public boolean hasEnabledAccounts() { 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(); int count = cursor.getInt(0); - return (count>0); + return (count > 0); } @Override diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index e2445b2a9..dfbe9db76 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -15,7 +15,8 @@ public class EventReceiver extends BroadcastReceiver { } else { mIntentForService.setAction("other"); } - if (intent.getAction().equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { + if (intent.getAction().equals("ui") + || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { context.startService(mIntentForService); } } diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java index af8ab4b2c..ac78a4540 100644 --- a/src/eu/siacs/conversations/services/ImageProvider.java +++ b/src/eu/siacs/conversations/services/ImageProvider.java @@ -31,7 +31,7 @@ public class ImageProvider extends ContentProvider { if (uuids == null) { throw new FileNotFoundException(); } - String[] uuidsSplited = uuids.split("/",2); + String[] uuidsSplited = uuids.split("/", 2); if (uuidsSplited.length != 3) { throw new FileNotFoundException(); } diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java new file mode 100644 index 000000000..831ce51ff --- /dev/null +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -0,0 +1,206 @@ +package eu.siacs.conversations.services; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +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 android.util.Log; + +import eu.siacs.conversations.Config; +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; + private Conversation mOpenConversation; + private boolean mIsInForeground; + + public NotificationService(XmppConnectionService service) { + this.mXmppConnectionService = service; + this.mNotificationManager = (NotificationManager) service + .getSystemService(Context.NOTIFICATION_SERVICE); + } + + public synchronized void push(Message message) { + if (this.mIsInForeground + && this.mOpenConversation == message.getConversation()) { + Log.d(Config.LOGTAG,"ignoring notification because foreground and conv matches"); + return; // simply ignore + } else { + Log.d(Config.LOGTAG,"pushed new notification"); + } + 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(!(this.mIsInForeground && this.mOpenConversation == null)); + } + + 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)); + if (notify) { + 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); + } + if (ringtone != null) { + mBuilder.setSound(Uri.parse(ringtone)); + } + } + mBuilder.setLights(0xffffffff, 2000, 4000); + 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; + } + + public static boolean wasHighlightedOrPrivate(Message message) { + String nick = message.getConversation().getMucOptions().getActualNick(); + Pattern highlight = generateNickHighlightPattern(nick); + Matcher m = highlight.matcher(message.getBody()); + return (m.find() || message.getType() == Message.TYPE_PRIVATE); + } + + private static Pattern generateNickHighlightPattern(String nick) { + // We expect a word boundary, i.e. space or start of string, followed by + // the + // nick (matched in case-insensitive manner), followed by optional + // punctuation (for example "bob: i disagree" or "how are you alice?"), + // followed by another word boundary. + return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b", + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + + public void setOpenConversation(Conversation conversation) { + this.mOpenConversation = conversation; + } + + public void setIsInForeground(boolean foreground) { + this.mIsInForeground = foreground; + } + +} diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index badf1df52..b83be7fbd 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -93,6 +93,8 @@ public class XmppConnectionService extends Service { private MemorizingTrustManager mMemorizingTrustManager; + private NotificationService mNotificationService; + private MessageParser mMessageParser = new MessageParser(this); private PresenceParser mPresenceParser = new PresenceParser(this); private IqParser mIqParser = new IqParser(this); @@ -401,6 +403,7 @@ public class XmppConnectionService extends Service { this.mRandom = new SecureRandom(); this.mMemorizingTrustManager = new MemorizingTrustManager( getApplicationContext()); + this.mNotificationService = new NotificationService(this); this.databaseBackend = DatabaseBackend .getInstance(getApplicationContext()); this.fileBackend = new FileBackend(getApplicationContext()); @@ -968,6 +971,7 @@ public class XmppConnectionService extends Service { switchToForeground(); } this.mOnConversationUpdate = listener; + this.mNotificationService.setIsInForeground(true); this.convChangedListenerCount++; } @@ -975,6 +979,7 @@ public class XmppConnectionService extends Service { this.convChangedListenerCount--; if (this.convChangedListenerCount == 0) { this.mOnConversationUpdate = null; + this.mNotificationService.setIsInForeground(false); if (checkListeners()) { switchToBackground(); } @@ -1268,7 +1273,7 @@ public class XmppConnectionService extends Service { } } } - notifyUi(conversation, false); + updateConversationUi(); } public boolean renewSymmetricKey(Conversation conversation) { @@ -1577,15 +1582,6 @@ public class XmppConnectionService extends Service { 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() { if (mOnConversationUpdate != null) { mOnConversationUpdate.onConversationUpdate(); @@ -1624,6 +1620,7 @@ public class XmppConnectionService extends Service { public void markRead(Conversation conversation) { conversation.markRead(); + mNotificationService.clear(conversation); String id = conversation.popLatestMarkableMessageId(); if (confirmMessages() && id != null) { Account account = conversation.getAccount(); @@ -1758,4 +1755,8 @@ public class XmppConnectionService extends Service { } return contacts; } + + public NotificationService getNotificationService() { + return this.mNotificationService; + } } diff --git a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index 76c12a474..04059d528 100644 --- a/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -201,7 +201,7 @@ public class ConferenceDetailsActivity extends XmppActivity { private void populateView() { mYourPhoto.setImageBitmap(conversation.getAccount().getImage(this, 48)); setTitle(conversation.getName()); - mFullJid.setText(conversation.getContactJid().split("/",2)[0]); + mFullJid.setText(conversation.getContactJid().split("/", 2)[0]); mYourNick.setText(conversation.getMucOptions().getActualNick()); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); if (conversation.getMucOptions().online()) { diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java index b6b6aa722..03cf753d3 100644 --- a/src/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/eu/siacs/conversations/ui/ConversationActivity.java @@ -12,7 +12,6 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.utils.ExceptionHelper; -import eu.siacs.conversations.utils.UIHelper; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; @@ -144,6 +143,9 @@ public class ConversationActivity extends XmppActivity implements } invalidateOptionsMenu(); hideKeyboard(); + if (xmppConnectionServiceBound) { + xmppConnectionService.getNotificationService().setOpenConversation(null); + } } @Override @@ -151,24 +153,10 @@ public class ConversationActivity extends XmppActivity implements paneShouldBeOpen = false; if ((conversationList.size() > 0) && (getSelectedConversation() != null)) { - ActionBar ab = getActionBar(); - if (ab != null) { - ab.setDisplayHomeAsUpEnabled(true); - ab.setHomeButtonEnabled(true); - if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE - || activity.useSubjectToIdentifyConference()) { - ab.setTitle(getSelectedConversation().getName()); - } else { - ab.setTitle(getSelectedConversation() - .getContactJid().split("/")[0]); - } - } - invalidateOptionsMenu(); + openConversation(getSelectedConversation()); if (!getSelectedConversation().isRead()) { xmppConnectionService .markRead(getSelectedConversation()); - UIHelper.updateNotification(getApplicationContext(), - getConversationList(), null, false); listView.invalidateViews(); } } @@ -181,6 +169,25 @@ public class ConversationActivity extends XmppActivity implements } }); } + + public void openConversation(Conversation conversation) { + ActionBar ab = getActionBar(); + if (ab != null) { + ab.setDisplayHomeAsUpEnabled(true); + ab.setHomeButtonEnabled(true); + if (getSelectedConversation().getMode() == Conversation.MODE_SINGLE + || activity.useSubjectToIdentifyConference()) { + ab.setTitle(getSelectedConversation().getName()); + } else { + ab.setTitle(getSelectedConversation() + .getContactJid().split("/")[0]); + } + } + invalidateOptionsMenu(); + if (xmppConnectionServiceBound) { + xmppConnectionService.getNotificationService().setOpenConversation(conversation); + } + } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -297,7 +304,8 @@ public class ConversationActivity extends XmppActivity implements int which) { conversation .setNextEncryption(Message.ENCRYPTION_NONE); - xmppConnectionService.databaseBackend.updateConversation(conversation); + xmppConnectionService.databaseBackend + .updateConversation(conversation); selectPresenceToAttachFile(attachmentChoice); } }); @@ -402,7 +410,7 @@ public class ConversationActivity extends XmppActivity implements }); builder.create().show(); } - + protected void attachFileDialog() { View menuAttachFile = findViewById(R.id.action_attach_file); if (menuAttachFile == null) { @@ -473,7 +481,8 @@ public class ConversationActivity extends XmppActivity implements conversation.setNextEncryption(Message.ENCRYPTION_NONE); break; } - xmppConnectionService.databaseBackend.updateConversation(conversation); + xmppConnectionService.databaseBackend + .updateConversation(conversation); fragment.updateChatMsgHint(); return true; } @@ -603,6 +612,7 @@ public class ConversationActivity extends XmppActivity implements xmppConnectionService.removeOnConversationListChangedListener(); xmppConnectionService.removeOnAccountListChangedListener(); xmppConnectionService.removeOnRosterUpdateListener(); + xmppConnectionService.getNotificationService().setOpenConversation(null); } super.onStop(); } diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java index a8dee4f76..064b00be4 100644 --- a/src/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/eu/siacs/conversations/ui/ConversationFragment.java @@ -379,14 +379,7 @@ public class ConversationFragment extends Fragment { if (activity.getSlidingPaneLayout().isSlideable()) { if (!activity.shouldPaneBeOpen()) { activity.getSlidingPaneLayout().closePane(); - activity.getActionBar().setDisplayHomeAsUpEnabled(true); - activity.getActionBar().setHomeButtonEnabled(true); - if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) { - activity.getActionBar().setTitle(conversation.getName()); - } else { - activity.getActionBar().setTitle(conversation.getContactJid().split("/")[0]); - } - activity.invalidateOptionsMenu(); + activity.openConversation(conversation); } } if (this.conversation.getMode() == Conversation.MODE_MULTI) { @@ -502,8 +495,6 @@ public class ConversationFragment extends Fragment { updateChatMsgHint(); if (!activity.shouldPaneBeOpen()) { activity.xmppConnectionService.markRead(conversation); - UIHelper.updateNotification(getActivity(), - activity.getConversationList(), null, false); activity.updateConversationList(); } this.updateSendButton(); @@ -668,7 +659,8 @@ public class ConversationFragment extends Fragment { int which) { conversation .setNextEncryption(Message.ENCRYPTION_NONE); - xmppService.databaseBackend.updateConversation(conversation); + xmppService.databaseBackend + .updateConversation(conversation); message.setEncryption(Message.ENCRYPTION_NONE); xmppService.sendMessage(message); messageSent(); @@ -697,7 +689,8 @@ public class ConversationFragment extends Fragment { conversation .setNextEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE); - xmppService.databaseBackend.updateConversation(conversation); + xmppService.databaseBackend + .updateConversation(conversation); xmppService.sendMessage(message); messageSent(); } diff --git a/src/eu/siacs/conversations/ui/SettingsActivity.java b/src/eu/siacs/conversations/ui/SettingsActivity.java index fc361fb82..fc6308fce 100644 --- a/src/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/eu/siacs/conversations/ui/SettingsActivity.java @@ -21,7 +21,7 @@ public class SettingsActivity extends XmppActivity implements super.onCreate(savedInstanceState); mSettingsFragment = new SettingsFragment(); getFragmentManager().beginTransaction() - .replace(android.R.id.content,mSettingsFragment).commit(); + .replace(android.R.id.content, mSettingsFragment).commit(); } @Override @@ -34,12 +34,16 @@ public class SettingsActivity extends XmppActivity implements super.onStart(); PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); - ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource"); - if (resources!=null) { - ArrayList<CharSequence> entries = new ArrayList<CharSequence>(Arrays.asList(resources.getEntries())); - entries.add(0,Build.MODEL); - resources.setEntries(entries.toArray(new CharSequence[entries.size()])); - resources.setEntryValues(entries.toArray(new CharSequence[entries.size()])); + ListPreference resources = (ListPreference) mSettingsFragment + .findPreference("resource"); + if (resources != null) { + ArrayList<CharSequence> entries = new ArrayList<CharSequence>( + Arrays.asList(resources.getEntries())); + entries.add(0, Build.MODEL); + resources.setEntries(entries.toArray(new CharSequence[entries + .size()])); + resources.setEntryValues(entries.toArray(new CharSequence[entries + .size()])); } } diff --git a/src/eu/siacs/conversations/ui/StartConversationActivity.java b/src/eu/siacs/conversations/ui/StartConversationActivity.java index e4b49d082..1a5fba959 100644 --- a/src/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/eu/siacs/conversations/ui/StartConversationActivity.java @@ -325,8 +325,8 @@ public class StartConversationActivity extends XmppActivity { final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView .findViewById(R.id.jid); jid.setAdapter(new KnownHostsAdapter(this, - android.R.layout.simple_list_item_1, mKnownHosts)); - if (prefilledJid!=null) { + android.R.layout.simple_list_item_1, mKnownHosts)); + if (prefilledJid != null) { jid.append(prefilledJid); } populateAccountSpinner(spinner); @@ -536,7 +536,8 @@ public class StartConversationActivity extends XmppActivity { setIntent(null); 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(); String jid = uri.getSchemeSpecificPart().split("\\?")[0]; return handleJid(jid); @@ -545,8 +546,7 @@ public class StartConversationActivity extends XmppActivity { } private boolean handleJid(String jid) { - List<Contact> contacts = xmppConnectionService - .findContacts(jid); + List<Contact> contacts = xmppConnectionService.findContacts(jid); if (contacts.size() == 0) { showCreateContactDialog(jid); return false; diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java index b54bc1524..518f7b0be 100644 --- a/src/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/eu/siacs/conversations/ui/XmppActivity.java @@ -63,7 +63,7 @@ public abstract class XmppActivity extends Activity { protected int mColorOrange; protected int mColorGreen; protected int mPrimaryColor; - + protected boolean mUseSubject = true; private DisplayMetrics metrics; @@ -217,7 +217,7 @@ public abstract class XmppActivity extends Activity { return PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); } - + public boolean useSubjectToIdentifyConference() { return mUseSubject; } @@ -256,7 +256,7 @@ public abstract class XmppActivity extends Activity { intent.putExtra("contact", contact.getJid()); startActivity(intent); } - + public void switchToAccount(Account account) { Intent intent = new Intent(this, EditAccountActivity.class); intent.putExtra("jid", account.getJid()); @@ -294,7 +294,8 @@ public abstract class XmppActivity extends Activity { if (conversation != null) { conversation .setNextEncryption(Message.ENCRYPTION_PGP); - xmppConnectionService.databaseBackend.updateConversation(conversation); + xmppConnectionService.databaseBackend + .updateConversation(conversation); } } diff --git a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index e40723f41..7b470faa4 100644 --- a/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -52,7 +52,8 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> { } TextView convName = (TextView) view .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()); } else { convName.setText(conv.getContactJid().split("/")[0]); diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index d18263155..671e66d5b 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -7,13 +7,11 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.regex.Pattern; -import java.util.regex.Matcher; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ManageAccountActivity; @@ -27,7 +25,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -35,13 +32,11 @@ import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; -import android.preference.PreferenceManager; import android.provider.ContactsContract.Contacts; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.format.DateFormat; import android.text.format.DateUtils; -import android.text.Html; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; @@ -331,177 +326,6 @@ public class UIHelper { mNotificationManager.notify(1111, notification); } - private static Pattern generateNickHighlightPattern(String nick) { - // We expect a word boundary, i.e. space or start of string, followed by - // the - // nick (matched in case-insensitive manner), followed by optional - // punctuation (for example "bob: i disagree" or "how are you alice?"), - // followed by another word boundary. - return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b", - Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); - } - - public static void updateNotification(Context context, - List<Conversation> conversations, Conversation currentCon, - boolean notify) { - NotificationManager mNotificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); - - SharedPreferences preferences = PreferenceManager - .getDefaultSharedPreferences(context); - boolean showNofifications = preferences.getBoolean("show_notification", - true); - boolean vibrate = preferences.getBoolean("vibrate_on_notification", - true); - boolean alwaysNotify = preferences.getBoolean( - "notify_in_conversation_when_highlighted", false); - - if (!showNofifications) { - mNotificationManager.cancel(2342); - return; - } - - String targetUuid = ""; - - if ((currentCon != null) - && (currentCon.getMode() == Conversation.MODE_MULTI) - && (!alwaysNotify) && notify) { - String nick = currentCon.getMucOptions().getActualNick(); - Pattern highlight = generateNickHighlightPattern(nick); - Matcher m = highlight.matcher(currentCon.getLatestMessage() - .getBody()); - notify = m.find() - || (currentCon.getLatestMessage().getType() == Message.TYPE_PRIVATE); - } - - List<Conversation> unread = new ArrayList<Conversation>(); - for (Conversation conversation : conversations) { - if (conversation.getMode() == Conversation.MODE_MULTI) { - if ((!conversation.isRead()) - && ((wasHighlightedOrPrivate(conversation) || (alwaysNotify)))) { - unread.add(conversation); - } - } else { - if (!conversation.isRead()) { - unread.add(conversation); - } - } - } - String ringtone = preferences.getString("notification_ringtone", null); - - NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( - context); - if (unread.size() == 0) { - mNotificationManager.cancel(2342); - return; - } else if (unread.size() == 1) { - Conversation conversation = unread.get(0); - targetUuid = conversation.getUuid(); - mBuilder.setLargeIcon(conversation.getImage(context, 64)); - mBuilder.setContentTitle(conversation.getName()); - if (notify) { - mBuilder.setTicker(conversation.getLatestMessage() - .getReadableBody(context)); - } - StringBuilder bigText = new StringBuilder(); - List<Message> messages = conversation.getMessages(); - String firstLine = ""; - for (int i = messages.size() - 1; i >= 0; --i) { - if (!messages.get(i).isRead()) { - if (i == messages.size() - 1) { - firstLine = messages.get(i).getReadableBody(context); - bigText.append(firstLine); - } else { - firstLine = messages.get(i).getReadableBody(context); - bigText.insert(0, firstLine + "\n"); - } - } else { - break; - } - } - mBuilder.setContentText(firstLine); - mBuilder.setStyle(new NotificationCompat.BigTextStyle() - .bigText(bigText.toString())); - } else { - NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); - style.setBigContentTitle(unread.size() + " " - + context.getString(R.string.unread_conversations)); - StringBuilder names = new StringBuilder(); - for (int i = 0; i < unread.size(); ++i) { - targetUuid = unread.get(i).getUuid(); - if (i < unread.size() - 1) { - names.append(unread.get(i).getName() + ", "); - } else { - names.append(unread.get(i).getName()); - } - style.addLine(Html.fromHtml("<b>" - + unread.get(i).getName() - + "</b> " - + unread.get(i).getLatestMessage() - .getReadableBody(context))); - } - mBuilder.setContentTitle(unread.size() + " " - + context.getString(R.string.unread_conversations)); - mBuilder.setContentText(names.toString()); - mBuilder.setStyle(style); - } - if ((currentCon != null) && (notify)) { - targetUuid = currentCon.getUuid(); - } - if (unread.size() != 0) { - mBuilder.setSmallIcon(R.drawable.ic_notification); - 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)); - } - } - - TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); - stackBuilder.addParentStack(ConversationActivity.class); - - Intent viewConversationIntent = new Intent(context, - ConversationActivity.class); - viewConversationIntent.setAction(Intent.ACTION_VIEW); - viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, - targetUuid); - viewConversationIntent - .setType(ConversationActivity.VIEW_CONVERSATION); - - stackBuilder.addNextIntent(viewConversationIntent); - - PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( - 0, PendingIntent.FLAG_UPDATE_CURRENT); - - mBuilder.setContentIntent(resultPendingIntent); - Notification notification = mBuilder.build(); - mNotificationManager.notify(2342, notification); - } - } - - private static boolean wasHighlightedOrPrivate(Conversation conversation) { - List<Message> messages = conversation.getMessages(); - String nick = conversation.getMucOptions().getActualNick(); - Pattern highlight = generateNickHighlightPattern(nick); - for (int i = messages.size() - 1; i >= 0; --i) { - if (messages.get(i).isRead()) { - break; - } else { - Matcher m = highlight.matcher(messages.get(i).getBody()); - if (m.find() - || messages.get(i).getType() == Message.TYPE_PRIVATE) { - return true; - } - } - } - return false; - } - public static void prepareContactBadge(final Activity activity, QuickContactBadge badge, final Contact contact, Context context) { if (contact.getSystemAccount() != null) { diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 8694e68c4..b055e35a3 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -657,7 +657,7 @@ public class XmppConnection implements Runnable { if (bind != null) { Element jid = bind.findChild("jid"); 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")) { smVersion = 3; EnablePacket enable = new EnablePacket(smVersion); diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index 4eac99e68..92fdbe0b6 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -88,8 +88,8 @@ public class JingleConnection implements Downloadable { sendSuccess(); if (acceptedAutomatically) { message.markUnread(); - JingleConnection.this.mXmppConnectionService.notifyUi( - message.getConversation(), true); + JingleConnection.this.mXmppConnectionService + .getNotificationService().push(message); } BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; @@ -256,12 +256,12 @@ public class JingleConnection implements Downloadable { this.status = STATUS_INITIATED; Conversation conversation = this.mXmppConnectionService .findOrCreateConversation(account, - packet.getFrom().split("/",2)[0], false); + packet.getFrom().split("/", 2)[0], false); this.message = new Message(conversation, "", Message.ENCRYPTION_NONE); this.message.setType(Message.TYPE_IMAGE); this.message.setStatus(Message.STATUS_RECEIVED_OFFER); this.message.setDownloadable(this); - String[] fromParts = packet.getFrom().split("/",2); + String[] fromParts = packet.getFrom().split("/", 2); this.message.setPresence(fromParts[1]); this.account = account; this.initiator = packet.getFrom(); @@ -319,8 +319,8 @@ public class JingleConnection implements Downloadable { + " allowed size:" + this.mJingleConnectionManager .getAutoAcceptFileSize()); - this.mXmppConnectionService - .notifyUi(conversation, true); + this.mXmppConnectionService.getNotificationService() + .push(message); } this.file = this.mXmppConnectionService.getFileBackend() .getJingleFile(message, false); |