text message : add visual new message notification
- adds a red buble with the number of unread messages.
Change-Id: I8c40df3e0421fba02444e5092a8975ce27ce989c
Tuleap: #961
diff --git a/Contact.cpp b/Contact.cpp
index 1fb7032..b49cbbd 100644
--- a/Contact.cpp
+++ b/Contact.cpp
@@ -26,6 +26,7 @@
using namespace Windows::UI::Core;
using namespace RingClientUWP;
+using namespace ViewModel;
Contact::Contact(String^ name,
String^ ringID)
@@ -33,6 +34,24 @@
name_ = name;
ringID_ = ringID;
conversation_ = ref new Conversation();
+ notificationNewMessage_ = Windows::UI::Xaml::Visibility::Collapsed;
+ unreadMessages_ = 0; // not saved on disk yet (TO DO)
+
+ /* connect to delegate */
+ ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () {
+ notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
+ unreadMessages_++;
+ PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
+ });
+ ContactsViewModel::instance->newContactSelected += ref new RingClientUWP::NewContactSelected([&]() {
+ if (ContactsViewModel::instance->selectedContact == this) {
+ PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
+ notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed;
+ unreadMessages_ = 0;
+ }
+ });
+
+
}
void
diff --git a/Contact.h b/Contact.h
index eb1ff21..7e84d87 100644
--- a/Contact.h
+++ b/Contact.h
@@ -19,6 +19,7 @@
**************************************************************************/
using namespace Platform;
using namespace Windows::Data::Json;
+using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Data;
/* strings required by Windows::Data::Json. Defined here on puprose */
@@ -36,7 +37,6 @@
Contact(String^ name, String^ ringID);
JsonObject^ ToJsonObject();
-
virtual event PropertyChangedEventHandler^ PropertyChanged;
property String^ name_;
@@ -48,12 +48,33 @@
return conversation_;
}
}
+ property Visibility notificationNewMessage
+ {
+ Visibility get()
+ {
+ return notificationNewMessage_;
+ }
+ void set(Visibility visibility)
+ {
+ notificationNewMessage_ = visibility;
+ PropertyChanged(this, ref new PropertyChangedEventArgs("notificationNewMessage"));
+ }
+ }
+ property String^ unreadMessages
+ {
+ String^ get()
+ {
+ return unreadMessages_.ToString();
+ }
+ }
protected:
void NotifyPropertyChanged(String^ propertyName);
private:
Conversation^ conversation_;
+ Visibility notificationNewMessage_;
+ unsigned int unreadMessages_;
};
}
diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp
index 80799ff..0aa9aed 100644
--- a/ContactsViewModel.cpp
+++ b/ContactsViewModel.cpp
@@ -43,11 +43,17 @@
if (contact == nullptr)
contact = addNewContact(from, from); // contact checked inside addNewContact.
+ bool isNotSelected = (contact != ContactsViewModel::instance->selectedContact) ? true : false;
+
if (contact == nullptr) {
ERR_("contact not handled!");
return;
}
+ screenConversationMessage("" /* accountId not used yet at this stage */, from, payload);
+
+ if (contact->ringID_ == from && isNotSelected)
+ notifyNewConversationMessage();
});
}
diff --git a/ContactsViewModel.h b/ContactsViewModel.h
index 29dfec8..b4de756 100644
--- a/ContactsViewModel.h
+++ b/ContactsViewModel.h
@@ -25,8 +25,11 @@
namespace RingClientUWP
{
+/* delegates */
delegate void NewContactSelected();
delegate void NoContactSelected();
+delegate void ScreenConversationMessage(String^ accountId, String^ from, String^ payload);
+delegate void NotifyNewConversationMessage();
namespace ViewModel {
public ref class ContactsViewModel sealed
@@ -79,6 +82,8 @@
/* events */
event NewContactSelected^ newContactSelected;
event NoContactSelected^ noContactSelected;
+ event ScreenConversationMessage^ screenConversationMessage;
+ event NotifyNewConversationMessage^ notifyNewConversationMessage;
private:
ContactsViewModel(); // singleton
diff --git a/SmartPanel.xaml b/SmartPanel.xaml
index 9e5fb61..cef2e26 100644
--- a/SmartPanel.xaml
+++ b/SmartPanel.xaml
@@ -58,9 +58,9 @@
</Border.RenderTransform>
</Border>
<Border x:Name="_visualNotificationNewMessage_"
- Visibility="Collapsed"
+ Visibility="{x:Bind notificationNewMessage, Mode=OneWay}"
Style="{StaticResource BorderStyle2}">
- <TextBlock Text="0"
+ <TextBlock Text="{x:Bind unreadMessages, Mode=OneWay}"
Style="{StaticResource TextStyle3}"/>
<Border.RenderTransform>
<TranslateTransform X="-17" Y="-14"/>
diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp
index d9e0dd5..4c340ef 100644
--- a/SmartPanel.xaml.cpp
+++ b/SmartPanel.xaml.cpp
@@ -44,6 +44,11 @@
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
_smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
+
+ /* connect delegate */
+ ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&]() {
+ //_visualNotificationNewMessage_->Vi
+ });
}
void