Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 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 |
|
| 25 | using namespace RingClientUWP::Views;
|
| 26 | using namespace RingClientUWP::ViewModel;
|
| 27 |
|
| 28 | using namespace Platform;
|
| 29 | using namespace Windows::Foundation;
|
| 30 | using namespace Windows::Foundation::Collections;
|
| 31 | using namespace Windows::UI::Xaml;
|
| 32 | using namespace Windows::UI::Xaml::Controls;
|
| 33 | using namespace Windows::UI::Xaml::Controls::Primitives;
|
| 34 | using namespace Windows::UI::Xaml::Data;
|
| 35 | using namespace Windows::UI::Xaml::Documents;
|
| 36 | using namespace Windows::UI::Xaml::Input;
|
| 37 | using namespace Windows::UI::Xaml::Media;
|
| 38 | using namespace Windows::UI::Xaml::Navigation;
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 39 | using namespace Windows::ApplicationModel::Core;
|
| 40 | using namespace Platform;
|
| 41 | using namespace Windows::UI::Core;
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 42 |
|
| 43 | MessageTextPage::MessageTextPage()
|
| 44 | {
|
| 45 | InitializeComponent();
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 46 |
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 47 | /* connect delegates. */
|
| 48 | // REFACTO : useless ?
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 49 | RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
|
| 50 | String^ from, String^ payload) {
|
| 51 | });
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 52 | 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 Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 58 |
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 59 | });
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 60 | }
|
| 61 |
|
| 62 | void
|
| 63 | RingClientUWP::Views::MessageTextPage::updatePageContent()
|
| 64 | {
|
| 65 | auto contact = ContactsViewModel::instance->selectedContact;
|
| 66 | if (!contact)
|
| 67 | return;
|
| 68 |
|
| 69 | _title_->Text = contact->name_;
|
| 70 |
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 71 | _messagesList_->ItemsSource = contact->_conversation->_messages;
|
| 72 |
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 73 | scrollDown();
|
| 74 | }
|
| 75 |
|
| 76 | void RingClientUWP::Views::MessageTextPage::scrollDown()
|
| 77 | {
|
| 78 | _scrollView_->UpdateLayout();
|
| 79 | _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 80 | }
|
| 81 |
|
| 82 | void
|
| 83 | RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 84 | {
|
| 85 | sendMessage();
|
| 86 | }
|
| 87 |
|
| 88 | void
|
| 89 | RingClientUWP::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 |
|
| 96 | void
|
| 97 | RingClientUWP::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 Jager | 655df54 | 2016-08-31 10:24:47 -0400 | [diff] [blame] | 108 | RingD::instance->sendAccountTextMessage(txt);
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 109 | scrollDown();
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 110 | }
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 111 |
|
| 112 | Object ^ 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
|
| 121 | Object ^ 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 |
|
| 126 | RingClientUWP::Views::BubbleBackground::BubbleBackground()
|
| 127 | {}
|
| 128 |
|
| 129 | Object ^ 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
|
| 135 | Object ^ 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 |
|
| 140 | RingClientUWP::Views::BubbleHorizontalAlignement::BubbleHorizontalAlignement()
|
| 141 | {}
|