From 2b4f94e9ffc08c1eb48db271b9dedd9829dbf8f5 Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Thu, 12 Dec 2013 10:15:47 -0500
Subject: [PATCH] * #36758: displayed name in ui are the same as in daemon
 history

---
 res/animator/slidein_up.xml                 |  2 +-
 res/animator/slideout_down.xml              |  2 +-
 src/org/sflphone/loaders/HistoryLoader.java |  8 ++++----
 src/org/sflphone/model/CallContact.java     |  8 ++++++++
 src/org/sflphone/model/HistoryEntry.java    | 12 +++++++++++-
 5 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/res/animator/slidein_up.xml b/res/animator/slidein_up.xml
index 220ba5327..b61cd72d1 100644
--- a/res/animator/slidein_up.xml
+++ b/res/animator/slidein_up.xml
@@ -4,5 +4,5 @@
     android:propertyName="y"
     android:valueFrom="2000"
     android:valueTo="0"
-    android:interpolator="@android:anim/overshoot_interpolator"
+    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
     android:valueType="floatType" />
\ No newline at end of file
diff --git a/res/animator/slideout_down.xml b/res/animator/slideout_down.xml
index 0d957fb69..be50687fd 100644
--- a/res/animator/slideout_down.xml
+++ b/res/animator/slideout_down.xml
@@ -4,5 +4,5 @@
     android:propertyName="y"
     android:valueFrom="0"
     android:valueTo="2000"
-    android:interpolator="@android:anim/overshoot_interpolator"
+    android:interpolator="@android:anim/accelerate_interpolator"
     android:valueType="floatType" />
\ No newline at end of file
diff --git a/src/org/sflphone/loaders/HistoryLoader.java b/src/org/sflphone/loaders/HistoryLoader.java
index c454cc81d..b1654a0b7 100644
--- a/src/org/sflphone/loaders/HistoryLoader.java
+++ b/src/org/sflphone/loaders/HistoryLoader.java
@@ -57,7 +57,7 @@ public class HistoryLoader extends AsyncTaskLoader<ArrayList<HistoryEntry>> {
 
                 if (historyEntries.containsKey(number_called)) {
                     // It's a direct match
-                    historyEntries.get(number_called).addHistoryCall(new HistoryCall(entry));
+                    historyEntries.get(number_called).addHistoryCall(new HistoryCall(entry), contact);
                 } else {
                     // Maybe we can extract the extension @ account pattern
                     Pattern p = Pattern.compile("<sip:([^@]+)@([^>]+)>");
@@ -65,17 +65,17 @@ public class HistoryLoader extends AsyncTaskLoader<ArrayList<HistoryEntry>> {
                     if (m.find()) {
 
                         if (historyEntries.containsKey(m.group(1) + "@" + m.group(2))) {
-                            historyEntries.get(m.group(1) + "@" + m.group(2)).addHistoryCall(new HistoryCall(entry));
+                            historyEntries.get(m.group(1) + "@" + m.group(2)).addHistoryCall(new HistoryCall(entry), contact);
                         } else {
                             HistoryEntry e = new HistoryEntry(entry.get(ServiceConstants.history.ACCOUNT_ID_KEY), contact);
-                            e.addHistoryCall(new HistoryCall(entry));
+                            e.addHistoryCall(new HistoryCall(entry), contact);
                             historyEntries.put(m.group(1) + "@" + m.group(2), e);
                         }
 
                     } else {
 
                         HistoryEntry e = new HistoryEntry(entry.get(ServiceConstants.history.ACCOUNT_ID_KEY), contact);
-                        e.addHistoryCall(new HistoryCall(entry));
+                        e.addHistoryCall(new HistoryCall(entry), contact);
                         historyEntries.put(number_called, e);
                     }
 
diff --git a/src/org/sflphone/model/CallContact.java b/src/org/sflphone/model/CallContact.java
index fd703952f..746321913 100644
--- a/src/org/sflphone/model/CallContact.java
+++ b/src/org/sflphone/model/CallContact.java
@@ -323,4 +323,12 @@ public class CallContact implements Parcelable {
         contact_photo = new WeakReference<Bitmap>(externalBMP);
     }
 
+    /**
+     * A contact is Unknown when his name == his phone number
+     * @return true when Name == Number
+     */
+    public boolean isUnknown() {
+       return mDisplayName.contentEquals(phones.get(0).getNumber());
+    }
+
 }
diff --git a/src/org/sflphone/model/HistoryEntry.java b/src/org/sflphone/model/HistoryEntry.java
index 278277b65..141690e5e 100644
--- a/src/org/sflphone/model/HistoryEntry.java
+++ b/src/org/sflphone/model/HistoryEntry.java
@@ -83,7 +83,14 @@ public class HistoryEntry implements Parcelable {
         this.contact = contact;
     }
 
-    public void addHistoryCall(HistoryCall historyCall) {
+    /**
+     * Each call is associated with a contact.
+     * When adding a call to an HIstoryEntry, this methods also verifies if we can update 
+     * the contact (if contact is Unknown, replace it)
+     * @param historyCall The call to put in this HistoryEntry 
+     * @param linkedTo The associated CallContact
+     */
+    public void addHistoryCall(HistoryCall historyCall, CallContact linkedTo) {
         calls.put(historyCall.call_start, historyCall);
         if (historyCall.isIncoming()) {
             ++incoming_sum;
@@ -92,6 +99,9 @@ public class HistoryEntry implements Parcelable {
         }
         if (historyCall.isMissed())
             missed_sum++;
+        
+        if(contact.isUnknown() && !linkedTo.isUnknown())
+            setContact(linkedTo);
     }
 
     public String getNumber() {
-- 
GitLab