blob: 65e0a68ebf1975c2c0e8e3618db665f5d66b6387 [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"
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040019#include "ContactsViewModel.h"
Nicolas Jagerc551c362016-10-01 19:24:50 -040020
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040021#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 Jagerc551c362016-10-01 19:24:50 -040047 /* connect to delegates */
Nicolas Jager93abfea2016-08-30 12:33:07 -040048 RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
Nicolas Jagerc551c362016-10-01 19:24:50 -040049 String^ fromRingId, String^ payload) {
50 scrollDown();
Nicolas Jager7bef1492016-09-14 11:23:29 -040051 });
Nicolas Jager8f805cd2016-10-05 11:54:40 -040052 RingD::instance->incomingMessage += ref new RingClientUWP::IncomingMessage(this, &RingClientUWP::Views::MessageTextPage::OnincomingMessage);
53
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040054}
55
56void
57RingClientUWP::Views::MessageTextPage::updatePageContent()
58{
Nicolas Jagerc551c362016-10-01 19:24:50 -040059 auto item = SmartPanelItemsViewModel::instance->_selectedItem;
60 auto contact = item->_contact;
61
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040062 if (!contact)
63 return;
64
65 _title_->Text = contact->name_;
66
Nicolas Jager93abfea2016-08-30 12:33:07 -040067 _messagesList_->ItemsSource = contact->_conversation->_messages;
68
Nicolas Jager7bef1492016-09-14 11:23:29 -040069 scrollDown();
70}
71
72void RingClientUWP::Views::MessageTextPage::scrollDown()
73{
74 _scrollView_->UpdateLayout();
75 _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040076}
77
78void
79RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
80{
81 sendMessage();
82}
83
84void
85RingClientUWP::Views::MessageTextPage::_messageTextBox__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
86{
87 if (e->Key == Windows::System::VirtualKey::Enter) {
88 sendMessage();
89 }
90}
91
92void
93RingClientUWP::Views::MessageTextPage::sendMessage()
94{
Nicolas Jagerc551c362016-10-01 19:24:50 -040095 auto item = SmartPanelItemsViewModel::instance->_selectedItem;
96 auto contact = item->_contact;
97
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040098 auto txt = _messageTextBox_->Text;
99
100 /* empty the textbox */
101 _messageTextBox_->Text = "";
102
103 if (!contact || txt->IsEmpty())
104 return;
105
Nicolas Jager655df542016-08-31 10:24:47 -0400106 RingD::instance->sendAccountTextMessage(txt);
Nicolas Jager7bef1492016-09-14 11:23:29 -0400107 scrollDown();
Nicolas Jager8a85e1f2016-08-15 15:11:06 -0400108}
Nicolas Jager7bef1492016-09-14 11:23:29 -0400109
110Object ^ RingClientUWP::Views::BubbleBackground::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
111{
112 auto settings = ref new Windows::UI::ViewManagement::UISettings();
113 auto color = settings->GetColorValue(Windows::UI::ViewManagement::UIColorType::Accent);
114
115 return ((bool)value) ? ref new SolidColorBrush(color) : ref new SolidColorBrush(Windows::UI::Colors::LightBlue);
116}
117
118// we only do OneWay so the next function is not used
119Object ^ RingClientUWP::Views::BubbleBackground::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
120{
121 throw ref new Platform::NotImplementedException();
122}
123
124RingClientUWP::Views::BubbleBackground::BubbleBackground()
125{}
126
127Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::Convert(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
128{
129 return ((bool)value) ? Windows::UI::Xaml::HorizontalAlignment::Left : Windows::UI::Xaml::HorizontalAlignment::Right;
130}
131
132// we only do OneWay so the next function is not used
133Object ^ RingClientUWP::Views::BubbleHorizontalAlignement::ConvertBack(Object ^ value, Windows::UI::Xaml::Interop::TypeName targetType, Object ^ parameter, String ^ language)
134{
135 throw ref new Platform::NotImplementedException();
136}
137
138RingClientUWP::Views::BubbleHorizontalAlignement::BubbleHorizontalAlignement()
139{}
Nicolas Jager8f805cd2016-10-05 11:54:40 -0400140
141
142void RingClientUWP::Views::MessageTextPage::OnincomingMessage(Platform::String ^callId, Platform::String ^from, Platform::String ^payload)
143{
144 scrollDown();
145}