Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -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 |
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 20 | #include "ContactsViewModel.h"
|
| 21 | #include "MessageTextPage.xaml.h"
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 22 | #include "SmartPanel.xaml.h"
|
| 23 | #include "RingConsolePanel.xaml.h"
|
Nicolas Jager | e069c41 | 2016-08-15 15:00:17 -0400 | [diff] [blame] | 24 | #include "VideoPage.xaml.h"
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 25 | #include "WelcomePage.xaml.h"
|
| 26 |
|
| 27 | #include "MainPage.xaml.h"
|
| 28 |
|
| 29 | using namespace RingClientUWP;
|
| 30 | using namespace RingClientUWP::Views;
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 31 | using namespace RingClientUWP::ViewModel;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 32 |
|
| 33 | using namespace Platform;
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 34 | using namespace Windows::ApplicationModel::Core;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 35 | using namespace Windows::Foundation;
|
| 36 | using namespace Windows::Foundation::Collections;
|
| 37 | using namespace Windows::UI::ViewManagement;
|
| 38 | using namespace Windows::UI::Xaml;
|
| 39 | using namespace Windows::UI::Xaml::Controls;
|
| 40 | using namespace Windows::UI::Xaml::Controls::Primitives;
|
| 41 | using namespace Windows::UI::Core;
|
| 42 | using namespace Windows::UI::Xaml::Data;
|
| 43 | using namespace Windows::UI::Xaml::Input;
|
| 44 | using namespace Windows::UI::Xaml::Interop;
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 45 | using namespace Windows::UI::Xaml::Navigation;
|
| 46 | using namespace Windows::ApplicationModel::Activation;
|
| 47 | using namespace Windows::Graphics::Display;
|
| 48 | using namespace Windows::System;
|
| 49 |
|
| 50 | MainPage::MainPage()
|
| 51 | {
|
| 52 | InitializeComponent();
|
| 53 |
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 54 | Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::OnResize);
|
| 55 |
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 56 | _welcomeFrame_->Navigate(TypeName(RingClientUWP::Views::WelcomePage::typeid));
|
| 57 | _smartPanel_->Navigate(TypeName(RingClientUWP::Views::SmartPanel::typeid));
|
| 58 | _consolePanel_->Navigate(TypeName(RingClientUWP::Views::RingConsolePanel::typeid));
|
Nicolas Jager | e069c41 | 2016-08-15 15:00:17 -0400 | [diff] [blame] | 59 | _videoFrame_->Navigate(TypeName(RingClientUWP::Views::VideoPage::typeid));
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 60 | _messageTextFrame_->Navigate(TypeName(RingClientUWP::Views::MessageTextPage::typeid));
|
| 61 |
|
| 62 | /* connect to delegates */
|
| 63 | ContactsViewModel::instance->newContactSelected += ref new NewContactSelected([&]() {
|
| 64 | showFrame(_messageTextFrame_);
|
| 65 | });
|
| 66 | ContactsViewModel::instance->noContactSelected += ref new NoContactSelected([&]() {
|
| 67 | showFrame(_welcomeFrame_);
|
| 68 | });
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 69 |
|
| 70 | DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
|
| 71 | dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
|
Nicolas Jager | 7bef149 | 2016-09-14 11:23:29 -0400 | [diff] [blame] | 72 | Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
|
Nicolas Jager | 998fbd7 | 2016-08-08 11:41:28 -0400 | [diff] [blame] | 73 | }
|
| 74 |
|
| 75 | void
|
| 76 | MainPage::OnKeyDown(KeyRoutedEventArgs^ e)
|
| 77 | {
|
| 78 | if (e->Key == VirtualKey::F5) {
|
| 79 | _outerSplitView_->OpenPaneLength = Window::Current->Bounds.Width;
|
| 80 | _outerSplitView_->IsPaneOpen = !_outerSplitView_->IsPaneOpen;
|
| 81 | }
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 82 | }
|
| 83 |
|
| 84 | void RingClientUWP::MainPage::_toggleSmartBoxButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
| 85 | {
|
| 86 | _innerSplitView_->IsPaneOpen = !_innerSplitView_->IsPaneOpen;
|
atraczyk | 0cf42d7 | 2016-09-06 11:16:37 -0400 | [diff] [blame] | 87 | if (_innerSplitView_->IsPaneOpen) {
|
| 88 | dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Normal);
|
| 89 | _hamburgerButtonBar_->Width = 320;
|
| 90 | }
|
| 91 | else {
|
| 92 | dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Minimized);
|
| 93 | _hamburgerButtonBar_->Width = 60;
|
| 94 | }
|
Nicolas Jager | 1586120 | 2016-08-12 11:13:05 -0400 | [diff] [blame] | 95 | }
|
Nicolas Jager | 8a85e1f | 2016-08-15 15:11:06 -0400 | [diff] [blame] | 96 |
|
| 97 | void
|
| 98 | RingClientUWP::MainPage::showFrame(Windows::UI::Xaml::Controls::Frame^ frame)
|
| 99 | {
|
| 100 | _navGrid_->SetRow(_welcomeFrame_, 0);
|
| 101 | _navGrid_->SetRow(_messageTextFrame_, 0);
|
| 102 | _navGrid_->SetRow(_videoFrame_, 0);
|
| 103 |
|
| 104 | if (frame == _welcomeFrame_) {
|
| 105 | _navGrid_->SetRow(_welcomeFrame_, 1);
|
| 106 | } else if (frame == _videoFrame_) {
|
| 107 | _navGrid_->SetRow(_videoFrame_, 1);
|
| 108 | } else if (frame == _messageTextFrame_) {
|
| 109 | _navGrid_->SetRow(_messageTextFrame_, 1);
|
| 110 | dynamic_cast<MessageTextPage^>(_messageTextFrame_->Content)->updatePageContent();
|
| 111 | }
|
| 112 | }
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 113 |
|
| 114 | void
|
| 115 | RingClientUWP::MainPage::OnNavigatedTo(NavigationEventArgs ^ e)
|
| 116 | {
|
| 117 | RingD::instance->startDaemon();
|
atraczyk | 1ddcb5a | 2016-09-07 16:18:30 -0400 | [diff] [blame] | 118 | showLoadingOverlay(true, false);
|
| 119 | }
|
| 120 |
|
| 121 | void
|
| 122 | RingClientUWP::MainPage::showLoadingOverlay(bool load, bool modal)
|
| 123 | {
|
| 124 | if (!isLoading && load) {
|
| 125 | isLoading = true;
|
| 126 | _loadingOverlay_->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
| 127 | if (modal) {
|
| 128 | _fadeInModalStoryboard_->Begin();
|
| 129 | auto blackBrush = ref new Windows::UI::Xaml::Media::SolidColorBrush(Windows::UI::Colors::Black);
|
| 130 | _loadingOverlayRect_->Fill = blackBrush;
|
| 131 | }
|
| 132 | else {
|
| 133 | auto whiteBrush = ref new Windows::UI::Xaml::Media::SolidColorBrush(Windows::UI::Colors::White);
|
| 134 | _loadingOverlayRect_->Fill = whiteBrush;
|
| 135 | _loadingOverlayRect_->Opacity = 1.0;
|
| 136 | }
|
| 137 | OnResize(nullptr, nullptr);
|
| 138 | }
|
| 139 | else if (!load) {
|
| 140 | isLoading = false;
|
| 141 | _fadeOutStoryboard_->Begin();
|
| 142 | }
|
| 143 | }
|
| 144 |
|
| 145 | void
|
| 146 | RingClientUWP::MainPage::PositionImage()
|
| 147 | {
|
| 148 | bounds = ApplicationView::GetForCurrentView()->VisibleBounds;
|
| 149 |
|
| 150 | auto img = ref new Image();
|
| 151 | auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage();
|
| 152 | Windows::Foundation::Uri^ uri;
|
| 153 |
|
| 154 | if (bounds.Width < 1200)
|
| 155 | uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/TESTS/logo-ring.scale-200.png");
|
| 156 | else
|
| 157 | uri = ref new Windows::Foundation::Uri("ms-appx:///Assets/TESTS/logo-ring.scale-150.png");
|
| 158 |
|
| 159 | bitmapImage->UriSource = uri;
|
| 160 | img->Source = bitmapImage;
|
| 161 | _loadingImage_->Source = img->Source;
|
| 162 |
|
| 163 | _loadingImage_->SetValue(Canvas::LeftProperty, bounds.Width * 0.5 - _loadingImage_->Width * 0.5);
|
| 164 | _loadingImage_->SetValue(Canvas::TopProperty, bounds.Height * 0.5 - _loadingImage_->Height * 0.5);
|
| 165 | }
|
| 166 |
|
| 167 | void
|
| 168 | RingClientUWP::MainPage::PositionRing()
|
| 169 | {
|
| 170 | double left;
|
| 171 | double top;
|
| 172 | if (bounds.Width < 1200) {
|
| 173 | _splashProgressRing_->Width = 118;
|
| 174 | _splashProgressRing_->Height = 118;
|
| 175 | left = bounds.Width * 0.5 - _loadingImage_->Width * 0.5 - 145;
|
| 176 | top = bounds.Height * 0.5 - _loadingImage_->Height * 0.5 - 60;
|
| 177 | }
|
| 178 | else {
|
| 179 | _splashProgressRing_->Width = 162;
|
| 180 | _splashProgressRing_->Height = 162;
|
| 181 | left = bounds.Width * 0.5 - _loadingImage_->Width * 0.5 - 195;
|
| 182 | top = bounds.Height * 0.5 - _loadingImage_->Height * 0.5 - 84;
|
| 183 | }
|
| 184 | _splashProgressRing_->SetValue(Canvas::LeftProperty, left + _loadingImage_->Width * 0.5);
|
| 185 | _splashProgressRing_->SetValue(Canvas::TopProperty, top + _loadingImage_->Height * 0.5);
|
| 186 | }
|
| 187 |
|
| 188 | void
|
| 189 | RingClientUWP::MainPage::OnResize(Platform::Object^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ e)
|
| 190 | {
|
| 191 | PositionImage();
|
| 192 | PositionRing();
|
| 193 | }
|
| 194 |
|
| 195 | void
|
| 196 | RingClientUWP::MainPage::DisplayProperties_DpiChanged(DisplayInformation^ sender, Platform::Object^ args)
|
| 197 | {
|
| 198 | OnResize(nullptr, nullptr);
|
| 199 | }
|
| 200 |
|
| 201 | void
|
| 202 | RingClientUWP::MainPage::hideLoadingOverlay()
|
| 203 | {
|
| 204 | _loadingOverlay_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
atraczyk | 61b2842 | 2016-08-24 09:25:59 -0400 | [diff] [blame] | 205 | } |