Commit 72b42926 authored by Nicolas Jager's avatar Nicolas Jager

internal : add logic and ui to manage account deletion

Change-Id: I95fd4583575c3fdb1e826f92f10a28d03c74683f
Tulesp: #1244
parent 6abfc0d2
......@@ -33,6 +33,7 @@ AccountListItem::AccountListItem(Account^ a)
{
_account = a;
_editionMode = false;
}
void
......
......@@ -22,6 +22,8 @@ using namespace Windows::Data::Json;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Data;
#include <RingDebug.h>
namespace RingClientUWP
{
namespace Controls {
......
......@@ -293,6 +293,19 @@ void RingClientUWP::RingD::updateAccount(String^ accountId)
tasksList_.push(task);
}
void RingClientUWP::RingD::deleteAccount(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::DeleteAccount);
task->_accountId = accountId;
tasksList_.push(task);
}
void
RingClientUWP::RingD::startDaemon()
{
......@@ -733,6 +746,14 @@ RingD::dequeueTasks()
DRing::setAccountDetails(Utils::toString(account->accountID_), accountDetails);
break;
}
case Request::DeleteAccount:
{
auto accountId = task->_accountId;
auto accountId2 = Utils::toString(accountId);
DRing::removeAccount(accountId2);
break;
}
default:
break;
}
......
......@@ -98,6 +98,7 @@ internal:
void askToExportOnRing(String^ accountId, String^ password);
void eraseCacheFolder();
void updateAccount(String^ accountId);
void deleteAccount(String^ accountId);
/* TODO : move members */
///bool hasConfig; // replaced by startingStatus
......@@ -130,7 +131,8 @@ private:
RegisterDevice,
GetKnownDevices,
ExportOnRing,
UpdateAccount
UpdateAccount,
DeleteAccount
};
......
......@@ -541,14 +541,14 @@
<ToggleSwitch x:Name="_upnpState_"
Margin="20,10"/>
<!-- delete account sub menu. -->
<!--<StackPanel Orientation="Horizontal" Margin="10">
<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"/>-->
Content="Delete"/>
</StackPanel>
<!-- buttons yes/no to accept the modification. -->
<Grid Grid.Row="1">
......
......@@ -63,7 +63,13 @@ SmartPanel::SmartPanel()
/* connect delegates */
Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) {
_accountsList_->SelectedIndex = index;
if (_accountsList_) {
auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size;
if (accountsListSize > index)
_accountsList_->SelectedIndex = index;
else
_accountsList_->SelectedIndex = 0;
}
});
Configuration::UserPreferences::instance->loadProfileImage += ref new LoadProfileImage([this]() {
StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
......@@ -728,11 +734,30 @@ void RingClientUWP::Views::SmartPanel::_acceptAccountModification__Click(Platfor
{
auto account = AccountListItemsViewModel::instance->_selectedItem->_account;
auto accountId = account->accountID_;
account->name_ = _aliasTextBoxEditionMenu_->Text;
account->_upnpState = _upnpState_->IsOn;
RingD::instance->updateAccount(accountId);
// mettre ca en visibility du bouton delete
auto accountsListSize = dynamic_cast<Vector<AccountListItem^>^>(_accountsList_->ItemsSource)->Size;
if (_deleteAccountBtnEditionMenu_->IsChecked && accountsListSize > 1) {
RingD::instance->deleteAccount(accountId);
/* rebuild a new list of accounts without the one to delete */
auto newAccountList = ref new Vector<AccountListItem^>();
for each (AccountListItem^ item in AccountListItemsViewModel::instance->itemsList) {
if (item->_account->accountID_ != accountId)
newAccountList->Append(item);
}
_accountsList_->ItemsSource = newAccountList;
} else {
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;
......
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