Commit e72856b7 authored by Nicolas Jager's avatar Nicolas Jager

contact : add capability to delete contact and conversation file

Change-Id: Ia2781ffcbbf1929b5535cb7fd16e2f36eff5eb33
Tuleap: #1285
parent 1ba34442
......@@ -136,6 +136,19 @@ Contact::DestringifyConversation(String^ data)
}
}
void RingClientUWP::Contact::deleteConversationFile()
{
StorageFolder^ localfolder = ApplicationData::Current->LocalFolder;
String^ messagesFile = ".messages\\" + GUID_ + ".json";
// refacto : Utils::fileExists fails here if the file doesn't exist, code below should replace fileExist everywhere
create_task(localfolder->TryGetItemAsync(messagesFile)).then([](IStorageItem^ storageFile) {
if (storageFile)
storageFile->DeleteAsync();
});
}
void
Contact::saveConversationToFile()
{
......
......@@ -95,6 +95,7 @@ internal:
void saveConversationToFile();
String^ StringifyConversation();
void DestringifyConversation(String^ data);
void deleteConversationFile();
protected:
void NotifyPropertyChanged(String^ propertyName);
......
......@@ -173,6 +173,20 @@ ContactsViewModel::Destringify(String^ data)
}
}
void RingClientUWP::ViewModel::ContactsViewModel::deleteContact(Contact ^ contact)
{
unsigned int index;
auto itemsList = SmartPanelItemsViewModel::instance->itemsList;
auto item = SmartPanelItemsViewModel::instance->_selectedItem;
if (contactsList_->IndexOf(contact, &index)) {
contact->deleteConversationFile();
contactsList_->RemoveAt(index);
}
saveContactsToFile();
}
void RingClientUWP::ViewModel::ContactsViewModel::OnincomingMessage(Platform::String ^callId, Platform::String ^payload)
{
......
......@@ -27,6 +27,7 @@ namespace RingClientUWP
/* delegates */
delegate void ContactAdded(Contact^);
delegate void ContactDeleted(Contact^);
namespace ViewModel {
public ref class ContactsViewModel sealed
......@@ -49,6 +50,7 @@ internal:
void openContactsFromFile();
String^ Stringify();
void Destringify(String^ data);
void deleteContact(Contact^ contact);
/* properties */
property Vector<Contact^>^ contactsList
......@@ -61,6 +63,7 @@ internal:
/* events */
event ContactAdded^ contactAdded;
event ContactDeleted^ contactDeleted;
private:
ContactsViewModel(); // singleton
......
......@@ -70,6 +70,9 @@ MainPage::MainPage()
smartPanel->summonVideoPage += ref new RingClientUWP::SummonVideoPage(this, &RingClientUWP::MainPage::OnsummonVideoPage);
auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
videoPage->pressHangUpCall += ref new RingClientUWP::PressHangUpCall(this, &RingClientUWP::MainPage::OnpressHangUpCall);
auto messageTextFrame = dynamic_cast<MessageTextPage^>(_messageTextFrame_->Content);
messageTextFrame->closeMessageTextPage += ref new RingClientUWP::CloseMessageTextPage(this, &RingClientUWP::MainPage::OncloseMessageTextPage);
DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
......@@ -398,3 +401,10 @@ MainPage::BeginExtendedExecution()
}
});
}
void RingClientUWP::MainPage::OncloseMessageTextPage()
{
auto smartPanel = dynamic_cast<SmartPanel^>(_smartPanel_->Content);
smartPanel->unselectContact();
}
......@@ -74,5 +74,6 @@ private:
void OnsummonVideoPage();
void OnpressHangUpCall();
void OnstateChange(Platform::String ^callId, CallStatus state, int code);
void OncloseMessageTextPage();
};
}
......@@ -134,6 +134,7 @@
VerticalAlignment="Center"
FontSize="20"
Margin="20,0" />
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="_associableAccountsList_">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:Account">
......@@ -143,6 +144,10 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button x:Name="_deleteContact_"
Content="delete"
Click="_deleteContact__Click"/>
</StackPanel>
</StackPanel>
</StackPanel>
......
......@@ -179,3 +179,14 @@ void RingClientUWP::Views::MessageTextPage::OnSelectionChanged(Platform::Object
auto account = dynamic_cast<Account^>(_associableAccountsList_->SelectedItem);
SmartPanelItemsViewModel::instance->_selectedItem->_contact->_accountIdAssociated = account->accountID_;
}
void RingClientUWP::Views::MessageTextPage::_deleteContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto item = SmartPanelItemsViewModel::instance->_selectedItem;
auto contact = item->_contact;
closeMessageTextPage();
ContactsViewModel::instance->deleteContact(contact);
SmartPanelItemsViewModel::instance->removeItem(item);
}
......@@ -21,6 +21,8 @@
namespace RingClientUWP
{
delegate void CloseMessageTextPage();
namespace Views
{
......@@ -45,6 +47,9 @@ public:
void updatePageContent();
void scrollDown();
internal:
event CloseMessageTextPage^ closeMessageTextPage;
private:
void _sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
......@@ -52,6 +57,7 @@ private:
void OnincomingMessage(Platform::String ^callId, Platform::String ^payload);
void OnSelectionChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^e);
void _deleteContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}
}
......@@ -173,6 +173,11 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
_upnpState_->IsOn = accountListItem->_account->_upnpState;
}
void RingClientUWP::Views::SmartPanel::unselectContact()
{
_smartList_->SelectedItem = nullptr;
}
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{
_shareMenuButton_->IsChecked = false;
......
......@@ -83,6 +83,7 @@ public ref class SmartPanel sealed
public:
SmartPanel();
void updatePageContent();
void unselectContact();
internal:
enum class Mode { Minimized, Normal };
......
......@@ -76,3 +76,11 @@ SmartPanelItemsViewModel::getIndex(Contact^ contact)
}
return i;
}
void RingClientUWP::ViewModel::SmartPanelItemsViewModel::removeItem(SmartPanelItem ^ item)
{
unsigned int index;
if (itemsList->IndexOf(item, &index))
itemsList->RemoveAt(index);
}
......@@ -46,6 +46,7 @@ internal:
SmartPanelItem^ findItem(Contact^ contact);
unsigned int getIndex(String^ callId);
unsigned int getIndex(Contact^ contact);
void removeItem(SmartPanelItem^ item);
property Vector<SmartPanelItem^>^ itemsList
{
......
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