blob: 6a7569d8475280473b1ada4a67f78c6d682bad8c [file] [log] [blame]
Nicolas Jager998fbd72016-08-08 11:41:28 -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
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040020#include "ContactsViewModel.h"
21#include "MessageTextPage.xaml.h"
Nicolas Jager998fbd72016-08-08 11:41:28 -040022#include "SmartPanel.xaml.h"
23#include "RingConsolePanel.xaml.h"
Nicolas Jagere069c412016-08-15 15:00:17 -040024#include "VideoPage.xaml.h"
Nicolas Jager998fbd72016-08-08 11:41:28 -040025#include "WelcomePage.xaml.h"
26
27#include "MainPage.xaml.h"
28
29using namespace RingClientUWP;
30using namespace RingClientUWP::Views;
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040031using namespace RingClientUWP::ViewModel;
Nicolas Jager998fbd72016-08-08 11:41:28 -040032
33using namespace Platform;
Nicolas Jager15861202016-08-12 11:13:05 -040034using namespace Windows::ApplicationModel::Core;
Nicolas Jager998fbd72016-08-08 11:41:28 -040035using namespace Windows::Foundation;
36using namespace Windows::Foundation::Collections;
37using namespace Windows::UI::ViewManagement;
38using namespace Windows::UI::Xaml;
39using namespace Windows::UI::Xaml::Controls;
40using namespace Windows::UI::Xaml::Controls::Primitives;
41using namespace Windows::UI::Core;
42using namespace Windows::UI::Xaml::Data;
43using namespace Windows::UI::Xaml::Input;
44using namespace Windows::UI::Xaml::Interop;
Nicolas Jager998fbd72016-08-08 11:41:28 -040045using namespace Windows::UI::Xaml::Navigation;
46using namespace Windows::ApplicationModel::Activation;
47using namespace Windows::Graphics::Display;
48using namespace Windows::System;
49
50MainPage::MainPage()
51{
52 InitializeComponent();
53
atraczyk1ddcb5a2016-09-07 16:18:30 -040054 Window::Current->SizeChanged += ref new WindowSizeChangedEventHandler(this, &MainPage::OnResize);
55
Nicolas Jager998fbd72016-08-08 11:41:28 -040056 _welcomeFrame_->Navigate(TypeName(RingClientUWP::Views::WelcomePage::typeid));
57 _smartPanel_->Navigate(TypeName(RingClientUWP::Views::SmartPanel::typeid));
58 _consolePanel_->Navigate(TypeName(RingClientUWP::Views::RingConsolePanel::typeid));
Nicolas Jagere069c412016-08-15 15:00:17 -040059 _videoFrame_->Navigate(TypeName(RingClientUWP::Views::VideoPage::typeid));
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040060 _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 });
atraczyk1ddcb5a2016-09-07 16:18:30 -040069
70 DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
71 dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
Nicolas Jager7bef1492016-09-14 11:23:29 -040072 Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
Nicolas Jager998fbd72016-08-08 11:41:28 -040073}
74
75void
76MainPage::OnKeyDown(KeyRoutedEventArgs^ e)
77{
78 if (e->Key == VirtualKey::F5) {
79 _outerSplitView_->OpenPaneLength = Window::Current->Bounds.Width;
80 _outerSplitView_->IsPaneOpen = !_outerSplitView_->IsPaneOpen;
81 }
Nicolas Jager15861202016-08-12 11:13:05 -040082}
83
84void RingClientUWP::MainPage::_toggleSmartBoxButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
85{
86 _innerSplitView_->IsPaneOpen = !_innerSplitView_->IsPaneOpen;
atraczyk0cf42d72016-09-06 11:16:37 -040087 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 Jager15861202016-08-12 11:13:05 -040095}
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040096
97void
98RingClientUWP::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}
atraczyk61b28422016-08-24 09:25:59 -0400113
114void
115RingClientUWP::MainPage::OnNavigatedTo(NavigationEventArgs ^ e)
116{
117 RingD::instance->startDaemon();
atraczyk1ddcb5a2016-09-07 16:18:30 -0400118 showLoadingOverlay(true, false);
119}
120
121void
122RingClientUWP::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
145void
146RingClientUWP::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
167void
168RingClientUWP::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
188void
189RingClientUWP::MainPage::OnResize(Platform::Object^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ e)
190{
191 PositionImage();
192 PositionRing();
193}
194
195void
196RingClientUWP::MainPage::DisplayProperties_DpiChanged(DisplayInformation^ sender, Platform::Object^ args)
197{
198 OnResize(nullptr, nullptr);
199}
200
201void
202RingClientUWP::MainPage::hideLoadingOverlay()
203{
204 _loadingOverlay_->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
atraczyk61b28422016-08-24 09:25:59 -0400205}