Commit bf406b2c authored by Nicolas Jager's avatar Nicolas Jager

add accountListItem

Change-Id: Ic59097eb8158e8bae606409500e295684b4e5e29
Tuleap: #1238
parent 586e3620
......@@ -38,7 +38,6 @@ Account::Account(String^ name,
accountType_ = accountType;
accountID_ = accountID;
_deviceId = deviceId;
_isSelected = false;
}
void
......
......@@ -45,22 +45,12 @@ public:
devicesIdList_ = value;
}
}
property bool _isSelected {
void set(bool value) {
// isSelected_ = value; disabled on purpose for future use
PropertyChanged(this, ref new PropertyChangedEventArgs("_isSelected"));
}
bool get() {
return isSelected_;
}
}
protected:
void NotifyPropertyChanged(String^ propertyName);
private:
Windows::Foundation::Collections::IVector<String^>^ devicesIdList_;
bool isSelected_;
};
}
......
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <traczyk.andreas@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 "AccountListItem.h"
using namespace Windows::ApplicationModel::Core;
using namespace Platform;
using namespace Windows::Data::Json;
using namespace Windows::UI::Core;
using namespace RingClientUWP;
using namespace RingClientUWP::Controls;
using namespace ViewModel;
AccountListItem::AccountListItem(Account^ a)
{
_account = a;
}
void
AccountListItem::NotifyPropertyChanged(String^ propertyName)
{
CoreApplicationView^ view = CoreApplication::MainView;
view->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High,
ref new DispatchedHandler([this, propertyName]()
{
PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
}));
}
\ No newline at end of file
#pragma once
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <traczyk.andreas@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/>. *
**************************************************************************/
using namespace Platform;
using namespace Windows::Data::Json;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Data;
namespace RingClientUWP
{
namespace Controls {
public ref class AccountListItem sealed : public INotifyPropertyChanged
{
public:
AccountListItem(Account^ a);
virtual event PropertyChangedEventHandler^ PropertyChanged;
property Account^ _account;
property bool _isSelected {
void set(bool value) {
isSelected_ = value;
PropertyChanged(this, ref new PropertyChangedEventArgs("_isSelected"));
}
bool get() {
return isSelected_;
}
}
protected:
void NotifyPropertyChanged(String^ propertyName);
private:
bool isSelected_;
};
}
}
/***************************************************************************
* 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 "AccountListItemsViewModel.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;
AccountListItemsViewModel::AccountListItemsViewModel()
{
itemsList_ = ref new Vector<AccountListItem^>();
/* connect to delegates */
AccountsViewModel::instance->accountAdded += ref new RingClientUWP::AccountAdded(this, &RingClientUWP::ViewModel::AccountListItemsViewModel::OnaccountAdded);
AccountsViewModel::instance->clearAccountsList += ref new RingClientUWP::ClearAccountsList(this, &RingClientUWP::ViewModel::AccountListItemsViewModel::OnclearAccountsList);
}
void RingClientUWP::ViewModel::AccountListItemsViewModel::OnaccountAdded(RingClientUWP::Account ^account)
{
auto item = ref new AccountListItem(account);
itemsList_->Append(item);
}
void RingClientUWP::ViewModel::AccountListItemsViewModel::OnclearAccountsList()
{
itemsList_->Clear();
}
/***************************************************************************
* 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 AccountListItemsViewModel sealed
{
internal:
/* singleton */
static property AccountListItemsViewModel^ instance
{
AccountListItemsViewModel^ get()
{
static AccountListItemsViewModel^ instance_ = ref new AccountListItemsViewModel();
return instance_;
}
}
/* functions */
// to do
property Vector<AccountListItem^>^ itemsList
{
Vector<AccountListItem^>^ get()
{
return itemsList_;
}
}
property AccountListItem^ _selectedItem
{
AccountListItem^ get()
{
return currentItem_;
}
void set(AccountListItem^ value)
{
currentItem_ = value;
}
}
private:
AccountListItemsViewModel(); // singleton
Vector<AccountListItem^>^ itemsList_;
AccountListItem^ currentItem_;
void OnaccountAdded(RingClientUWP::Account ^account);
void OnclearAccountsList();
};
}
}
......@@ -31,19 +31,21 @@ AccountsViewModel::AccountsViewModel()
void
AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId)
{
auto account = ref new Account(
Utils::toPlatformString(name),
Utils::toPlatformString(ringID),
Utils::toPlatformString(accountType),
Utils::toPlatformString(accountID),
Utils::toPlatformString(deviceId));
accountsList_->Append(ref new Account(
Utils::toPlatformString(name),
Utils::toPlatformString(ringID),
Utils::toPlatformString(accountType),
Utils::toPlatformString(accountID),
Utils::toPlatformString(deviceId)
));
accountsList_->Append(account);
updateScrollView();
accountAdded(account);
}
void
AccountsViewModel::clearAccountList()
{
accountsList_->Clear();
clearAccountsList();
}
\ No newline at end of file
......@@ -27,6 +27,8 @@ namespace RingClientUWP
delegate void NewAccountSelected();
delegate void NoAccountSelected();
delegate void UpdateScrollView();
delegate void AccountAdded(Account^ account);
delegate void ClearAccountsList();
namespace ViewModel {
public ref class AccountsViewModel sealed
......@@ -47,27 +49,6 @@ internal:
void clearAccountList();
/* properties */
property Account^ selectedAccount
{
Account^ get()
{
return currentItem_;
}
void set(Account^ value)
{
oldItem_ = currentItem_;
if (oldItem_)
oldItem_->_isSelected = false;
currentItem_ = value;
if (currentItem_)
currentItem_->_isSelected = true;
if (value)
newAccountSelected();
else
noAccountSelected();
}
}
property Vector<Account^>^ accountsList
{
Vector<Account^>^ get()
......@@ -80,12 +61,12 @@ internal:
event NewAccountSelected^ newAccountSelected;
event NoAccountSelected^ noAccountSelected;
event UpdateScrollView^ updateScrollView;
event AccountAdded^ accountAdded;
event ClearAccountsList^ clearAccountsList;
private:
AccountsViewModel(); // singleton
Vector<Account^>^ accountsList_;
Account^ currentItem_;
Account^ oldItem_;
};
}
......
......@@ -73,7 +73,7 @@ RingClientUWP::RingD::reloadAccountList()
void RingClientUWP::RingD::sendAccountTextMessage(String^ message)
{
/* account id */
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
std::wstring accountId2(accountId->Begin());
std::string accountId3(accountId2.begin(), accountId2.end());
......@@ -109,7 +109,7 @@ void RingClientUWP::RingD::sendAccountTextMessage(String^ message)
void RingClientUWP::RingD::sendSIPTextMessage(String^ message)
{
/* account id */
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
std::wstring accountId2(accountId->Begin());
std::string accountId3(accountId2.begin(), accountId2.end());
......@@ -164,7 +164,7 @@ void RingClientUWP::RingD::placeCall(Contact^ contact)
{
MSG_("!--->> placeCall");
auto to = contact->ringID_;
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
auto to2 = Utils::toString(to);
auto accountId2 = Utils::toString(accountId);
......
......@@ -170,9 +170,9 @@
</Grid>
</Grid>
</DataTemplate>
<!-- template for accounts. -->
<DataTemplate x:Key="AccountTemplate"
x:DataType="local:Account">
<!-- template for AccountListItems. -->
<DataTemplate x:Key="AccountListItemsTemplate"
x:DataType="controls:AccountListItem">
<Grid Margin="0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
......@@ -184,7 +184,7 @@
<Image x:Name="_AccountTypeIcon_"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Source="{x:Bind accountType_, Converter={StaticResource _AccountTypeToSourceImage_}, Mode=OneWay}"/>
Source="{x:Bind _account.accountType_, Converter={StaticResource _AccountTypeToSourceImage_}, Mode=OneWay}"/>
</Border>
<Button x:Name="_editAccountMenuButton_"
HorizontalAlignment="Right"
......@@ -203,11 +203,11 @@
<StackPanel Grid.Column="1">
<TextBlock x:Name="_accountName_"
Style="{StaticResource TextStyle5}"
Text="{x:Bind name_}"/>
Text="{x:Bind _account.name_}"/>
<TextBlock x:Name="_ringID_"
Grid.ColumnSpan="2"
Style="{StaticResource TextStyle6}"
Text="{x:Bind ringID_}"/>
Text="{x:Bind _account.ringID_}"/>
</StackPanel>
</Grid>
</DataTemplate>
......@@ -440,7 +440,7 @@
Width="320"
ItemContainerStyle="{StaticResource contactsListBoxStyle}"
Background="#FFE4F1F9"
ItemTemplate="{StaticResource AccountTemplate}"/>
ItemTemplate="{StaticResource AccountListItemsTemplate}"/>
</ScrollViewer>
<Button x:Name="_addAccountBtn_"
Grid.Row="1"
......
......@@ -39,6 +39,8 @@ using namespace Windows::Foundation;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Foundation;
using namespace Concurrency;
using namespace Platform::Collections;
using namespace Windows::ApplicationModel::Core;
......@@ -49,7 +51,8 @@ SmartPanel::SmartPanel()
{
InitializeComponent();
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
/* populate accounts listBox*/
_accountsList_->ItemsSource = AccountListItemsViewModel::instance->itemsList;
/* populate the smartlist */
_smartList_->ItemsSource = SmartPanelItemsViewModel::instance->itemsList;
......@@ -136,25 +139,25 @@ SmartPanel::SmartPanel()
void
RingClientUWP::Views::SmartPanel::updatePageContent()
{
auto account = AccountsViewModel::instance->selectedAccount;
if (!account)
auto accountListItem = AccountListItemsViewModel::instance->_selectedItem;
if (!accountListItem)
return;
auto name = account->name_;
auto name = accountListItem->_account->name_;
Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
Configuration::UserPreferences::instance->save();
_selectedAccountName_->Text = name;
_selectedAccountName_->Text = name; // refacto : bind this in xaml directly
/// _devicesIdList_->ItemsSource = account->_devicesIdList;
_deviceId_->Text = account->_deviceId; /* this is the current device ...
_deviceId_->Text = accountListItem->_account->_deviceId; /* this is the current device ...
... in the way to get all associated devices, we have to querry the daemon : */
_devicesMenuButton_->Visibility = (account->accountType_ == "RING")
_devicesMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
_shareMenuButton_->Visibility = (account->accountType_ == "RING")
_shareMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
}
......@@ -321,8 +324,8 @@ SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI
}
}
}
auto account = safe_cast<Account^>(listbox->SelectedItem);
AccountsViewModel::instance->selectedAccount = account;
auto account = safe_cast<AccountListItem^>(listbox->SelectedItem);
AccountListItemsViewModel::instance->_selectedItem = account;
updatePageContent();
}
......@@ -432,7 +435,7 @@ void RingClientUWP::Views::SmartPanel::_contactItem__PointerReleased(Platform::O
void RingClientUWP::Views::SmartPanel::generateQRcode()
{
auto ringId = AccountsViewModel::instance->selectedAccount->ringID_;
auto ringId = AccountListItemsViewModel::instance->_selectedItem->_account->ringID_;
auto ringId2 = Utils::toString(ringId);
_ringId_->Text = ringId;
......@@ -589,7 +592,7 @@ void RingClientUWP::Views::SmartPanel::_devicesMenuButton__Checked(Platform::Obj
_waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
RingD::instance->askToRefreshKnownDevices(accountId);
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
......@@ -613,7 +616,7 @@ void RingClientUWP::Views::SmartPanel::_addDevice__Click(Platform::Object^ sende
void RingClientUWP::Views::SmartPanel::OndevicesListRefreshed(Platform::Collections::Vector<Platform::String ^, std::equal_to<Platform::String ^>, true> ^devicesList)
{
_waitingDevicesList_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
AccountsViewModel::instance->selectedAccount->_devicesIdList = devicesList;
AccountListItemsViewModel::instance->_selectedItem->_account->_devicesIdList = devicesList;
_devicesIdList_->ItemsSource = devicesList;
_devicesIdList_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
......@@ -624,7 +627,7 @@ void RingClientUWP::Views::SmartPanel::_pinGeneratorYes__Click(Platform::Object^
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_waitingForPin_->Visibility = Windows::UI::Xaml::Visibility::Visible;
auto accountId = AccountsViewModel::instance->selectedAccount->accountID_;
auto accountId = AccountListItemsViewModel::instance->_selectedItem->_account->accountID_;
auto password = _passwordForPinGenerator_->Password;
_passwordForPinGenerator_->Password = "";
......@@ -690,7 +693,7 @@ Object ^ RingClientUWP::Views::AccountSelectedToVisibility::Convert(Object ^ val
{
//auto accountId = static_cast<bool(value);
if (/*AccountsViewModel::instance->selectedAccount->_isSelected ==*/ (bool)value == true)
if (/*AccountListItemsViewModel::instance->_selectedItem->_account->_isSelected ==*/ (bool)value == true)
return Windows::UI::Xaml::Visibility::Visible;
return Windows::UI::Xaml::Visibility::Collapsed;
......
......@@ -32,6 +32,8 @@
/* required by generated headers. */
#include "App.xaml.h"
#include "Account.h"
#include "AccountListItem.h"
#include "AccountListItemsViewModel.h"
#include "AccountsViewModel.h"
#include "Contact.h"
#include "ContactsViewModel.h"
......
......@@ -166,6 +166,8 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Account.h" />
<ClInclude Include="AccountListItem.h" />
<ClInclude Include="AccountListItemsViewModel.h" />
<ClInclude Include="AccountsViewModel.h" />
<ClInclude Include="Contact.h" />
<ClInclude Include="ContactsViewModel.h" />
......@@ -284,6 +286,8 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="Account.cpp" />
<ClCompile Include="AccountListItem.cpp" />
<ClCompile Include="AccountListItemsViewModel.cpp" />
<ClCompile Include="AccountsViewModel.cpp" />
<ClCompile Include="App.xaml.cpp">
<DependentUpon>App.xaml</DependentUpon>
......
......@@ -104,6 +104,12 @@
<ClCompile Include="VideoCaptureManager.cpp">
<Filter>Media\Video</Filter>
</ClCompile>
<ClCompile Include="AccountListItem.cpp">
<Filter>Controls</Filter>
</ClCompile>
<ClCompile Include="AccountListItemsViewModel.cpp">
<Filter>ModelViews</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
......@@ -164,6 +170,12 @@
<ClInclude Include="Globals.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="AccountListItem.h">
<Filter>Controls</Filter>
</ClInclude>
<ClInclude Include="AccountListItemsViewModel.h">
<Filter>ModelViews</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<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