Apply fixes after review.
authorPiotr Czaja/Advanced Frameworks (PLT) /SRPOL/Engineer/Samsung Electronics <p.czaja@samsung.com>
Wed, 1 Sep 2021 11:13:22 +0000 (13:13 +0200)
committerPiotr Czaja <p.czaja@samsung.com>
Tue, 14 Sep 2021 11:01:34 +0000 (13:01 +0200)
Fitness/Services/ScreenActivityService.cs [deleted file]
Fitness/Services/ScreenInteractionService.cs [new file with mode: 0644]
Fitness/Services/ScreenInteractionState.cs [new file with mode: 0644]
Fitness/ViewModels/ExercisingViewModel.cs
Fitness/Views/ExercisingView.xaml.cs
Fitness/res/layout/ExercisingView.xaml
Fitness/res/layout/PlayingView.xaml

diff --git a/Fitness/Services/ScreenActivityService.cs b/Fitness/Services/ScreenActivityService.cs
deleted file mode 100644 (file)
index c1e8fd0..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using Tizen.NUI;
-
-namespace Fitness.Services
-{
-    /// <summary>
-    /// Manages screen activity.
-    /// </summary>
-    public class ScreenActivityService : IDisposable
-    {
-        private const uint ActivityInterval = 3000;
-        private readonly Window win = NUIApplication.GetDefaultWindow();
-        private readonly Timer activityTimer;
-
-        /// <summary>
-        /// Initializes a new instance of the <see cref="ScreenActivityService"/> class.
-        /// </summary>
-        public ScreenActivityService()
-        {
-            activityTimer = new Timer(ActivityInterval);
-            activityTimer.Tick += ActivatyTimer_Tick;
-            win.TouchEvent += Win_TouchEvent;
-        }
-
-        /// <summary>
-        /// Raised when the screen is touched.
-        /// </summary>
-        public event EventHandler ScreenActivated;
-
-        /// <summary>
-        /// Raised when the screen is deactivated.
-        /// </summary>
-        public event EventHandler ScreenDeactivated;
-
-        /// <summary>
-        /// Starts the screen activity timer.
-        /// </summary>
-        public void StartTimer()
-        {
-            activityTimer.Start();
-        }
-
-        /// <summary>
-        /// Stops the screen activity timer.
-        /// </summary>
-        public void StopTimer()
-        {
-            activityTimer.Stop();
-        }
-
-        /// <summary>
-        /// Disposes activity timer.
-        /// </summary>
-        public void Dispose()
-        {
-            activityTimer?.Dispose();
-        }
-
-        private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
-        {
-            if (e.Touch.GetState(0) == PointStateType.Down)
-            {
-                ScreenActivated?.Invoke(this, EventArgs.Empty);
-            }
-        }
-
-        private bool ActivatyTimer_Tick(object source, Timer.TickEventArgs e)
-        {
-            ScreenDeactivated?.Invoke(this, EventArgs.Empty);
-            return false;
-        }
-    }
-}
diff --git a/Fitness/Services/ScreenInteractionService.cs b/Fitness/Services/ScreenInteractionService.cs
new file mode 100644 (file)
index 0000000..4fc023e
--- /dev/null
@@ -0,0 +1,68 @@
+using System;
+using Tizen.NUI;
+
+namespace Fitness.Services
+{
+    /// <summary>
+    /// Manages user interaction with the screen.
+    /// </summary>
+    public class ScreenInteractionService : IDisposable
+    {
+        private const uint ActivityInterval = 3000;
+        private readonly Window win = NUIApplication.GetDefaultWindow();
+        private readonly Timer activityTimer;
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="ScreenInteractionService"/> class.
+        /// </summary>
+        public ScreenInteractionService()
+        {
+            activityTimer = new Timer(ActivityInterval);
+            activityTimer.Tick += ActivatyTimer_Tick;
+            win.TouchEvent += Win_TouchEvent;
+        }
+
+        /// <summary>
+        /// Raised when the screen state has changed.
+        /// </summary>
+        public event EventHandler<ScreenInteractionState> ScreenInteractionStateChanged;
+
+        /// <summary>
+        /// Starts the screen activity timer.
+        /// </summary>
+        public void StartTimer()
+        {
+            activityTimer.Start();
+        }
+
+        /// <summary>
+        /// Stops the screen activity timer.
+        /// </summary>
+        public void StopTimer()
+        {
+            activityTimer.Stop();
+        }
+
+        /// <summary>
+        /// Disposes activity timer.
+        /// </summary>
+        public void Dispose()
+        {
+            activityTimer?.Dispose();
+        }
+
+        private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Down)
+            {
+                ScreenInteractionStateChanged.Invoke(this, ScreenInteractionState.Activated);
+            }
+        }
+
+        private bool ActivatyTimer_Tick(object source, Timer.TickEventArgs e)
+        {
+            ScreenInteractionStateChanged.Invoke(this, ScreenInteractionState.Deactivated);
+            return false;
+        }
+    }
+}
diff --git a/Fitness/Services/ScreenInteractionState.cs b/Fitness/Services/ScreenInteractionState.cs
new file mode 100644 (file)
index 0000000..df04e39
--- /dev/null
@@ -0,0 +1,18 @@
+namespace Fitness.Services
+{
+    /// <summary>
+    /// State of screen interaction.
+    /// </summary>
+    public enum ScreenInteractionState
+    {
+        /// <summary>
+        /// Screen interaction activated.
+        /// </summary>
+        Activated,
+
+        /// <summary>
+        /// Screen interaction deactivated.
+        /// </summary>
+        Deactivated,
+    }
+}
index c7820b14d4639bf4d901a17fb82e26f5b208e978..b787029f52fa7b76dbf4ff91baea83499dea3c31 100644 (file)
@@ -25,6 +25,7 @@ namespace Fitness.ViewModels
         private int repetitions;
         private Landmark[,] poseLandmarks;
         private bool isSummaryVisible;
