Commit 7bef149e authored by Nicolas Jager's avatar Nicolas Jager

text message : visual enhancement

- creates bubble : blue for you, pink for your contact.
- scrolls down to the last message.

Tuleap: #1040
Change-Id: I9e3867202a2a4f7f666043aeaee59ddf221365a0
parent 121bdf32
......@@ -77,8 +77,10 @@ Contact::Contact(String^ name,
}
/* connect to delegate */
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () {
PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] (
bool isContactNotSelected) {
if (isContactNotSelected)
PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
});
ContactsViewModel::instance->newContactSelected += ref new RingClientUWP::NewContactSelected([&]() {
if (ContactsViewModel::instance->selectedContact == this) {
......
......@@ -55,11 +55,12 @@ ContactsViewModel::ContactsViewModel()
/* save contacts conversation to disk */
contact->saveConversationToFile();
if (contact->ringID_ == from && isNotSelected) {
if (contact->ringID_ == from) {
// increment contact's unread message count
contact->addNotifyNewConversationMessage();
if(isNotSelected)
contact->addNotifyNewConversationMessage();
// update the xaml for all contacts
notifyNewConversationMessage();
notifyNewConversationMessage(isNotSelected);
// save to disk
saveContactsToFile();
}
......
......@@ -29,7 +29,7 @@ namespace RingClientUWP
delegate void NewContactSelected();
delegate void NoContactSelected();
delegate void ScreenConversationMessage(String^ accountId, String^ from, String^ payload);
delegate void NotifyNewConversationMessage();
delegate void NotifyNewConversationMessage(bool isContactNotSelected);
delegate void ShowContactBar();
delegate void ContactAdded(Contact^);
......
......@@ -69,7 +69,7 @@ MainPage::MainPage()
DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
}
void
......
......@@ -3,18 +3,41 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RingClientUWP"
xmlns:views="using:RingClientUWP.Views"
xmlns:ctl="using:RingClientUWP.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<DataTemplate x:Key="ConversationMessageTemplate" x:DataType="local:ConversationMessage">
<Grid>
<TextBlock x:Name="_msgContent_" Text="{x:Bind Payload}"/>
<!-- bubble -->
<views:BubbleBackground x:Key="_bubbleBackground_" />
<views:BubbleHorizontalAlignement x:Key="_bubbleHorizontalAlignement_" />
<DataTemplate x:Key="ConversationMessageTemplate"
x:DataType="local:ConversationMessage">
<Grid Margin="0"
HorizontalAlignment="{x:Bind FromContact, Converter={StaticResource _bubbleHorizontalAlignement_}}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<Border Background="{x:Bind FromContact, Converter={StaticResource _bubbleBackground_}}"
CornerRadius="10"
Grid.Column="1"
Width="auto"
Height="auto"
Padding="5"
Margin="5" >
<ContentPresenter>
<!--Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."-->
<TextBlock x:Name="_msgContent_"
TextWrapping="Wrap"
Text="{x:Bind Payload}"
Foreground="White"/>
</ContentPresenter>
</Border>
</Grid>
</DataTemplate>
<!-- barre d'envoi de message -->
<Style TargetType="TextBox">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
......@@ -85,7 +108,7 @@
</Style>
</Page.Resources>
<Grid Background="White">
<Grid Background="#FFF2F2F2">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*"/>
......@@ -107,15 +130,17 @@
</StackPanel>
</StackPanel>
<ScrollViewer BorderThickness="0,1,0,1"
<ScrollViewer x:Name="_scrollView_"
BorderThickness="0,1,0,1"
BorderBrush="LightBlue"
Grid.Row="1">
<StackPanel x:Name="_messagesWindowOutput_"
Background="#FFF2F2F2">
<ListBox x:Name="_messagesList_"
Margin="0"
Padding="0"
ItemTemplate="{StaticResource ConversationMessageTemplate}"/>
<StackPanel>
<ListBox x:Name="_messagesList_"
Margin="0"
Padding="0"
ItemContainerStyle="{StaticResource messageBubleStyle}"
ItemTemplate="{StaticResource ConversationMessageTemplate}">
</ListBox>
</StackPanel>
</ScrollViewer>
<Grid Height="50"
......
......@@ -36,22 +36,27 @@ using namespace Windows::UI::Xaml::Documents;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::ApplicationModel::Core;
using namespace Platform;
using namespace Windows::UI::Core;
MessageTextPage::MessageTextPage()
{
InitializeComponent();
/* connect delegates. */ // may be useless
/* connect delegates. */
// REFACTO : useless ?
RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
String^ from, String^ payload) {
});
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&](
bool isContactNotSelected) {
if (!isContactNotSelected) {
/* if the contact is selected that means we should scroll down */
scrollDown();
}
}
void
RingClientUWP::Views::MessageTextPage::OnNavigatedTo(NavigationEventArgs ^ e)
{
updatePageContent();
});
}
void
......@@ -65,6 +70,13 @@ RingClientUWP::Views::MessageTextPage::updatePageContent()
_messagesList_->ItemsSource = contact->_conversation->_messages;
scrollDown();
}
void RingClientUWP::Views::MessageTextPage::scrollDown()
{
_scrollView_->UpdateLayout();
_scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
}
void
......@@ -94,5 +106,36 @@ RingClientUWP::Views::MessageTextPage::sendMessage()
return;
RingD::instance->sendAccountTextMessage(txt);
scrollDown();
}
Object ^ RingClientUWP::Views::BubbleBackground::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
auto settings = ref new Windows::UI::ViewManagement::UISettings();
auto color = settings->GetColorValue(Windows::UI::ViewManagement::UIColorType::Accent);
return ((bool)value) ? ref new SolidColorBrush(color) : ref new SolidColorBrush(Windows::UI::Colors::LightBlue);
}
// we only do OneWay so the next function is not used
Object ^ RingClientUWP::Views::BubbleBackground::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
throw ref new Platform::NotImplementedException();
}
RingClientUWP::Views::BubbleBackground::BubbleBackground()
{}
Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
return ((bool)value) ? Windows::UI::Xaml::HorizontalAlignment::Left : Windows::UI::Xaml::HorizontalAlignment::Right;
}
// we only do OneWay so the next function is not used
Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
{
throw ref new Platform::NotImplementedException();
}
RingClientUWP::Views::BubbleHorizontalAlignement::BubbleHorizontalAlignement()
{}
......@@ -23,14 +23,27 @@ namespace RingClientUWP
{
namespace Views
{
public ref class BubbleBackground sealed : IValueConverter {
public:
virtual Object^ Convert(Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object^ parameter, String^ language);
virtual Object^ ConvertBack(Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object^ parameter, String^ language);
BubbleBackground();
};
public ref class BubbleHorizontalAlignement sealed : IValueConverter {
public:
virtual Object^ Convert(Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object^ parameter, String^ language);
virtual Object^ ConvertBack(Object^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object^ parameter, String^ language);
BubbleHorizontalAlignement();
};
public ref class MessageTextPage sealed
{
public:
MessageTextPage();
void updatePageContent();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
void scrollDown();
private:
void _sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
......
......@@ -338,6 +338,27 @@
<Setter Property="Height" Value="23"/>
<Setter Property="Padding" Value="4"/>
</Style>
<Style x:Key="messageBubleStyle"
TargetType="ListBoxItem">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="20,0,40,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Selected" />
<VisualState x:Name="Unselected">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
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