smartpanel : add time stamp

- shows last call date in the smartpanel.
- shows "more user friendly", callstatus in smartpanel.
- store last call date in contacts.json.
- edit call button xaml.

Change-Id: I2caa9ddb9d45b5be54a456b67ff535d0c85a4e80
Tuleap: #790
diff --git a/Contact.cpp b/Contact.cpp
index e92cf81..d62d3f5 100644
--- a/Contact.cpp
+++ b/Contact.cpp
@@ -76,6 +76,7 @@
     _displayName = "";

 

     contactStatus_ = contactStatus;

+    lastTime_ = "never";

 }

 

 void

@@ -101,6 +102,7 @@
     contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_));

     contactObject->SetNamedValue(accountIdAssociatedKey, JsonValue::CreateStringValue(_accountIdAssociated));

     contactObject->SetNamedValue(vcardUIDKey, JsonValue::CreateStringValue(_vcardUID));

+    contactObject->SetNamedValue(lastTimeKey, JsonValue::CreateStringValue(_lastTime));

 

     JsonObject^ jsonObject = ref new JsonObject();

     jsonObject->SetNamedValue(contactKey, contactObject);

diff --git a/Contact.h b/Contact.h
index 84a7c3e..6e4074b 100644
--- a/Contact.h
+++ b/Contact.h
@@ -35,6 +35,8 @@
 String^ contactListKey = "contactlist";

 String^ accountIdAssociatedKey = "accountIdAssociated";

 String^ vcardUIDKey = "vcardUID";

+String^ lastTimeKey = "lastTime";

+

 

 namespace RingClientUWP

 {

@@ -146,6 +148,20 @@
         }

     }

 

+    property String^ _lastTime

+    {

+        String^ get()

+        {

+            return lastTime_;

+        }

+        void set(String^ value)

+        {

+            lastTime_ = value;

+            NotifyPropertyChanged("_lastTime");

+        }

+    }

+

+

     VCardUtils::VCard^ getVCard();

 

 internal:

@@ -168,6 +184,7 @@
     Windows::UI::Xaml::GridLength contactBarHeight_ = 0;

     ContactStatus contactStatus_;

     String^ name_;

+    String^ lastTime_;

 };

 }

 

diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp
index 6183254..3debaef 100644
--- a/ContactsViewModel.cpp
+++ b/ContactsViewModel.cpp
@@ -167,6 +167,7 @@
     unsigned int    unreadmessages;

     String^			accountIdAssociated;

     String^         vcardUID;

+    String^			lastTime;

 

     JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray());

     for (unsigned int i = 0; i < contactlist->Size; i++) {

@@ -182,12 +183,18 @@
                 unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey));

                 accountIdAssociated = contactObject->GetNamedString(accountIdAssociatedKey);

                 vcardUID = contactObject->GetNamedString(vcardUIDKey);

+

+                if (contactObject->HasKey(lastTimeKey))

+                    lastTime = contactObject->GetNamedString(lastTimeKey);

             }

             auto contact = ref new Contact(name, ringid, guid, unreadmessages, ContactStatus::READY);

             contact->_displayName = displayname;

             contact->_accountIdAssociated = accountIdAssociated;

             // contact image

             contact->_vcardUID = vcardUID;

+            if (lastTime)

+                contact->_lastTime = lastTime;