+        private bool isUserInterfaceVisible = true;
         private ICommand summaryBackCommand;
         private ICommand summaryOkCommand;
         private string summaryTitle;
@@ -278,6 +279,22 @@ namespace Fitness.ViewModels
             }
         }
 
+        /// <summary>
+        /// Gets a value indicating whether the summary pop-up is visible.
+        /// </summary>
+        public bool IsUserInterfaceVisible
+        {
+            get => isUserInterfaceVisible;
+            set
+            {
+                if (value != isUserInterfaceVisible)
+                {
+                    isUserInterfaceVisible = value;
+                    RaisePropertyChanged();
+                }
+            }
+        }
+
         /// <summary>
         /// Gets PauseWorkout Command.
         /// </summary>
index c33697550d23251dc964a89e4f6e03eb76a9ddea..492bbfdc9ee06c8b8105b9685ba38d73a245ae27 100644 (file)
@@ -25,7 +25,8 @@ namespace Fitness.Views
 
         private const int TransitionTime = 500;
         private const string UnhandledWorkoutStateMessage = "Unhandled workout state.";
-        private ScreenActivityService screenActivityService;
+        private const string UnhandledScreenInteractionStateMessage = "Unhandled screen interaction state.";
+        private ScreenInteractionService screenActivityService;
         private CancellationTokenSource source;
         private bool isInitialized = false;
         private (Coordinates Preview, Coordinates Camera) playing;
@@ -71,8 +72,7 @@ namespace Fitness.Views
                 cameraView.StopPreview();
             }
 
-            screenActivityService.ScreenActivated -= OnScreenActivated;
-            screenActivityService.ScreenDeactivated -= OnScreenDeactivated;
+            screenActivityService.ScreenInteractionStateChanged -= OnScreenInteractionStateChanged;
         }
 
         /// <summary>
@@ -86,8 +86,7 @@ namespace Fitness.Views
                 cameraView.Preview += DetectPreview;
             }
 
