Commit 0788e96d authored by Nicolas Jager's avatar Nicolas Jager

text message : add visual new message notification

- adds a red buble with the number of unread messages.

Change-Id: I8c40df3e0421fba02444e5092a8975ce27ce989c
Tuleap: #961
parent 6e30ad83
...@@ -26,6 +26,7 @@ using namespace Windows::Data::Json; ...@@ -26,6 +26,7 @@ using namespace Windows::Data::Json;
using namespace Windows::UI::Core; using namespace Windows::UI::Core;
using namespace RingClientUWP; using namespace RingClientUWP;
using namespace ViewModel;
Contact::Contact(String^ name, Contact::Contact(String^ name,
String^ ringID) String^ ringID)
...@@ -33,6 +34,24 @@ Contact::Contact(String^ name, ...@@ -33,6 +34,24 @@ Contact::Contact(String^ name,
name_ = name; name_ = name;
ringID_ = ringID; ringID_ = ringID;
conversation_ = ref new Conversation(); 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 void
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
**************************************************************************/ **************************************************************************/
using namespace Platform; using namespace Platform;
using namespace Windows::Data::Json; using namespace Windows::Data::Json;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Data;
/* strings required by Windows::Data::Json. Defined here on puprose */ /* strings required by Windows::Data::Json. Defined here on puprose */
...@@ -36,7 +37,6 @@ public: ...@@ -36,7 +37,6 @@ public:
Contact(String^ name, String^ ringID); Contact(String^ name, String^ ringID);
JsonObject^ ToJsonObject(); JsonObject^ ToJsonObject();
virtual event PropertyChangedEventHandler^ PropertyChanged; virtual event PropertyChangedEventHandler^ PropertyChanged;
property String^ name_; property String^ name_;
...@@ -48,12 +48,33 @@ public: ...@@ -48,12 +48,33 @@ public:
return conversation_; 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: protected:
void NotifyPropertyChanged(String^ propertyName); void NotifyPropertyChanged(String^ propertyName);
private: private:
Conversation^ conversation_; Conversation^ conversation_;
Visibility notificationNewMessage_;
unsigned int unreadMessages_;
}; };
} }
......
...@@ -43,11 +43,17 @@ ContactsViewModel::ContactsViewModel() ...@@ -43,11 +43,17 @@ ContactsViewModel::ContactsViewModel()
if (contact == nullptr) if (contact == nullptr)
contact = addNewContact(from, from); // contact checked inside addNewContact. contact = addNewContact(from, from); // contact checked inside addNewContact.
bool isNotSelected = (contact != ContactsViewModel::instance->selectedContact) ? true : false;
if (contact == nullptr) { if (contact == nullptr) {
ERR_("contact not handled!"); ERR_("contact not handled!");
return; return;
} }
screenConversationMessage("" /* accountId not used yet at this stage */, from, payload);
if (contact->ringID_ == from && isNotSelected)
notifyNewConversationMessage();
}); });
} }
......
...@@ -25,8 +25,11 @@ using namespace Concurrency; ...@@ -25,8 +25,11 @@ using namespace Concurrency;
namespace RingClientUWP namespace RingClientUWP
{ {
/* delegates */
delegate void NewContactSelected(); delegate void NewContactSelected();
delegate void NoContactSelected(); delegate void NoContactSelected();
delegate void ScreenConversationMessage(String^ accountId, String^ from, String^ payload);
delegate void NotifyNewConversationMessage();
namespace ViewModel { namespace ViewModel {
public ref class ContactsViewModel sealed public ref class ContactsViewModel sealed
...@@ -79,6 +82,8 @@ internal: ...@@ -79,6 +82,8 @@ internal:
/* events */ /* events */
event NewContactSelected^ newContactSelected; event NewContactSelected^ newContactSelected;
event NoContactSelected^ noContactSelected; event NoContactSelected^ noContactSelected;
event ScreenConversationMessage^ screenConversationMessage;
event NotifyNewConversationMessage^ notifyNewConversationMessage;
private: private:
ContactsViewModel(); // singleton ContactsViewModel(); // singleton
......
...@@ -58,9 +58,9 @@ ...@@ -58,9 +58,9 @@
</Border.RenderTransform> </Border.RenderTransform>
</Border> </Border>
<Border x:Name="_visualNotificationNewMessage_" <Border x:Name="_visualNotificationNewMessage_"
Visibility="Collapsed" Visibility="{x:Bind notificationNewMessage, Mode=OneWay}"
Style="{StaticResource BorderStyle2}"> Style="{StaticResource BorderStyle2}">
<TextBlock Text="0" <TextBlock Text="{x:Bind unreadMessages, Mode=OneWay}"
Style="{StaticResource TextStyle3}"/> Style="{StaticResource TextStyle3}"/>
<Border.RenderTransform> <Border.RenderTransform>
<TranslateTransform X="-17" Y="-14"/> <TranslateTransform X="-17" Y="-14"/>
......
...@@ -44,6 +44,11 @@ SmartPanel::SmartPanel() ...@@ -44,6 +44,11 @@ SmartPanel::SmartPanel()
_accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList;
_smartList_->ItemsSource = ContactsViewModel::instance->contactsList; _smartList_->ItemsSource = ContactsViewModel::instance->contactsList;
/* connect delegate */
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&]() {
//_visualNotificationNewMessage_->Vi
});
} }
void void
......
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