+

             std::string contactImageFile = RingD::instance->getLocalFolder() + ".vcards\\"

                                            + Utils::toString(contact->_vcardUID) + ".png";

             if (Utils::fileExists(contactImageFile)) {

diff --git a/Globals.h b/Globals.h
index ad6a493..56533c7 100644
--- a/Globals.h
+++ b/Globals.h
@@ -3,6 +3,7 @@
 /* public enumerations. */

 public enum class CallStatus {

     NONE,

+    OUTGOING_REQUESTED,

     INCOMING_RINGING,

     OUTGOING_RINGING,

     SEARCHING,

diff --git a/RingD.cpp b/RingD.cpp
index fdb45dd..555d71a 100644
--- a/RingD.cpp
+++ b/RingD.cpp
@@ -20,6 +20,8 @@
 

 /* daemon */

 #include <dring.h>

+#include "dring/call_const.h"

+

 #include "callmanager_interface.h"

 #include "configurationmanager_interface.h"

 #include "presencemanager_interface.h"

@@ -969,7 +971,9 @@
         case Request::HangUpCall:

         {

             auto callId = task->_callId;

+

             DRing::hangUp(Utils::toString(callId));

+

         }

         break;

         case Request::PauseCall:

diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index c1a1635..1396381 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -38,6 +38,7 @@
         <views:CollapseEmptyString x:Key="_CollapseEmptyString_" />

         <views:ContactStatusNotification x:Key="_ContactStatusNotification_" />

         <views:boolToVisibility x:Key="_boolToVisibility_" />

+        <views:CallStatusToSpinnerVisibility x:Key="_CallStatusToSpinnerVisibility_" />

 

         <!-- template for contacts. -->

         <DataTemplate x:Key="ContactTemplate"

@@ -228,27 +229,39 @@
 

                         <Grid Grid.Column="1">

                             <Grid.RowDefinitions>

-                                <RowDefinition Height="30"/>

+                                <RowDefinition Height="40"/>

                                 <RowDefinition Height="30"/>

                             </Grid.RowDefinitions>

                             <!-- name of the contact. -->

-                            <TextBlock  x:Name="_contactName_"

-                                    Grid.Row="0"

-                                    Text="{x:Bind _contact._name, Mode=OneWay}"

-                                    TextTrimming="CharacterEllipsis">

-                            </TextBlock>

+                            <StackPanel Grid.Row="0">

+                                <TextBlock  x:Name="_contactName_"

+                                            Text="{x:Bind _contact._name, Mode=OneWay}"

+                                            TextTrimming="CharacterEllipsis">

+                                </TextBlock>

+                                <StackPanel Orientation="Horizontal">

+                                    <TextBlock  x:Name="_contactLastTime_"

+                                                FontStyle="Italic"

+                                                Foreground="#333333"

+                                                FontSize="10"

+                                                Text="{x:Bind _contact._lastTime, Mode=OneWay}"/>

+                                    <ProgressBar Foreground="#333333"

+                                                 Width="100"

+                                                 Visibility="{x:Bind _callStatus, Converter={StaticResource _CallStatusToSpinnerVisibility_}, Mode=OneWay}"

+                                                 IsIndeterminate="True"/>

+                                </StackPanel>

+                            </StackPanel>

                             <!-- call button. -->

+                            <!-- Style="{StaticResource roundButtonTemplate}" old style, keep it until refacto -->

                             <Button Grid.Row="0"

                                     Visibility="{x:Bind _isCallable, Converter={StaticResource _boolToVisibility_}, Mode=OneWay}"

                                     Click="_callContact__Click"

                                     VerticalAlignment="Bottom"

                                     HorizontalAlignment="Left"

-                                    Margin="10,0"

-                                    Style="{StaticResource roundButtonTemplate}"

+                                    Style="{StaticResource ButtonStyleForCallBar}"

                                     FontFamily="Segoe MDL2 Assets"

                                     Content="&#xE116;">

                                 <Button.RenderTransform>

-                                    <TranslateTransform X="90" Y="25"/>

+                                    <TranslateTransform X="0" Y="18"/>

                                 </Button.RenderTransform>

                             </Button>

                         </Grid>

@@ -263,13 +276,14 @@
                         <RowDefinition Height="auto"/>

                         <RowDefinition Height="auto"/>

                     </Grid.RowDefinitions>

-                    <TextBlock x:Name="_CallStatus_"

+                    <!-- KEEP _CallStatus_ FOR DEBUG -->

+                    <!--<TextBlock x:Name="_CallStatus_"

                            Grid.Row="0"

                            Foreground="White"

                            Text="{x:Bind _callStatus, Mode=OneWay}"

                            Visibility="{x:Bind _callStatus, Converter={StaticResource _HasAnActiveCall_}, Mode=OneWay}"

                            HorizontalAlignment="Center">

-                    </TextBlock>

+                    </TextBlock>-->

                     <StackPanel Orientation="Horizontal"

                                 Visibility="Visible"

                                 Grid.Row="1"

diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index d553670..a9b8dd1 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -122,14 +122,12 @@
             return;

         }

 

-        item->_callStatus = state;

-

         switch (state) {

         case CallStatus::NONE:

         case CallStatus::ENDED:

         {

             bool isInCall = false;

-            for (auto item : SmartPanelItemsViewModel::instance->itemsList) {

+            for (auto item : SmartPanelItemsViewModel::instance->itemsList) { // WTF!!! item instead of it!!!! (XXX)

                 if (item->_callId && item->_callStatus == CallStatus::IN_PROGRESS) {

                     isInCall = true;

                     RingD::instance->currentCallId = item->_callId;

@@ -138,8 +136,6 @@
             }

             if (!isInCall)

                 _settingsMenuButton_->Visibility = VIS::Visible;

-

-            item->_callId = "";

             break;

         }

         case CallStatus::IN_PROGRESS:

@@ -541,8 +537,9 @@
                         RingD::instance->pauseCall(Utils::toString(it->_callId));

 

                 if (item->_callStatus == CallStatus::ENDED || item->_callStatus == CallStatus::NONE) {

-                    item->_callStatus == CallStatus::OUTGOING_REQUESTED;

+                    item->_callStatus = CallStatus::OUTGOING_REQUESTED;

                     RingD::instance->placeCall(contact);

+                    item->_contact->_lastTime = "looking for " + item->_contact->_name + ".";

                 }

 

                 /* move the item of the top of the list */

@@ -1863,3 +1860,26 @@
         _smartList_->ScrollIntoView(item);

     }

 }

+

+Object ^ RingClientUWP::Views::CallStatusToSpinnerVisibility::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)

+{

+    auto callStatus = static_cast<CallStatus>(value);

+

+

+    if (callStatus == CallStatus::INCOMING_RINGING

+            || callStatus == CallStatus::OUTGOING_REQUESTED

+            || callStatus == CallStatus::OUTGOING_RINGING

+            || callStatus == CallStatus::SEARCHING)

+        return  Windows::UI::Xaml::Visibility::Visible;

+    else

+        return  Windows::UI::Xaml::Visibility::Collapsed;

+

+}

+

+Object ^ RingClientUWP::Views::CallStatusToSpinnerVisibility::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)

