LoadingView implementation
authorLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 12 Nov 2020 14:29:36 +0000 (15:29 +0100)
committerPiotr Czaja <p.czaja@samsung.com>
Tue, 14 Sep 2021 11:01:34 +0000 (13:01 +0200)
Fitness/ViewModels/LoadingViewModel.cs [new file with mode: 0644]
Fitness/ViewModels/WorkoutViewModel.cs
Fitness/res/layout/LoadingView.xaml
Fitness/res/layout/images/circle.svg [new file with mode: 0644]

diff --git a/Fitness/ViewModels/LoadingViewModel.cs b/Fitness/ViewModels/LoadingViewModel.cs
new file mode 100644 (file)
index 0000000..14c0300
--- /dev/null
@@ -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();
+        }
+    }
+}
index 48c0f5d..4dbc02e 100644 (file)
@@ -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(); });
         }
 
index d43e190..dc67e47 100644 (file)
@@ -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"
+  >
+  <ctrl:Page.BindingContext>
+      <vm:LoadingViewModel x:Name="context"/>
+  </ctrl:Page.BindingContext>
+  <ctrl:Page.Layout>
+      <AbsoluteLayout/>
+  </ctrl:Page.Layout>
+  <ImageView PositionUsesPivotPoint="true" ParentOrigin="Center" PivotPoint="Center" HeightResizePolicy="SizeRelativeToParent" WidthForHeight="true" SizeModeFactor="0.0,0.8,1.0" ResourceUrl="*Resource*/layout/images/circle.svg" x:Name="image" Opacity="0.48"/>
+  <TextLabel Text="{Binding Text}" PointSize="60" WidthResizePolicy="FillToParent" HeightResizePolicy="FillToParent" PositionUsesPivotPoint="true" PivotPoint="Center" ParentOrigin="Center" VerticalAlignment="Center" HorizontalAlignment="Center" TextColor="#000C2B"/>
 </ctrl:Page>
diff --git a/Fitness/res/layout/images/circle.svg b/Fitness/res/layout/images/circle.svg
new file mode 100644 (file)
index 0000000..a6c590a
--- /dev/null
@@ -0,0 +1,3 @@
+<svg height="748" width="748">
+  <circle cx="374" cy="374" r="374" stroke="#707070" stroke-width="3" fill="white" />
+</svg>