Skip to content
Snippets Groups Projects
Commit a3162160 authored by Aline Bonnet's avatar Aline Bonnet
Browse files

ui: fix notifications

When receiving many text messages, as many notifications were created.
Now, there is one notification for every conversation with new
messages.

If you received messages from several senders, the ringID was always
the same. This commit fixes this behavior.

Change-Id: I8c54a7cca1ad395f3b3f9f5fba32c832cfd893bf
Tuleap: #1414
parent 9dc8593a
No related branches found
No related tags found
No related merge requests found
...@@ -900,7 +900,6 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -900,7 +900,6 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
@Override @Override
protected Map<String, Conversation> doInBackground(Void... params) { protected Map<String, Conversation> doInBackground(Void... params) {
final Map<String, Conversation> ret = new HashMap<>();
try { try {
final List<HistoryCall> history = mHistoryService.getAll(); final List<HistoryCall> history = mHistoryService.getAll();
final List<HistoryText> historyTexts = mHistoryService.getAllTextMessages(); final List<HistoryText> historyTexts = mHistoryService.getAllTextMessages();
...@@ -911,7 +910,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -911,7 +910,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
CallContact contact = getCreateContact(call.getContactID(), call.getContactKey(), call.getNumber()); CallContact contact = getCreateContact(call.getContactID(), call.getContactKey(), call.getNumber());
Map.Entry<String, Conversation> merge = null; Map.Entry<String, Conversation> merge = null;
for (Map.Entry<String, Conversation> ce : ret.entrySet()) { for (Map.Entry<String, Conversation> ce : conversations.entrySet()) {
Conversation conversation = ce.getValue(); Conversation conversation = ce.getValue();
if ((contact.getId() > 0 && contact.getId() == conversation.getContact().getId()) || conversation.getContact().hasNumber(call.getNumber())) { if ((contact.getId() > 0 && contact.getId() == conversation.getContact().getId()) || conversation.getContact().hasNumber(call.getNumber())) {
merge = ce; merge = ce;
...@@ -922,25 +921,25 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -922,25 +921,25 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
Conversation conversation = merge.getValue(); Conversation conversation = merge.getValue();
if (conversation.getContact().getId() <= 0 && contact.getId() > 0) { if (conversation.getContact().getId() <= 0 && contact.getId() > 0) {
conversation.setContact(contact); conversation.setContact(contact);
ret.remove(merge.getKey()); conversations.remove(merge.getKey());
ret.put(contact.getIds().get(0), conversation); conversations.put(contact.getIds().get(0), conversation);
} }
conversation.addHistoryCall(call); conversation.addHistoryCall(call);
continue; continue;
} }
String key = contact.getIds().get(0); String key = contact.getIds().get(0);
if (ret.containsKey(key)) { if (conversations.containsKey(key)) {
ret.get(key).addHistoryCall(call); conversations.get(key).addHistoryCall(call);
} else { } else {
Conversation conversation = new Conversation(contact); Conversation conversation = new Conversation(contact);
conversation.addHistoryCall(call); conversation.addHistoryCall(call);
ret.put(key, conversation); conversations.put(key, conversation);
} }
} }
for (HistoryText htext : historyTexts) { for (HistoryText htext : historyTexts) {
CallContact contact = getCreateContact(htext.getContactID(), htext.getContactKey(), htext.getNumber()); CallContact contact = getCreateContact(htext.getContactID(), htext.getContactKey(), htext.getNumber());
Tuple<HistoryEntry, HistoryCall> p = findHistoryByCallId(ret, htext.getCallId()); Tuple<HistoryEntry, HistoryCall> p = findHistoryByCallId(conversations, htext.getCallId());
if (contact == null && p != null) { if (contact == null && p != null) {
contact = p.first.getContact(); contact = p.first.getContact();
...@@ -960,12 +959,14 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -960,12 +959,14 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
} }
String key = contact.getIds().get(0); String key = contact.getIds().get(0);
if (ret.containsKey(key)) { if (conversations.containsKey(key)) {
ret.get(key).addTextMessage(msg); if (!conversations.get(key).getTextMessages().contains(msg)) {
conversations.get(key).addTextMessage(msg);
}
} else { } else {
Conversation c = new Conversation(contact); Conversation c = new Conversation(contact);
c.addTextMessage(msg); c.addTextMessage(msg);
ret.put(key, c); conversations.put(key, c);
} }
} }
...@@ -993,7 +994,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -993,7 +994,7 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
Conversation conv = null; Conversation conv = null;
ArrayList<String> ids = contact.getIds(); ArrayList<String> ids = contact.getIds();
for (String id : ids) { for (String id : ids) {
conv = ret.get(id); conv = conversations.get(id);
if (conv != null) { if (conv != null) {
break; break;
} }
...@@ -1003,24 +1004,24 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -1003,24 +1004,24 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
} else { } else {
conv = new Conversation(contact); conv = new Conversation(contact);
conv.addConference(conf); conv.addConference(conf);
ret.put(ids.get(0), conv); conversations.put(ids.get(0), conv);
} }
} }
} }
for (Conversation c : ret.values()) { for (Conversation c : conversations.values()) {
Log.w(TAG, "Conversation : " + c.getContact().getId() + " " + c.getContact().getDisplayName() + " " + c.getLastNumberUsed(c.getLastAccountUsed()) + " " + c.getLastInteraction().toString()); Log.w(TAG, "Conversation : " + c.getContact().getId() + " " + c.getContact().getDisplayName() + " " + c.getLastNumberUsed(c.getLastAccountUsed()) + " " + c.getLastInteraction().toString());
} }
for (int i = 0; i < localContactCache.size(); i++) { for (int i = 0; i < localContactCache.size(); i++) {
CallContact contact = localContactCache.valueAt(i); CallContact contact = localContactCache.valueAt(i);
String key = contact.getIds().get(0); String key = contact.getIds().get(0);
if (!ret.containsKey(key)) { if (!conversations.containsKey(key)) {
ret.put(key, new Conversation(contact)); conversations.put(key, new Conversation(contact));
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "ConversationLoader doInBackground", e); Log.e(TAG, "ConversationLoader doInBackground", e);
} }
return ret; return conversations;
} }
} }
...@@ -1089,14 +1090,14 @@ public class LocalService extends Service implements Observer<DaemonEvent> { ...@@ -1089,14 +1090,14 @@ public class LocalService extends Service implements Observer<DaemonEvent> {
mMessageNotificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE) mMessageNotificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setPriority(NotificationCompat.PRIORITY_HIGH) .setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL) .setDefaults(NotificationCompat.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_ring_logo_white) .setSmallIcon(R.drawable.ic_ring_logo_white);
.setContentTitle(contact.getDisplayName()); }
mMessageNotificationBuilder.setContentTitle(contact.getDisplayName());
String[] split = contact.getDisplayName().split(":"); String[] split = contact.getDisplayName().split(":");
if (split.length > 0) { if (split.length > 0) {
mLastBlockchainQuery = split[1]; mLastBlockchainQuery = split[1];
mAccountService.lookupAddress("", "", mLastBlockchainQuery); mAccountService.lookupAddress("", "", mLastBlockchainQuery);
} }
}
Intent c_intent = new Intent(Intent.ACTION_VIEW) Intent c_intent = new Intent(Intent.ACTION_VIEW)
.setClass(this, ConversationActivity.class) .setClass(this, ConversationActivity.class)
.setData(android.net.Uri.withAppendedPath(ContentUriHandler.CONVERSATION_CONTENT_URI, contact.getIds().get(0))); .setData(android.net.Uri.withAppendedPath(ContentUriHandler.CONVERSATION_CONTENT_URI, contact.getIds().get(0)));
......
...@@ -212,4 +212,28 @@ public class TextMessage { ...@@ -212,4 +212,28 @@ public class TextMessage {
mNotified = noti; mNotified = noti;
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
TextMessage that = (TextMessage) o;
if (mTimestamp != that.mTimestamp) {
return false;
}
return mMessage.equals(that.mMessage);
}
@Override
public int hashCode() {
int result = (int) (mTimestamp ^ (mTimestamp >>> 32));
result = 31 * result + mMessage.hashCode();
return result;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment