Commit 6abfc0d2 authored by Nicolas Jager's avatar Nicolas Jager

smartpanel : adds ui for ring accounts edition

Change-Id: Id773083f7266ea45593f80ea6ec595c90bf0b04c
Tuleap: #1243
parent a570103b
......@@ -31,13 +31,15 @@ Account::Account(String^ name,
String^ ringID,
String^ accountType,
String^ accountID,
String^ deviceId)
String^ deviceId,
bool upnpState)
{
name_ = name;
ringID_ = ringID;
accountType_ = accountType;
accountID_ = accountID;
_deviceId = deviceId;
_upnpState = _upnpState;
}
void
......
......@@ -28,11 +28,20 @@ namespace RingClientUWP
public ref class Account sealed : public INotifyPropertyChanged
{
public:
Account(String^ name, String^ ringID, String^ accountType, String^ accountID, String^ deviceId);
Account(String^ name, String^ ringID, String^ accountType, String^ accountID, String^ deviceId, bool upnpState);
virtual event PropertyChangedEventHandler^ PropertyChanged;
property String^ name_;
property String^ name_
{
String^ get() {
return name__;
}
void set(String^ value) {
name__ = value;
PropertyChanged(this, ref new PropertyChangedEventArgs("name_"));
}
}
property String^ ringID_;
property String^ accountType_; // refacto : create a enum accountType
property String^ accountID_;
......@@ -44,13 +53,15 @@ public:
void set(Windows::Foundation::Collections::IVector<String^>^ value) {
devicesIdList_ = value;
}
}
};
property bool _upnpState;
protected:
void NotifyPropertyChanged(String^ propertyName);
private:
Windows::Foundation::Collections::IVector<String^>^ devicesIdList_;
String^ name__;
};
}
......
......@@ -31,7 +31,8 @@ using namespace ViewModel;
AccountListItem::AccountListItem(Account^ a)
{
_account = a;
_account = a;
_editionMode = false;
}
void
......
......@@ -41,6 +41,7 @@ public:
return isSelected_;
}
}
property bool _editionMode;
protected:
void NotifyPropertyChanged(String^ propertyName);
......
......@@ -50,3 +50,13 @@ void RingClientUWP::ViewModel::AccountListItemsViewModel::OnclearAccountsList()
{
itemsList_->Clear();
}
AccountListItem^
RingClientUWP::ViewModel::AccountListItemsViewModel::findItem(String^ accountId)
{
for each (AccountListItem^ item in itemsList_)
if (item->_account->accountID_ == accountId)
return item;
return nullptr;
}
......@@ -42,9 +42,9 @@ internal:
}
/* functions */
// to do
AccountListItem^ findItem(String^ accountId);
/* properties */
property Vector<AccountListItem^>^ itemsList
{
Vector<AccountListItem^>^ get()
......@@ -61,6 +61,8 @@ internal:
}
void set(AccountListItem^ value)
{
if (currentItem_)
currentItem_->_isSelected = false;
currentItem_ = value;
}
}
......
......@@ -29,14 +29,15 @@ AccountsViewModel::AccountsViewModel()
}
void
AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId)
AccountsViewModel::add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId, bool upnpState)
{
auto account = ref new Account(
Utils::toPlatformString(name),
Utils::toPlatformString(ringID),
Utils::toPlatformString(accountType),
Utils::toPlatformString(accountID),
Utils::toPlatformString(deviceId));
Utils::toPlatformString(deviceId),
upnpState);
accountsList_->Append(account);
updateScrollView();
......@@ -48,4 +49,13 @@ AccountsViewModel::clearAccountList()
{
accountsList_->Clear();
clearAccountsList();
}
\ No newline at end of file
}
Account ^ RingClientUWP::ViewModel::AccountsViewModel::findItem(String ^ accountId)
{
for each (Account^ item in accountsList_)
if (item->accountID_ == accountId)
return item;
return nullptr;
}
......@@ -31,6 +31,7 @@ delegate void AccountAdded(Account^ account);
delegate void ClearAccountsList();
namespace ViewModel {
public ref class AccountsViewModel sealed
{
internal:
......@@ -45,8 +46,9 @@ internal:
}
/* functions */
void add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId);
void add(std::string& name, std::string& ringID, std::string& accountType, std::string& accountID, std::string& deviceId, bool upnpState);
void clearAccountList();
Account^ findItem(String^ accountId);
/* properties */
property Vector<Account^>^ accountsList
......
......@@ -27,6 +27,8 @@
#include "fileutils.h"
#include "account_schema.h"
#include "account_const.h"
#include "string_utils.h" // used to get some const expr like TRUE_STR
#include "SmartPanel.xaml.h"
......@@ -44,7 +46,7 @@ using namespace RingClientUWP::ViewModel;
void
RingClientUWP::RingD::reloadAccountList()
{
RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList();
//RingClientUWP::ViewModel::AccountsViewModel::instance->clearAccountList();
std::vector<std::string> accountList = DRing::getAccountList();
......@@ -61,6 +63,12 @@ RingClientUWP::RingD::reloadAccountList()
std::map<std::string,std::string> accountDetails = DRing::getAccountDetails(*rit);
std::string ringID(accountDetails.find(DRing::Account::ConfProperties::USERNAME)->second);
bool upnpState = (accountDetails.find(DRing::Account::ConfProperties::UPNP_ENABLED)->second == ring::TRUE_STR)
? true
: false;
MSG_("upnp state : " + accountDetails.find(DRing::Account::ConfProperties::UPNP_ENABLED)->second);
if(!ringID.empty())
ringID = ringID.substr(5);
......@@ -68,7 +76,22 @@ RingClientUWP::RingD::reloadAccountList()
auto type = accountDetails.find(DRing::Account::ConfProperties::TYPE)->second;
auto deviceId = (type == "SIP")? std::string() : accountDetails.find(DRing::Account::ConfProperties::RING_DEVICE_ID)->second;
RingClientUWP::ViewModel::AccountsViewModel::instance->add(alias, ringID, type, *rit /*account id*/, deviceId);
auto accountId = Utils::toPlatformString(*rit);
auto account = AccountsViewModel::instance->findItem(accountId);
if (account) {
account->name_ = Utils::toPlatformString(alias);
account->_upnpState = upnpState;
accountUpdated(account);
}
else {
RingClientUWP::ViewModel::AccountsViewModel::instance->add(alias, ringID, type, *rit /*account id*/, deviceId, upnpState);
}
if (editModeOn_) {
auto frame = dynamic_cast<Frame^>(Window::Current->Content);
dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(false, false);
}
}
......@@ -257,6 +280,19 @@ void RingClientUWP::RingD::eraseCacheFolder()
});
}
void RingClientUWP::RingD::updateAccount(String^ accountId)
{
editModeOn_ = true;
auto frame = dynamic_cast<Frame^>(Window::Current->Content);
dynamic_cast<RingClientUWP::MainPage^>(frame->Content)->showLoadingOverlay(true, true);
auto task = ref new RingD::Task(Request::UpdateAccount);
task->_accountId = accountId;
tasksList_.push(task);
}
void
RingClientUWP::RingD::startDaemon()
{
......@@ -398,6 +434,7 @@ RingClientUWP::RingD::startDaemon()
}),
DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]()
{
MSG_("<AccountsChanged>");
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::High,
ref new DispatchedHandler([=]() {
reloadAccountList();
......@@ -682,6 +719,19 @@ RingD::dequeueTasks()
auto password2 = Utils::toString(password);
DRing::exportOnRing(accountId2, password2);
break;
}
case Request::UpdateAccount:
{
auto accountId = task->_accountId;
auto accountId2 = Utils::toString(accountId);
auto account = AccountListItemsViewModel::instance->findItem(accountId)->_account;
std::map<std::string, std::string> accountDetails = DRing::getAccountDetails(accountId2);
accountDetails[DRing::Account::ConfProperties::UPNP_ENABLED] = (account->_upnpState) ? ring::TRUE_STR : ring::FALSE_STR;
accountDetails[DRing::Account::ConfProperties::ALIAS] = Utils::toString(account->name_);
DRing::setAccountDetails(Utils::toString(account->accountID_), accountDetails);
break;
}
default:
break;
......
......@@ -35,6 +35,7 @@ delegate void IncomingMessage(String^ callId, String^ payload);
delegate void DevicesListRefreshed(Vector<String^>^ devicesList);
delegate void ExportOnRingEnded(String^ accountId, String^ pin);
delegate void SummonWizard();
delegate void AccountUpdated(Account^ account);
public ref class RingD sealed
......@@ -96,6 +97,7 @@ internal:
void askToRefreshKnownDevices(String^ accountId);
void askToExportOnRing(String^ accountId, String^ password);
void eraseCacheFolder();
void updateAccount(String^ accountId);
/* TODO : move members */
///bool hasConfig; // replaced by startingStatus
......@@ -111,6 +113,7 @@ internal:
event DevicesListRefreshed^ devicesListRefreshed;
event ExportOnRingEnded^ exportOnRingEnded;
event SummonWizard^ summonWizard;
event AccountUpdated^ accountUpdated;
private:
/* sub classes */
......@@ -126,7 +129,8 @@ private:
UnPauseCall,
RegisterDevice,
GetKnownDevices,
ExportOnRing
ExportOnRing,
UpdateAccount
};
......@@ -165,5 +169,6 @@ private:
bool daemonRunning_ = false;
std::queue<Task^> tasksList_;
StartingStatus startingStatus_ = StartingStatus::NORMAL;
bool editModeOn_ = false;
};
}
\ No newline at end of file
......@@ -192,6 +192,7 @@
VerticalAlignment="Top"
Content="&#xE104;"
FontFamily="Segoe MDL2 Assets"
Click="_editAccountMenuButton__Click"
FontSize="20"
Foreground="White"
Background="Transparent"
......@@ -204,7 +205,7 @@
<StackPanel Grid.Column="1">
<TextBlock x:Name="_accountName_"
Style="{StaticResource TextStyle5}"
Text="{x:Bind _account.name_}"/>
Text="{x:Bind _account.name_, Mode=OneWay}"/>
<TextBlock x:Name="_ringID_"
Grid.ColumnSpan="2"
Style="{StaticResource TextStyle6}"
......@@ -509,6 +510,67 @@
</StackPanel>
</Grid>
</Grid>
<!-- account edition menu. -->
<Grid x:Name="_accountEditionMenuGrid_"
Grid.Row="2"
Visibility="Collapsed"
Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Vertical"
Grid.Row="0"
Background="#FFE4F1F9">
<!-- alias sub menu. -->
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Style="{StaticResource TextSegoeStyle-20pt-black}"
Text="&#xE1CB;"/>
<TextBlock Text="Alias" Margin="10"/>
</StackPanel>
<TextBox x:Name="_aliasTextBoxEditionMenu_"
FontSize="20"
Margin="20,10"
PlaceholderText="Enter your username"/>
<!-- upnp sub menu. -->
<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Style="{StaticResource TextSegoeStyle-20pt-black}"
Text="&#xE15E;"/>
<TextBlock Text="UPnP" Margin="10"/>
</StackPanel>
<ToggleSwitch x:Name="_upnpState_"
Margin="20,10"/>
<!-- delete account sub menu. -->
<!--<StackPanel Orientation="Horizontal" Margin="10">
<TextBlock Style="{StaticResource TextSegoeStyle-20pt-black}"
Text="&#xE74D;"/>
<TextBlock Text="Delete account" Margin="10"/>
</StackPanel>
<ToggleButton x:Name="_deleteAccountBtnEditionMenu_"
Margin="20,10"
Content="Delete"/>-->
</StackPanel>
<!-- buttons yes/no to accept the modification. -->
<Grid Grid.Row="1">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center">
<Button x:Name="_acceptAccountModification_"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="&#xE081;"
Click="_acceptAccountModification__Click"
Style="{StaticResource ButtonStyle5}"/>
<Button x:Name="_cancelAccountModification_"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="&#xE106;"
Click="_cancelAccountModification__Click"
Style="{StaticResource ButtonStyle5}"/>
</StackPanel>
</Grid>
</Grid>
<!-- share menu. -->
<Grid x:Name="_shareMenuGrid_"
Grid.Row="2"
......
......@@ -131,7 +131,7 @@ SmartPanel::SmartPanel()
});
RingD::instance->exportOnRingEnded += ref new RingClientUWP::ExportOnRingEnded(this, &RingClientUWP::Views::SmartPanel::OnexportOnRingEnded);
RingD::instance->accountUpdated += ref new RingClientUWP::AccountUpdated(this, &RingClientUWP::Views::SmartPanel::OnaccountUpdated);
}
......@@ -143,7 +143,9 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
if (!accountListItem)
return;
auto name = accountListItem->_account->name_;
auto name = accountListItem->_account->name_; // refacto remove name variable and use the link directly on the next line... like _upnpnState..._
accountListItem->_isSelected = true;
Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex;
Configuration::UserPreferences::instance->save();
......@@ -160,6 +162,8 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
_shareMenuButton_->Visibility = (accountListItem->_account->accountType_ == "RING")
? Windows::UI::Xaml::Visibility::Visible
: Windows::UI::Xaml::Visibility::Collapsed;
_upnpState_->IsOn = accountListItem->_account->_upnpState;
}
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
......@@ -176,6 +180,7 @@ void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ se
{
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e)
......@@ -216,6 +221,7 @@ void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Objec
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_devicesMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_addingDeviceGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuButton_->IsChecked = false;
......@@ -228,6 +234,7 @@ void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Obj
{
_shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
......@@ -326,6 +333,7 @@ SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI
}
auto account = safe_cast<AccountListItem^>(listbox->SelectedItem);
AccountListItemsViewModel::instance->_selectedItem = account;
updatePageContent();
}
......@@ -706,3 +714,39 @@ Object ^ RingClientUWP::Views::AccountSelectedToVisibility::ConvertBack(Object ^
RingClientUWP::Views::AccountSelectedToVisibility::AccountSelectedToVisibility()
{}
void RingClientUWP::Views::SmartPanel::_editAccountMenuButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
_aliasTextBoxEditionMenu_->Text = account->name_;
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible;
}
void RingClientUWP::Views::SmartPanel::_acceptAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
auto accountId = account->accountID_;
account->name_ = _aliasTextBoxEditionMenu_->Text;
account->_upnpState = _upnpState_->IsOn;
RingD::instance->updateAccount(accountId);
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
_accountsMenuButton_->IsChecked = false;
}
void RingClientUWP::Views::SmartPanel::_cancelAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
_accountEditionMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
void RingClientUWP::Views::SmartPanel::OnaccountUpdated(RingClientUWP::Account ^account)
{
updatePageContent();
}
......@@ -119,6 +119,10 @@ private:
void OnexportOnRingEnded(Platform::String ^accountId, Platform::String ^pin);
void _closePin__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _shareMenuDone__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _editAccountMenuButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _acceptAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _cancelAccountModification__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void OnaccountUpdated(RingClientUWP::Account ^account);
};
}
}
\ No newline at end of file
......@@ -104,6 +104,19 @@
<Setter Property="Foreground"
Value="White"/>
</Style>
<Style x:Key="TextSegoeStyle-20pt-black"
TargetType="TextBlock">
<Setter Property="FontFamily"
Value="Segoe MDL2 Assets"/>
<Setter Property="FontSize"
Value="20"/>
<Setter Property="HorizontalAlignment"
Value="Left"/>
<Setter Property="VerticalAlignment"
Value="Center"/>
<Setter Property="Foreground"
Value="Black"/>
</Style>
<Style x:Key="ButtonStyle1"
TargetType="Button">
<Setter Property="Width"
......
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