+{

+    throw ref new Platform::NotImplementedException();

+}

+

+RingClientUWP::Views::CallStatusToSpinnerVisibility::CallStatusToSpinnerVisibility()

+{}

diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h
index 72e47a5..a9017d1 100644
--- a/SmartPanel.xaml.h
+++ b/SmartPanel.xaml.h
@@ -94,6 +94,13 @@
     boolToVisibility();

 };

 

+public ref class CallStatusToSpinnerVisibility sealed : IValueConverter {

+public:

+    virtual Object^ Convert(Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object^ parameter, String^ language);

+    virtual Object^ ConvertBack(Object^ value, Windows::UI::Xaml::Interop::TypeName  targetType, Object^ parameter, String^ language);

+    CallStatusToSpinnerVisibility();

+};

+

 public ref class SmartPanel sealed

 {

 public:

diff --git a/SmartPanelItem.cpp b/SmartPanelItem.cpp
index e093cca..f0d8b43 100644
--- a/SmartPanelItem.cpp
+++ b/SmartPanelItem.cpp
@@ -35,6 +35,7 @@
     videoMuted_ = false;

     isSelected_ = false;

     isHovered_ = false;

+    _callStatus = CallStatus::NONE;

 

     RingD::instance->callPlaced += ref new RingClientUWP::CallPlaced(this, &RingClientUWP::Controls::SmartPanelItem::OncallPlaced);

 }

