blob: 6a13b2291e27e1fdd6e2b07611cbe61c46bc1877 [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 */
Nicolas Jagerc551c362016-10-01 19:24:50 -040063 RingD::instance->stateChange += ref new RingClientUWP::StateChange(this, &RingClientUWP::MainPage::OnstateChange);
64 auto smartPanel = dynamic_cast<SmartPanel^>(_smartPanel_->Content);
65 smartPanel->summonMessageTextPage += ref new RingClientUWP::SummonMessageTextPage(this, &RingClientUWP::MainPage::OnsummonMessageTextPage);
66 smartPanel->summonWelcomePage += ref new RingClientUWP::SummonWelcomePage(this, &RingClientUWP::MainPage::OnsummonWelcomePage);
67 smartPanel->summonVideoPage += ref new RingClientUWP::SummonVideoPage(this, &RingClientUWP::MainPage::OnsummonVideoPage);
68 auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
69 videoPage->pressHangUpCall += ref new RingClientUWP::PressHangUpCall(this, &RingClientUWP::MainPage::OnpressHangUpCall);
atraczyk1ddcb5a2016-09-07 16:18:30 -040070
71 DisplayInformation^ displayInformation = DisplayInformation::GetForCurrentView();
72 dpiChangedtoken = (displayInformation->DpiChanged += ref new TypedEventHandler<DisplayInformation^,
Nicolas Jager7bef1492016-09-14 11:23:29 -040073 Platform::Object^>(this, &MainPage::DisplayProperties_DpiChanged));
Nicolas Jager998fbd72016-08-08 11:41:28 -040074}
75
76void
77MainPage::OnKeyDown(KeyRoutedEventArgs^ e)
78{
79 if (e->Key == VirtualKey::F5) {
80 _outerSplitView_->OpenPaneLength = Window::Current->Bounds.Width;
81 _outerSplitView_->IsPaneOpen = !_outerSplitView_->IsPaneOpen;
82 }
Nicolas Jager15861202016-08-12 11:13:05 -040083}
84
85void RingClientUWP::MainPage::_toggleSmartBoxButton__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
86{
87 _innerSplitView_->IsPaneOpen = !_innerSplitView_->IsPaneOpen;
atraczyk0cf42d72016-09-06 11:16:37 -040088 if (_innerSplitView_->IsPaneOpen) {
89 dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Normal);
90 _hamburgerButtonBar_->Width = 320;
91 }
92 else {
93 dynamic_cast<SmartPanel^>(_smartPanel_->Content)->setMode(Views::SmartPanel::Mode::Minimized);
94 _hamburgerButtonBar_->Width = 60;
95 }
Nicolas Jager15861202016-08-12 11:13:05 -040096}
Nicolas Jager8a85e1f2016-08-15 15:11:06 -040097
98void
99RingClientUWP::MainPage::showFrame(Windows::UI::Xaml::Controls::Frame^ frame)
100{
101 _navGrid_->SetRow(_welcomeFrame_, 0);
102 _navGrid_->SetRow(_messageTextFrame_, 0);
103 _navGrid_->SetRow(_videoFrame_, 0);
104
105 if (frame == _welcomeFrame_) {
106 _navGrid_->SetRow(_welcomeFrame_, 1);
107 } else if (frame == _videoFrame_) {
108 _navGrid_->SetRow(_videoFrame_, 1);
109 } else if (frame == _messageTextFrame_) {
110 _navGrid_->SetRow(_messageTextFrame_, 1);
Nicolas Jager8a85e1f2016-08-15 15:11:06 -0400111 }
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;
Nicolas Jagerc551c362016-10-01 19:24:50 -0400205}
206
207void RingClientUWP::MainPage::OnsummonMessageTextPage()
208{
209 auto messageTextPage = dynamic_cast<MessageTextPage^>(_messageTextFrame_->Content);
210 messageTextPage->updatePageContent();
211 showFrame(_messageTextFrame_);
212
213}
214
215
216void RingClientUWP::MainPage::OnsummonWelcomePage()
217{
218 showFrame(_welcomeFrame_);
219}
220
221
222void RingClientUWP::MainPage::OnsummonVideoPage()
223{
224 auto videoPage = dynamic_cast<VideoPage^>(_videoFrame_->Content);
225 videoPage->updatePageContent();
226 showFrame(_videoFrame_);
227}
228
229
230void RingClientUWP::MainPage::OnpressHangUpCall()
231{
232 OnsummonMessageTextPage();
233}
234
235
236
237void RingClientUWP::MainPage::OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code)
238{
239 auto item = SmartPanelItemsViewModel::instance->_selectedItem;
240
241 switch (state) {
242 /* send the user to the peer's message text page */
243 case CallStatus::ENDED:
244 {
245 if (item)
246 OnsummonMessageTextPage();
247 break;
248 }
Nicolas Jagerc551c362016-10-01 19:24:50 -0400249 default:
250 break;
251 }
252
253}
atraczyk14ba30c2016-09-22 18:31:59 -0400254
255void
256MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingEventArgs^ e)
257{
258 WriteLine("Application_Suspending");
259 if (Frame->CurrentSourcePageType.Name ==
Nicolas Jager083b3ae2016-10-04 08:46:19 -0400260 Interop::TypeName(MainPage::typeid).Name)
atraczyk14ba30c2016-09-22 18:31:59 -0400261 {
262 if (Video::VideoManager::instance->captureManager()->captureTaskTokenSource)
263 Video::VideoManager::instance->captureManager()->captureTaskTokenSource->cancel();
264 //displayInformation->OrientationChanged -= displayInformationEventToken;
265 auto deferral = e->SuspendingOperation->GetDeferral();
266 Video::VideoManager::instance->captureManager()->CleanupCameraAsync()
Nicolas Jager083b3ae2016-10-04 08:46:19 -0400267 .then([this, deferral]() {
atraczyk14ba30c2016-09-22 18:31:59 -0400268 deferral->Complete();
269 });
270 }
271}
272
273void
274MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventArgs^ e)
275{
276 if (e->Visible)
277 {
278 WriteLine("->Visible");
279 if (Video::VideoManager::instance->captureManager()->isInitialized) {
280 Video::VideoManager::instance->captureManager()->InitializeCameraAsync();
281 }
282 }
283 else
284 {
285 WriteLine("->Invisible");
286 }
Nicolas Jager083b3ae2016-10-04 08:46:19 -0400287}
288