diff --git a/Contact.cpp b/Contact.cpp index 50c142cf6e3254b1dd25fa7002303138f6822878..a151cc6d22fab23d5af462c28d3f2879609bc860 100644 --- a/Contact.cpp +++ b/Contact.cpp @@ -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() { diff --git a/Contact.h b/Contact.h index aa2671d62486a91ce89d05f795a1c8b47575dca3..8bf41646d3daa519de9449a53aa714a7c1445340 100644 --- a/Contact.h +++ b/Contact.h @@ -95,6 +95,7 @@ internal: void saveConversationToFile(); String^ StringifyConversation(); void DestringifyConversation(String^ data); + void deleteConversationFile(); protected: void NotifyPropertyChanged(String^ propertyName); diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index f19f44fc4524986bae42c3806ee808bc1c202fdc..9721c7d904d07f196694eef57d77e7df12255cef 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -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) { diff --git a/ContactsViewModel.h b/ContactsViewModel.h index b6ee05fa8602026ebe4652e8e359f4fc57e3d02f..bd78b1ef2d8035ac830da01ff06286df4f9f60eb 100644 --- a/ContactsViewModel.h +++ b/ContactsViewModel.h @@ -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 diff --git a/MainPage.xaml.cpp b/MainPage.xaml.cpp index 70f8418d55b2353fb54a9f68cbc00885d4774166..02057e24017f15494007143a3c8d63b5c8c0c1d6 100644 --- a/MainPage.xaml.cpp +++ b/MainPage.xaml.cpp @@ -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(); +} diff --git a/MainPage.xaml.h b/MainPage.xaml.h index a8b1934f524ab3fdd9c432f58226983540a15182..821efbfe72ebaae238d0c47104a36fb6d0ed4256 100644 --- a/MainPage.xaml.h +++ b/MainPage.xaml.h @@ -74,5 +74,6 @@ private: void OnsummonVideoPage(); void OnpressHangUpCall(); void OnstateChange(Platform::String ^callId, CallStatus state, int code); + void OncloseMessageTextPage(); }; } diff --git a/MessageTextPage.xaml b/MessageTextPage.xaml index 3435963cd41ff20d5199596d2594474b57c15b6c..92767ea1949b64d167f159b43b705dfc8444b39c 100644 --- a/MessageTextPage.xaml +++ b/MessageTextPage.xaml @@ -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> diff --git a/MessageTextPage.xaml.cpp b/MessageTextPage.xaml.cpp index e018cbdbead68f773d5a00e54c021aec20ab32b5..5adb8d1d30cce2bed60e91b094a73bf847d7ddfe 100644 --- a/MessageTextPage.xaml.cpp +++ b/MessageTextPage.xaml.cpp @@ -178,4 +178,15 @@ void RingClientUWP::Views::MessageTextPage::OnSelectionChanged(Platform::Object { auto account = dynamic_cast<Account^>(_associableAccountsList_->SelectedItem); SmartPanelItemsViewModel::instance->_selectedItem->_contact->_accountIdAssociated = account->accountID_; -} \ No newline at end of file +} + +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); +} diff --git a/MessageTextPage.xaml.h b/MessageTextPage.xaml.h index 8b902776009cda45dfe6c700c9ea6d82423aeb55..ffc701fa8c4465a89d03c9c1fae19acc78085397 100644 --- a/MessageTextPage.xaml.h +++ b/MessageTextPage.xaml.h @@ -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); }; } } diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 8ffbbcb790c27d54e46746be7cb38ccc6745cbcf..6b5bc150f574a0d05454ebb6f651a4eadb6d5e3c 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -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; diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 8cf5f7ef6d029f56aea242426c693d96fce78c63..cc53de793e4ee68931d418e9acb28ba794842317 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -83,6 +83,7 @@ public ref class SmartPanel sealed public: SmartPanel(); void updatePageContent(); + void unselectContact(); internal: enum class Mode { Minimized, Normal }; diff --git a/SmartPanelItemsViewModel.cpp b/SmartPanelItemsViewModel.cpp index e567398019c487784b1775ba92f1e7b755167b99..8147ff0d21f9402a7c3d9e62d3856d47597861ab 100644 --- a/SmartPanelItemsViewModel.cpp +++ b/SmartPanelItemsViewModel.cpp @@ -75,4 +75,12 @@ SmartPanelItemsViewModel::getIndex(Contact^ contact) break; } return i; -} \ No newline at end of file +} + +void RingClientUWP::ViewModel::SmartPanelItemsViewModel::removeItem(SmartPanelItem ^ item) +{ + unsigned int index; + + if (itemsList->IndexOf(item, &index)) + itemsList->RemoveAt(index); +} diff --git a/SmartPanelItemsViewModel.h b/SmartPanelItemsViewModel.h index f77d3a0b3d692ff71547bafaffddfeaa6853f43b..184120b73e3b849df6a129ce7ae16390f772f534 100644 --- a/SmartPanelItemsViewModel.h +++ b/SmartPanelItemsViewModel.h @@ -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 {