-            screenActivityService.ScreenActivated += OnScreenActivated;
-            screenActivityService.ScreenDeactivated += OnScreenDeactivated;
+            screenActivityService.ScreenInteractionStateChanged += OnScreenInteractionStateChanged;
         }
 
         private static void OnWorkoutStateChanged(BindableObject bindable, object oldValue, object newValue)
@@ -142,7 +141,7 @@ namespace Fitness.Views
 
             PlayingView.PreviewStub.Relayout += OnPlayingViewRelayout;
             cameraView.Preview += DetectPreview;
-            screenActivityService = new ScreenActivityService();
+            screenActivityService = new ScreenInteractionService();
         }
 
         private void ExecuteNewState(WorkoutState newState, WorkoutState oldState)
@@ -169,7 +168,7 @@ namespace Fitness.Views
 
                 case WorkoutState.Playing:
                     _ = ExecutePlayingState(oldState);
-                    OnScreenActivated();
+                    ShowUserInterface();
                     break;
 
                 case WorkoutState.OnHold:
@@ -300,22 +299,39 @@ namespace Fitness.Views
             }
         }
 
-        private void OnScreenActivated(object sender, System.EventArgs e)
+        private void OnScreenInteractionStateChanged(object sender, ScreenInteractionState screenInteractionState)
         {
-            OnScreenActivated();
+            switch (screenInteractionState)
+            {
+                case ScreenInteractionState.Activated:
+                    ShowUserInterface();
+                    break;
+
+                case ScreenInteractionState.Deactivated:
+                    HideUserInterface();
+                    break;
+
+                default:
+                    Services.Logger.Warn(UnhandledScreenInteractionStateMessage);
+                    break;
+            }
         }
 
-        private void OnScreenActivated()
+        private void HideUserInterface()
         {
-            UpperBar.Show();
-            PlayingView.BottomBar.Show();
-            screenActivityService.StartTimer();
+            if (BindingContext is ExercisingViewModel viewModel)
+            {
+                viewModel.IsUserInterfaceVisible = false;
+            }
         }
 
-        private void OnScreenDeactivated(object sender, System.EventArgs e)
+        private void ShowUserInterface()
         {
-            UpperBar.Hide();
-            PlayingView.BottomBar.Hide();
+            if (BindingContext is ExercisingViewModel viewModel)
+            {
+                viewModel.IsUserInterfaceVisible = true;
+            }
+            screenActivityService.StartTimer();
         }
 
         private void OnPlayingViewRelayout(object sender, System.EventArgs e)
index 987d738fc408c0d6593482d2018b8734ed375dc8..8a62c6843b9f3e2317fbe1ea32a9061698d57439 100644 (file)
     
     <!--Layer-->
 
-    <views:BarView x:Name="UpperBar"
-                   BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
+    <views:BarView BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
                    PrevCommand="{Binding PreviousWorkout}"
                    NextCommand="{Binding NextWorkout}"
-                   Title="{Binding CurrentWorkout.Title}"/>
+                   Title="{Binding CurrentWorkout.Title}"
+                   behaviors:VisibilitySetter.IsVisible="{Binding IsUserInterfaceVisible}"/>
     
     <views:LoadingView x:Name="LoadingView"/>
 
index bc67a7d50e36f60ec6f7d8fbd0bde0d8a766b06a..ac9d0183f42582ca03f761c451a3a4552ae8e411 100644 (file)
           Weight="1"/>
     
     <!--Bar-->
-    <View x:Name="BottomBar"
-          Size="{views:SizeInUnits Height=30}"
-          WidthSpecification="{Static LayoutParamPolicies.MatchParent}">
+    <View Size="{views:SizeInUnits Height=30}"
+          WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
+          behaviors:VisibilitySetter.IsVisible="{Binding IsUserInterfaceVisible}">
         <ctrl:NinePatchButton BindingContext="{Binding Source={x:Reference Root}, Path=BindingContext}"
                               PositionUsesPivotPoint="True"
                               ParentOrigin="Center"