call : accept/reject incoming calls

- removes contacts as sources for the smartList.
- creates smartListItems, and set them as sources for the smartList.
  SmartListItem is a UI control, not a model.
- adds contacts and calls (associated) inside smartListItem.
- removes some UI property from contact class (model).
- adds a new filter : Controls, where smartListItems belongs.

Tuleap: #1014
Change-Id: Ia7679c2328f9dc85b6265c5e518aad08805230fb
diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index db4bf79..8ac82bd 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -17,12 +17,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.   *

  **************************************************************************/

 #include "pch.h"

-

+#include <string> // move it

 #include "SmartPanel.xaml.h"

 

 using namespace Platform;

 

 using namespace RingClientUWP;

+using namespace RingClientUWP::Controls;

 using namespace RingClientUWP::Views;

 using namespace RingClientUWP::ViewModel;

 using namespace Windows::Media::Capture;

@@ -42,6 +43,12 @@
 {

     InitializeComponent();

 

+    _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;

+

+    /* populate the smartlist */

+    smartPanelItemsList_ = ref new Vector<SmartPanelItem^>();

+    _smartList_->ItemsSource = smartPanelItemsList_;

+

     /* connect delegates */

     Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {

         _accountsList_->SelectedIndex = index;

@@ -56,9 +63,52 @@
         _accountsListScrollView_->UpdateLayout();

         _accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);

     });

+    CallsViewModel::instance->callRecieved += ref new RingClientUWP::CallRecieved([&](

+    Call^ call) {

+        auto from = call->from;

+        auto contact = ContactsViewModel::instance->findContactByName(from);

 

-    _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;

-    _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;

+        if (contact == nullptr)

+            contact = ContactsViewModel::instance->addNewContact(from, from); // contact checked inside addNewContact.

+

+        if (contact == nullptr) {

+            ERR_("contact not handled!");

+            return;

+        }

+

+        auto item = findItem(contact);

+        item->_call = call;

+    });

+    RingD::instance->stateChange += ref new StateChange([this](String^ callId, String^ state, int code) {

+        auto call = CallsViewModel::instance->findCall(callId);

+

+        if (call == nullptr)

+            return;

+

+        auto item = findItem(call);

+

+        if (!item) {

+            WNG_("item not found");

+            return;

+        }

+

+        if (call->state == "incoming call")

+            item->_callBar = Windows::UI::Xaml::Visibility::Visible;

+

+        if (call->state == "CURRENT")

+            item->_callBar = Windows::UI::Xaml::Visibility::Collapsed;

+

+        if (call->state == "")

+            item->_callBar = Windows::UI::Xaml::Visibility::Collapsed;

+    });

+

+

+    ContactsViewModel::instance->contactAdded += ref new ContactAdded([this](Contact^ contact) {

+        auto smartPanelItem = ref new SmartPanelItem();

+        smartPanelItem->_contact = contact;

+        smartPanelItemsList_->Append(smartPanelItem);

+    });

+

 }

 

 void

@@ -177,7 +227,8 @@
 SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)

 {

     auto listbox = safe_cast<ListBox^>(sender);

-    auto contact = safe_cast<Contact^>(listbox->SelectedItem);

+    auto item = safe_cast<SmartPanelItem^>(listbox->SelectedItem);

+    auto contact = safe_cast<Contact^>(item->_contact);

     ContactsViewModel::instance->selectedContact = contact;

 }

 

@@ -217,20 +268,37 @@
 void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

 {

     auto button = dynamic_cast<Button^>(e->OriginalSource);

-    auto contact = dynamic_cast<Contact^>(button->DataContext);

-    auto call = contact->_call;

+    auto call = dynamic_cast<Call^>(button->DataContext);

 

     call->refuse();

-    contact->_contactBarHeight = 0;

 }

 

 

 void RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)

 {

     auto button = dynamic_cast<Button^>(e->OriginalSource);

-    auto contact = dynamic_cast<Contact^>(button->DataContext);

-    auto call = contact->_call;

+    auto call = dynamic_cast<Call^>(button->DataContext);

 

     call->accept();

-    contact->_contactBarHeight = 0;

 }

+

+SmartPanelItem^

+SmartPanel::findItem(Contact^ contact)

+{

+    for each (SmartPanelItem^ item in smartPanelItemsList_)

+        if (item->_contact == contact)

+            return item;

+

+    return nullptr;

+}

+

+

+SmartPanelItem^

+SmartPanel::findItem(Call^ call)

+{

+    for each (SmartPanelItem^ item in smartPanelItemsList_)

+        if (item->_call == call)

+            return item;

+

+    return nullptr;

+}
\ No newline at end of file