blob: aca763d0ccf4277c349ecd1477a58766b7b14079 [file] [log] [blame]
Nicolas Jager8a85e1f2016-08-15 15:11:06 -04001/**************************************************************************
2* Copyright (C) 2016 by Savoir-faire Linux *
3* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4* *
5* This program is free software; you can redistribute it and/or modify *
6* it under the terms of the GNU General Public License as published by *
7* the Free Software Foundation; either version 3 of the License, or *
8* (at your option) any later version. *
9* *
10* This program is distributed in the hope that it will be useful, *
11* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13* GNU General Public License for more details. *
14* *
15* You should have received a copy of the GNU General Public License *
16* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17**************************************************************************/
18#include "pch.h"
19
20#include "ContactsViewModel.h"
21#include "MainPage.xaml.h"
22
23#include "MessageTextPage.xaml.h"
24
25using namespace RingClientUWP::Views;
26using namespace RingClientUWP::ViewModel;
27
28using namespace Platform;
29using namespace Windows::Foundation;
30using namespace Windows::Foundation::Collections;
31using namespace Windows::UI::Xaml;
32using namespace Windows::UI::Xaml::Controls;
33using namespace Windows::UI::Xaml::Controls::Primitives;
34using namespace Windows::UI::Xaml::Data;
35using namespace Windows::UI::Xaml::Documents;
36using namespace Windows::UI::Xaml::Input;
37using namespace Windows::UI::Xaml::Media;
38using namespace Windows::UI::Xaml::Navigation;
Nicolas Jager7bef1492016-09-14 11:23:29 -040039using namespace Windows::ApplicationModel::Core;
40using namespace Platform;
41using namespace Windows::UI::Core;
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040042
43MessageTextPage::MessageTextPage()
44{
45 InitializeComponent();
Nicolas Jager93abfea2016-08-30 12:33:07 -040046
Nicolas Jager7bef1492016-09-14 11:23:29 -040047 /* connect delegates. */
48 // REFACTO : useless ?
Nicolas Jager93abfea2016-08-30 12:33:07 -040049 RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
50 String^ from, String^ payload) {
51 });
Nicolas Jager7bef1492016-09-14 11:23:29 -040052 ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&](
53 bool isContactNotSelected) {
54 if (!isContactNotSelected) {
55 /* if the contact is selected that means we should scroll down */
56 scrollDown();
57 }
Nicolas Jager93abfea2016-08-30 12:33:07 -040058
Nicolas Jager7bef1492016-09-14 11:23:29 -040059 });
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040060}
61
62void
63RingClientUWP::Views::MessageTextPage::updatePageContent()
64{
65 auto contact = ContactsViewModel::instance->selectedContact;
66 if (!contact)
67 return;
68
69 _title_->Text = contact->name_;
70
Nicolas Jager93abfea2016-08-30 12:33:07 -040071 _messagesList_->ItemsSource = contact->_conversation->_messages;
72
Nicolas Jager7bef1492016-09-14 11:23:29 -040073 scrollDown();
74}
75
76void RingClientUWP::Views::MessageTextPage::scrollDown()
77{
78 _scrollView_->UpdateLayout();
79 _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040080}
81
82void
83RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
84{
85 sendMessage();
86}
87
88void
89RingClientUWP::Views::MessageTextPage::_messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
90{
91 if (e->Key == Windows::System::VirtualKey::Enter) {
92 sendMessage();
93 }
94}
95
96void
97RingClientUWP::Views::MessageTextPage::sendMessage()
98{
99 auto contact = ContactsViewModel::instance->selectedContact;
100 auto txt = _messageTextBox_->Text;
101
102 /* empty the textbox */
103 _messageTextBox_->Text = "";
104
105 if (!contact || txt->IsEmpty())
106 return;
107
Nicolas Jager655df542016-08-31 10:24:47 -0400108 RingD::instance->sendAccountTextMessage(txt);
Nicolas Jager7bef1492016-09-14 11:23:29 -0400109 scrollDown();
Nicolas Jager8a85e1f2016-08-15 15:11:06 -0400110}
Nicolas Jager7bef1492016-09-14 11:23:29 -0400111
112Object ^ RingClientUWP::Views::BubbleBackground::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
113{
114 auto settings = ref new Windows::UI::ViewManagement::UISettings();
115 auto color = settings->GetColorValue(Windows::UI::ViewManagement::UIColorType::Accent);
116
117 return ((bool)value) ? ref new SolidColorBrush(color) : ref new SolidColorBrush(Windows::UI::Colors::LightBlue);
118}
119
120// we only do OneWay so the next function is not used
121Object ^ RingClientUWP::Views::BubbleBackground::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
122{
123 throw ref new Platform::NotImplementedException();
124}
125
126RingClientUWP::Views::BubbleBackground::BubbleBackground()
127{}
128
129Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
130{
131 return ((bool)value) ? Windows::UI::Xaml::HorizontalAlignment::Left : Windows::UI::Xaml::HorizontalAlignment::Right;
132}
133
134// we only do OneWay so the next function is not used
135Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
136{
137 throw ref new Platform::NotImplementedException();
138}
139
140RingClientUWP::Views::BubbleHorizontalAlignement::BubbleHorizontalAlignement()
141{}