From 66cf400bd1a54a2840eb9312ba2b5260d466f70a Mon Sep 17 00:00:00 2001 From: Lukasz Stanislawski Date: Thu, 12 Nov 2020 15:29:36 +0100 Subject: [PATCH] LoadingView implementation --- Fitness/ViewModels/LoadingViewModel.cs | 88 ++++++++++++++++++++++++++++++++++ Fitness/ViewModels/WorkoutViewModel.cs | 2 +- Fitness/res/layout/LoadingView.xaml | 12 ++++- Fitness/res/layout/images/circle.svg | 3 ++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 Fitness/ViewModels/LoadingViewModel.cs create mode 100644 Fitness/res/layout/images/circle.svg diff --git a/Fitness/ViewModels/LoadingViewModel.cs b/Fitness/ViewModels/LoadingViewModel.cs new file mode 100644 index 0000000..14c0300 --- /dev/null +++ b/Fitness/ViewModels/LoadingViewModel.cs @@ -0,0 +1,88 @@ +using System; +using Fitness.Services; +using Tizen.NUI; + +namespace Fitness.ViewModels +{ + public class LoadingViewModel : BaseViewModel, IDisposable + { + private const int TickIntervalInMilliseconds = 1500; + private string text; + private Timer timer; + private bool disposed = false; + + private string[] messages = new string[] + { + "get ready", + "1", + "2", + "3", + "GO!", + string.Empty, + }; + + public LoadingViewModel() + { + StartCounting(); + } + + ~LoadingViewModel() + { + Dispose(false); + } + + public string Text + { + get => text; + set + { + if (text != value) + { + text = value; + RaisePropertyChanged(); + } + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposed) + { + if (disposing) + { + timer?.Dispose(); + } + + disposed = true; + } + } + + private void StartCounting() + { + int count = 0; + timer = new Timer(TickIntervalInMilliseconds); + Text = messages[count++]; + + timer.Tick += (sender, args) => + { + Text = messages[count++]; + + if (count == messages.Length) + { + Services.NavigationService.Instance.NavigateToExercisingView(); + return false; + } + + return true; + }; + + timer.Start(); + } + } +} diff --git a/Fitness/ViewModels/WorkoutViewModel.cs b/Fitness/ViewModels/WorkoutViewModel.cs index 48c0f5d..4dbc02e 100644 --- a/Fitness/ViewModels/WorkoutViewModel.cs +++ b/Fitness/ViewModels/WorkoutViewModel.cs @@ -14,7 +14,7 @@ namespace Fitness.ViewModels { public WorkoutViewModel() { - WatchPreview = new Command(() => { NavigationService.Instance.NavigateToExercisePreviewView(); }); + WatchPreview = new Command(() => { NavigationService.Instance.NavigateToLoadingView(); }); StartWorkout = new Command(() => { NavigationService.Instance.NavigateToScanningView(); }); } diff --git a/Fitness/res/layout/LoadingView.xaml b/Fitness/res/layout/LoadingView.xaml index d43e190..dc67e47 100644 --- a/Fitness/res/layout/LoadingView.xaml +++ b/Fitness/res/layout/LoadingView.xaml @@ -3,5 +3,15 @@ xmlns="http://tizen.org/Tizen.NUI/2018/XAML" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ctrl="clr-namespace:Fitness.Controls" - HeightResizePolicy="FillToParent" WidthResizePolicy="FillToParent" BackgroundColor="#EEEFF1" ParentOrigin="Center" PivotPoint="Center" PositionUsesPivotPoint="true"> + xmlns:vm="clr-namespace:Fitness.ViewModels" + BackgroundColor="#EEEFF1" + > + + + + + + + + diff --git a/Fitness/res/layout/images/circle.svg b/Fitness/res/layout/images/circle.svg new file mode 100644 index 0000000..a6c590a --- /dev/null +++ b/Fitness/res/layout/images/circle.svg @@ -0,0 +1,3 @@ + + + -- 2.7.4