Commit 25608ed8 authored by atraczyk's avatar atraczyk

contacts: add a view-model for SmartPanelItem controls

- adds a view-model to expose SmartPanelItem controls
- replaces SmartPanelItem control functions for finding SmartPanelItems
  originally defined in SmartPanel
- adds selection of the corresponding SmartPanelItem when calling,
  and accepting/refusing a call

Change-Id: I635a805a8e8bf6a412a6ca3d8c7ec907d3c16c2b
Tuleap: #1041
parent 7bef149e
...@@ -70,8 +70,9 @@ ContactsViewModel::ContactsViewModel() ...@@ -70,8 +70,9 @@ ContactsViewModel::ContactsViewModel()
Contact^ // refacto : remove "byName" Contact^ // refacto : remove "byName"
ContactsViewModel::findContactByName(String^ name) ContactsViewModel::findContactByName(String^ name)
{ {
auto trimmedName = Utils::Trim(name);
for each (Contact^ contact in contactsList_) for each (Contact^ contact in contactsList_)
if (contact->name_ == name) if (contact->name_ == trimmedName)
return contact; return contact;
return nullptr; return nullptr;
...@@ -80,9 +81,9 @@ ContactsViewModel::findContactByName(String^ name) ...@@ -80,9 +81,9 @@ ContactsViewModel::findContactByName(String^ name)
Contact^ Contact^
ContactsViewModel::addNewContact(String^ name, String^ ringId) ContactsViewModel::addNewContact(String^ name, String^ ringId)
{ {
auto trimedName = Utils::Trim(name); auto trimmedName = Utils::Trim(name);
if (contactsList_ && !findContactByName(trimedName)) { if (contactsList_ && !findContactByName(trimmedName)) {
Contact^ contact = ref new Contact(trimedName, trimedName, nullptr, 0); Contact^ contact = ref new Contact(trimmedName, trimmedName, nullptr, 0);
contactsList_->Append(contact); contactsList_->Append(contact);
saveContactsToFile(); saveContactsToFile();
contactAdded(contact); contactAdded(contact);
......
...@@ -46,8 +46,7 @@ SmartPanel::SmartPanel() ...@@ -46,8 +46,7 @@ SmartPanel::SmartPanel()
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
/* populate the smartlist */ /* populate the smartlist */
smartPanelItemsList_ = ref new Vector<SmartPanelItem^>(); _smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;
_smartList_->ItemsSource = smartPanelItemsList_;
/* connect delegates */ /* connect delegates */
Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
...@@ -76,7 +75,7 @@ SmartPanel::SmartPanel() ...@@ -76,7 +75,7 @@ SmartPanel::SmartPanel()
return; return;
} }
auto item = findItem(contact); auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_call = call; item->_call = call;
}); });
RingD::instance->stateChange += ref new StateChange([this](String^ callId, String^ state, int code) { RingD::instance->stateChange += ref new StateChange([this](String^ callId, String^ state, int code) {
...@@ -85,7 +84,7 @@ SmartPanel::SmartPanel() ...@@ -85,7 +84,7 @@ SmartPanel::SmartPanel()
if (call == nullptr) if (call == nullptr)
return; return;
auto item = findItem(call); auto item = SmartPanelItemsViewModel::instance->findItem(call);
if (!item) { if (!item) {
WNG_("item not found"); WNG_("item not found");
...@@ -110,7 +109,7 @@ SmartPanel::SmartPanel() ...@@ -110,7 +109,7 @@ SmartPanel::SmartPanel()
ContactsViewModel::instance->contactAdded += ref new ContactAdded([this](Contact^ contact) { ContactsViewModel::instance->contactAdded += ref new ContactAdded([this](Contact^ contact) {
auto smartPanelItem = ref new SmartPanelItem(); auto smartPanelItem = ref new SmartPanelItem();
smartPanelItem->_contact = contact; smartPanelItem->_contact = contact;
smartPanelItemsList_->Append(smartPanelItem); SmartPanelItemsViewModel::instance->itemsList->Append(smartPanelItem);
}); });
RingD::instance->calling += ref new RingClientUWP::Calling([&]( RingD::instance->calling += ref new RingClientUWP::Calling([&](
...@@ -123,7 +122,7 @@ SmartPanel::SmartPanel() ...@@ -123,7 +122,7 @@ SmartPanel::SmartPanel()
return; return;
} }
auto item = findItem(contact); auto item = SmartPanelItemsViewModel::instance->findItem(contact);
if (item == nullptr) { if (item == nullptr) {
WNG_("cannot call the peer, smart panel item not found!"); WNG_("cannot call the peer, smart panel item not found!");
...@@ -300,6 +299,8 @@ void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::O ...@@ -300,6 +299,8 @@ void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::O
auto button = dynamic_cast<Button^>(e->OriginalSource); auto button = dynamic_cast<Button^>(e->OriginalSource);
auto call = dynamic_cast<Call^>(button->DataContext); auto call = dynamic_cast<Call^>(button->DataContext);
_smartList_->SelectedIndex = SmartPanelItemsViewModel::instance->getIndex(call);
call->refuse(); call->refuse();
} }
...@@ -309,28 +310,9 @@ void RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::O ...@@ -309,28 +310,9 @@ void RingClientUWP::Views::SmartPanel::_acceptIncomingCallBtn__Click(Platform::O
auto button = dynamic_cast<Button^>(e->OriginalSource); auto button = dynamic_cast<Button^>(e->OriginalSource);
auto call = dynamic_cast<Call^>(button->DataContext); auto call = dynamic_cast<Call^>(button->DataContext);
call->accept(); _smartList_->SelectedIndex = SmartPanelItemsViewModel::instance->getIndex(call);
}
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; call->accept();
} }
void void
...@@ -340,6 +322,8 @@ SmartPanel::_callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::Rou ...@@ -340,6 +322,8 @@ SmartPanel::_callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::Rou
auto item = dynamic_cast<SmartPanelItem^>(button->DataContext); auto item = dynamic_cast<SmartPanelItem^>(button->DataContext);
auto contact = item->_contact; auto contact = item->_contact;
_smartList_->SelectedIndex = SmartPanelItemsViewModel::instance->getIndex(contact);
RingD::instance->placeCall(contact); RingD::instance->placeCall(contact);
} }
......
...@@ -32,8 +32,6 @@ public ref class SmartPanel sealed ...@@ -32,8 +32,6 @@ public ref class SmartPanel sealed
public: public:
SmartPanel(); SmartPanel();
void updatePageContent(); void updatePageContent();
Controls::SmartPanelItem^ findItem(Contact^ contact);
Controls::SmartPanelItem^ findItem(Call^ call);
internal: internal:
enum class Mode { Minimized, Normal }; enum class Mode { Minimized, Normal };
...@@ -65,7 +63,6 @@ private: ...@@ -65,7 +63,6 @@ private:
void _contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); void _contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e);
/* members */ /* members */
Vector<Controls::SmartPanelItem^>^ smartPanelItemsList_;
}; };
} }
} }
\ No newline at end of file
/***************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "pch.h"
#include "SmartPanelItemsViewModel.h"
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Data::Json;
using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
using namespace Windows::UI::Core;
using namespace RingClientUWP;
using namespace ViewModel;
SmartPanelItemsViewModel::SmartPanelItemsViewModel()
{
itemsList_ = ref new Vector<SmartPanelItem^>();
}
SmartPanelItem^
SmartPanelItemsViewModel::findItem(Call^ call)
{
for each (SmartPanelItem^ item in itemsList)
if (item->_call == call)
return item;
return nullptr;
}
SmartPanelItem^
SmartPanelItemsViewModel::findItem(Contact^ contact)
{
for each (SmartPanelItem^ item in itemsList)
if (item->_contact == contact)
return item;
return nullptr;
}
unsigned int
SmartPanelItemsViewModel::getIndex(Call^ call)
{
unsigned int i;
for (i = 0; i < itemsList_->Size; i++) {
if (itemsList_->GetAt(i)->_call == call)
break;
}
return i;
}
unsigned int
SmartPanelItemsViewModel::getIndex(Contact^ contact)
{
unsigned int i;
for (i = 0; i < itemsList_->Size; i++) {
if (itemsList_->GetAt(i)->_contact == contact)
break;
}
return i;
}
\ No newline at end of file
/***************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#pragma once
using namespace Platform::Collections;
using namespace Concurrency;
using namespace RingClientUWP;
using namespace RingClientUWP::Controls;
namespace RingClientUWP
{
namespace ViewModel {
public ref class SmartPanelItemsViewModel sealed
{
internal:
/* singleton */
static property SmartPanelItemsViewModel^ instance
{
SmartPanelItemsViewModel^ get()
{
static SmartPanelItemsViewModel^ instance_ = ref new SmartPanelItemsViewModel();
return instance_;
}
}
/* functions */
SmartPanelItem^ findItem(Call^ call);
SmartPanelItem^ findItem(Contact^ contact);
unsigned int getIndex(Call^ call);
unsigned int getIndex(Contact^ contact);
property Vector<SmartPanelItem^>^ itemsList
{
Vector<SmartPanelItem^>^ get()
{
return itemsList_;
}
}
/* events */
private:
SmartPanelItemsViewModel(); // singleton
Vector<SmartPanelItem^>^ itemsList_;
SmartPanelItem^ currentItem_;
SmartPanelItem^ oldItem_;
};
}
}
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "Conversation.h" #include "Conversation.h"
#include "MainPage.xaml.h" #include "MainPage.xaml.h"
#include "SmartPanelItem.h" #include "SmartPanelItem.h"
#include "SmartPanelItemsViewModel.h"
/* ensure to be accessed from anywhere */ /* ensure to be accessed from anywhere */
#include "RingD.h" #include "RingD.h"
......
...@@ -190,6 +190,7 @@ ...@@ -190,6 +190,7 @@
<DependentUpon>SmartPanel.xaml</DependentUpon> <DependentUpon>SmartPanel.xaml</DependentUpon>
</ClInclude> </ClInclude>
<ClInclude Include="SmartPanelItem.h" /> <ClInclude Include="SmartPanelItem.h" />
<ClInclude Include="SmartPanelItemsViewModel.h" />
<ClInclude Include="UserPreferences.h" /> <ClInclude Include="UserPreferences.h" />
<ClInclude Include="Utils.h" /> <ClInclude Include="Utils.h" />
<ClInclude Include="VideoPage.xaml.h"> <ClInclude Include="VideoPage.xaml.h">
...@@ -303,6 +304,7 @@ ...@@ -303,6 +304,7 @@
<DependentUpon>SmartPanel.xaml</DependentUpon> <DependentUpon>SmartPanel.xaml</DependentUpon>
</ClCompile> </ClCompile>
<ClCompile Include="SmartPanelItem.cpp" /> <ClCompile Include="SmartPanelItem.cpp" />
<ClCompile Include="SmartPanelItemsViewModel.cpp" />
<ClCompile Include="UserPreferences.cpp" /> <ClCompile Include="UserPreferences.cpp" />
<ClCompile Include="VideoPage.xaml.cpp"> <ClCompile Include="VideoPage.xaml.cpp">
<DependentUpon>VideoPage.xaml</DependentUpon> <DependentUpon>VideoPage.xaml</DependentUpon>
......
...@@ -86,6 +86,9 @@ ...@@ -86,6 +86,9 @@
<ClCompile Include="SmartPanelItem.cpp"> <ClCompile Include="SmartPanelItem.cpp">
<Filter>Controls</Filter> <Filter>Controls</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="SmartPanelItemsViewModel.cpp">
<Filter>ModelViews</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="pch.h" /> <ClInclude Include="pch.h" />
...@@ -134,6 +137,9 @@ ...@@ -134,6 +137,9 @@
<ClInclude Include="SmartPanelItem.h"> <ClInclude Include="SmartPanelItem.h">
<Filter>Controls</Filter> <Filter>Controls</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="SmartPanelItemsViewModel.h">
<Filter>ModelViews</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="Assets\LockScreenLogo.scale-200.png"> <Image Include="Assets\LockScreenLogo.scale-200.png">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment