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"
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 19 | #include "ContactsViewModel.h"
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 20 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 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 | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 47 | /* connect to delegates */
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 48 | RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 49 | String^ fromRingId, String^ payload) {
|
| 50 | scrollDown();
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 51 | });
|
Nicolas Jager | 8f805cd | 2016-10-05 11:54:40 -0400 | [diff] [blame^] | 52 | RingD::instance->incomingMessage += ref new RingClientUWP::IncomingMessage(this, &RingClientUWP::Views::MessageTextPage::OnincomingMessage);
|
| 53 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 54 | }
|
| 55 |
|
| 56 | void
|
| 57 | RingClientUWP::Views::MessageTextPage::updatePageContent()
|
| 58 | {
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 59 | auto item = SmartPanelItemsViewModel::instance->_selectedItem;
|
| 60 | auto contact = item->_contact;
|
| 61 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 62 | if (!contact)
|
| 63 | return;
|
| 64 |
|
| 65 | _title_->Text = contact->name_;
|
| 66 |
|
Nicolas Jager | 93abfea | 2016-08-30 12:33:07 -0400 | [diff] [blame] | 67 | _messagesList_->ItemsSource = contact->_conversation->_messages;
|
| 68 |
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 69 | scrollDown();
|
| 70 | }
|
| 71 |
|
| 72 | void RingClientUWP::Views::MessageTextPage::scrollDown()
|
| 73 | {
|
| 74 | _scrollView_->UpdateLayout();
|
| 75 | _scrollView_->ScrollToVerticalOffset(_scrollView_->ScrollableHeight);
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 76 | }
|
| 77 |
|
| 78 | void
|
| 79 | RingClientUWP::Views::MessageTextPage::_sendBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 80 | {
|
| 81 | sendMessage();
|
| 82 | }
|
| 83 |
|
| 84 | void
|
| 85 | RingClientUWP::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 |
|
| 92 | void
|
| 93 | RingClientUWP::Views::MessageTextPage::sendMessage()
|
| 94 | {
|
Nicolas Jager | c551c36 | 2016-10-01 19:24:50 -0400 | [diff] [blame] | 95 | auto item = SmartPanelItemsViewModel::instance->_selectedItem;
|
| 96 | auto contact = item->_contact;
|
| 97 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 98 | auto txt = _messageTextBox_->Text;
|
| 99 |
|
| 100 | /* empty the textbox */
|
| 101 | _messageTextBox_->Text = "";
|
| 102 |
|
| 103 | if (!contact || txt->IsEmpty())
|
| 104 | return;
|
| 105 |
|
Nicolas Jager | 655df54 | 2016-08-31 10:24:47 -0400 | [diff] [blame] | 106 | RingD::instance->sendAccountTextMessage(txt);
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 107 | scrollDown();
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 108 | }
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 109 |
|
| 110 | Object ^ 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
|
| 119 | Object ^ 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 |
|
| 124 | RingClientUWP::Views::BubbleBackground::BubbleBackground()
|
| 125 | {}
|
| 126 |
|
| 127 | Object ^ 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
|
| 133 | Object ^ 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 |
|
| 138 | RingClientUWP::Views::BubbleHorizontalAlignement::BubbleHorizontalAlignement()
|
| 139 | {}
|
Nicolas Jager | 8f805cd | 2016-10-05 11:54:40 -0400 | [diff] [blame^] | 140 |
|
| 141 |
|
| 142 | void RingClientUWP::Views::MessageTextPage::OnincomingMessage(Platform::String ^callId, Platform::String ^from, Platform::String ^payload)
|
| 143 | {
|
| 144 | scrollDown();
|
| 145 | }
|