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) ...@@ -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 void
Contact::saveConversationToFile() Contact::saveConversationToFile()
{ {
......
...@@ -95,6 +95,7 @@ internal: ...@@ -95,6 +95,7 @@ internal:
void saveConversationToFile(); void saveConversationToFile();
String^ StringifyConversation(); String^ StringifyConversation();
void DestringifyConversation(String^ data); void DestringifyConversation(String^ data);
void deleteConversationFile();
protected: protected:
void NotifyPropertyChanged(String^ propertyName); void NotifyPropertyChanged(String^ propertyName);
......
...@@ -173,6 +173,20 @@ ContactsViewModel::Destringify(String^ data) ...@@ -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) void RingClientUWP::ViewModel::ContactsViewModel::OnincomingMessage(Platform::String ^callId, Platform::String ^payload)
{ {
......
...@@ -27,6 +27,7 @@ namespace RingClientUWP ...@@ -27,6 +27,7 @@ namespace RingClientUWP
/* delegates */ /* delegates */
delegate void ContactAdded(Contact^); delegate void ContactAdded(Contact^);
delegate void ContactDeleted(Contact^);
namespace ViewModel { namespace ViewModel {
public ref class ContactsViewModel sealed public ref class ContactsViewModel sealed
...@@ -49,6 +50,7 @@ internal: ...@@ -49,6 +50,7 @@ internal:
void openContactsFromFile(); void openContactsFromFile();
String^ Stringify(); String^ Stringify();
void Destringify(String^ data); void Destringify(String^ data);
void deleteContact(Contact^ contact);
/* properties */ /* properties */
property Vector<Contact^>^ contactsList property Vector<Contact^>^ contactsList
...@@ -61,6 +63,7 @@ internal: ...@@ -61,6 +63,7 @@ internal:
/* events */ /* events */
event ContactAdded^ contactAdded; event ContactAdded^ contactAdded;
event ContactDeleted^ contactDeleted;
private: private:
ContactsViewModel(); // singleton ContactsViewModel(); // singleton
......
...@@ -70,6 +70,9 @@ MainPage::MainPage() ...@@ -70,6 +70,9 @@ MainPage::MainPage()
smartPanel->summonVideoPage += ref new RingClientUWP::SummonVideoPage(this, &RingClientUWP::MainPage::OnsummonVideoPage); smartPanel->summonVideoPage += ref new RingClientUWP::SummonVideoPage(this, &RingClientUWP::MainPage::OnsummonVideoPage);
auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content); auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
videoPage->pressHangUpCall += ref new RingClientUWP::PressHangUpCall(this, &RingClientUWP::MainPage::OnpressHangUpCall); 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(); DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^, dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
...@@ -398,3 +401,10 @@ MainPage::BeginExtendedExecution() ...@@ -398,3 +401,10 @@ MainPage::BeginExtendedExecution()
} }
}); });
} }
void RingClientUWP::MainPage::OncloseMessageTextPage()
{
auto smartPanel = dynamic_cast<SmartPanel^>(_smartPanel_->Content);
smartPanel->unselectContact();
}
...@@ -74,5 +74,6 @@ private: ...@@ -74,5 +74,6 @@ private:
void OnsummonVideoPage(); void OnsummonVideoPage();
void OnpressHangUpCall(); void OnpressHangUpCall();
void OnstateChange(Platform::String ^callId, CallStatus state, int code); void OnstateChange(Platform::String ^callId, CallStatus state, int code);
void OncloseMessageTextPage();
}; };
} }
...@@ -134,6 +134,7 @@ ...@@ -134,6 +134,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="20" FontSize="20"
Margin="20,0" /> Margin="20,0" />
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="_associableAccountsList_"> <ComboBox x:Name="_associableAccountsList_">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate x:DataType="local:Account"> <DataTemplate x:DataType="local:Account">
...@@ -143,6 +144,10 @@ ...@@ -143,6 +144,10 @@
</DataTemplate> </DataTemplate>
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
<Button x:Name="_deleteContact_"
Content="delete"
Click="_deleteContact__Click"/>
</StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
......
...@@ -178,4 +178,15 @@ void RingClientUWP::Views::MessageTextPage::OnSelectionChanged(Platform::Object ...@@ -178,4 +178,15 @@ void RingClientUWP::Views::MessageTextPage::OnSelectionChanged(Platform::Object
{ {
auto account = dynamic_cast<Account^>(_associableAccountsList_->SelectedItem); auto account = dynamic_cast<Account^>(_associableAccountsList_->SelectedItem);
SmartPanelItemsViewModel::instance->_selectedItem->_contact->_accountIdAssociated = account->accountID_; 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);
}
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
namespace RingClientUWP namespace RingClientUWP
{ {
delegate void CloseMessageTextPage();
namespace Views namespace Views
{ {
...@@ -45,6 +47,9 @@ public: ...@@ -45,6 +47,9 @@ public:
void updatePageContent(); void updatePageContent();
void scrollDown(); void scrollDown();
internal:
event CloseMessageTextPage^ closeMessageTextPage;
private: private:
void _sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void _messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
...@@ -52,6 +57,7 @@ private: ...@@ -52,6 +57,7 @@ private:
void OnincomingMessage(Platform::String ^callId, Platform::String ^payload); void OnincomingMessage(Platform::String ^callId, Platform::String ^payload);
void OnSelectionChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs ^e); 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() ...@@ -173,6 +173,11 @@ RingClientUWP::Views::SmartPanel::updatePageContent()
_upnpState_->IsOn = accountListItem->_account->_upnpState; _upnpState_->IsOn = accountListItem->_account->_upnpState;
} }
void RingClientUWP::Views::SmartPanel::unselectContact()
{
_smartList_->SelectedItem = nullptr;
}
void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e)
{ {
_shareMenuButton_->IsChecked = false; _shareMenuButton_->IsChecked = false;
......
...@@ -83,6 +83,7 @@ public ref class SmartPanel sealed ...@@ -83,6 +83,7 @@ public ref class SmartPanel sealed
public: public:
SmartPanel(); SmartPanel();
void updatePageContent(); void updatePageContent();
void unselectContact();
internal: internal:
enum class Mode { Minimized, Normal }; enum class Mode { Minimized, Normal };
......
...@@ -75,4 +75,12 @@ SmartPanelItemsViewModel::getIndex(Contact^ contact) ...@@ -75,4 +75,12 @@ SmartPanelItemsViewModel::getIndex(Contact^ contact)
break; break;
} }
return i; 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);
}
...@@ -46,6 +46,7 @@ internal: ...@@ -46,6 +46,7 @@ internal:
SmartPanelItem^ findItem(Contact^ contact); SmartPanelItem^ findItem(Contact^ contact);
unsigned int getIndex(String^ callId); unsigned int getIndex(String^ callId);
unsigned int getIndex(Contact^ contact); unsigned int getIndex(Contact^ contact);
void removeItem(SmartPanelItem^ item);
property Vector<SmartPanelItem^>^ itemsList 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