diff --git a/SmartPanelItemsViewModel.cpp b/SmartPanelItemsViewModel.cpp
index b06cd06..5257cb7 100644
--- a/SmartPanelItemsViewModel.cpp
+++ b/SmartPanelItemsViewModel.cpp
@@ -25,6 +25,7 @@
 using namespace Windows::Storage;

 using namespace Windows::Storage::Streams;

 using namespace Windows::UI::Core;

+using namespace Windows::Globalization::DateTimeFormatting;

 

 

 using namespace RingClientUWP;

@@ -33,6 +34,7 @@
 SmartPanelItemsViewModel::SmartPanelItemsViewModel()

 {

     itemsList_ = ref new Vector<SmartPanelItem^>();

+    RingD::instance->stateChange += ref new RingClientUWP::StateChange(this, &RingClientUWP::ViewModel::SmartPanelItemsViewModel::OnstateChange);

 }

 

 SmartPanelItem^

@@ -97,3 +99,55 @@
         }

     }

 }

+

+void RingClientUWP::ViewModel::SmartPanelItemsViewModel::OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code)

+{

+    auto item = SmartPanelItemsViewModel::instance->findItem(callId);

+

+    if (!item) {

+        WNG_("item not found");

+        return;

+    }

+

+    item->_callStatus = state;

+

+    Windows::Globalization::Calendar^ calendar = ref new Windows::Globalization::Calendar();

+    Windows::Foundation::DateTime dateTime = calendar->GetDateTime();

+    auto timestampFormatter = ref new DateTimeFormatter("day month year hour minute second");

+

+    switch (state) {

+    case CallStatus::ENDED:

+    {

+        item->_contact->_lastTime = "Last call : " + timestampFormatter->Format(dateTime) + ".";

+        ContactsViewModel::instance->saveContactsToFile();

+        break;

+    }

+    case CallStatus::IN_PROGRESS:

+    {

+        item->_contact->_lastTime = "in progress.";

+        break;

+    }

+    case CallStatus::PEER_PAUSED:

+    {

+        item->_contact->_lastTime = "paused by "+ item->_contact->_name+".";

+        break;

+    }

+    case CallStatus::PAUSED:

+    {

+        item->_contact->_lastTime = "paused.";

+        break;

+    }

+    case CallStatus::OUTGOING_REQUESTED:

+    case CallStatus::OUTGOING_RINGING:

+    case CallStatus::SEARCHING:

+    {

+        item->_contact->_lastTime = "looking for " + item->_contact->_name + ".";

+        break;

+    }

+    case CallStatus::INCOMING_RINGING:

+        item->_contact->_lastTime = "incoming call from " + item->_contact->_name + ".";

+        break;

+    default:

+        break;

+    }

+}

diff --git a/SmartPanelItemsViewModel.h b/SmartPanelItemsViewModel.h
index ea854e0..9fdf3af 100644
--- a/SmartPanelItemsViewModel.h
+++ b/SmartPanelItemsViewModel.h
@@ -81,8 +81,7 @@
     Vector<SmartPanelItem^>^ itemsList_;

     SmartPanelItem^ currentItem_;

     SmartPanelItem^ oldItem_;

-

-

+    void OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code);

 };

 }

 }

diff --git a/Styles.xaml b/Styles.xaml
index 5a14e5d..994bb37 100644
--- a/Styles.xaml
+++ b/Styles.xaml
@@ -467,5 +467,14 @@
             </Setter.Value>

         </Setter>

     </Style>

+    <Style x:Key="ButtonStyleForCallBar"

+           TargetType="Button">

+        <Setter Property="Foreground"

+                Value="White"/>

+        <Setter Property="Background"

+                Value="#004c60"/>

+        <Setter Property="BorderThickness"

+                Value="0"/>

+    </Style>

 

 </ResourceDictionary>