Disabled navigation buttons on edges.
authorAndrzej Krawczyk <a.krawczyk@samsung.com>
Fri, 6 Aug 2021 13:23:23 +0000 (15:23 +0200)
committerPiotr Czaja <p.czaja@samsung.com>
Tue, 14 Sep 2021 11:01:34 +0000 (13:01 +0200)
Fitness/ViewModels/ChangeWorkoutViewModel.cs
Fitness/ViewModels/ExercisingViewModel.cs
Fitness/Views/Converters/CommandToBoolConverter.cs [new file with mode: 0644]
Fitness/res/layout/BarView.xaml
Fitness/res/layout/ExercisePreviewView.xaml

index 18c9e16d5c5f829a6544a851a1d2db27e26458ca..95b29fa3aaafc65a6f094b239d3d6e6308240464 100644 (file)
@@ -11,15 +11,14 @@ namespace Fitness.ViewModels
     public abstract class ChangeWorkoutViewModel : BaseViewModel
     {
         private WorkoutViewModel currentWorkout;
+        private ICommand previousWorkout;
+        private ICommand nextWorkout;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="ChangeWorkoutViewModel"/> class.
         /// </summary>
         public ChangeWorkoutViewModel()
         {
-            PreviousWorkout = new Command(GoPrevious);
-            NextWorkout = new Command(GoNext);
-
             Workouts = WorkoutRepository.Instance.GetAll();
         }
 
@@ -35,6 +34,8 @@ namespace Fitness.ViewModels
                 {
                     currentWorkout = value;
                     RaisePropertyChanged();
+
+                    UpdateeWorkoutNavigation();
                 }
             }
         }
@@ -42,12 +43,34 @@ namespace Fitness.ViewModels
         /// <summary>
         /// Gets previous workout.
         /// </summary>
-        public ICommand PreviousWorkout { get; private set; }
+        public ICommand PreviousWorkout
+        {
+            get => previousWorkout;
+            protected set
+            {
+                if (value != previousWorkout)
+                {
+                    previousWorkout = value;
+                    RaisePropertyChanged();
+                }
+            }
+        }
 
         /// <summary>
         /// Gets next workout.
         /// </summary>
-        public ICommand NextWorkout { get; private set; }
+        public ICommand NextWorkout
+        {
+            get => nextWorkout;
+            protected set
+            {
+                if (value != nextWorkout)
+                {
+                    nextWorkout = value;
+                    RaisePropertyChanged();
+                }
+            }
+        }
 
         /// <summary>
         /// Gets list of all available workouts.
@@ -57,17 +80,27 @@ namespace Fitness.ViewModels
         /// <summary>
         /// Go to next workout.
         /// </summary>
-        protected virtual void GoNext()
+        protected virtual ICommand GetGoNext()
         {
-            MoveBy(1);
+            if (Workouts.IndexOf(CurrentWorkout) + 1 >= Workouts.Count)
+            {
+                return null;
+            }
+
+            return new Command(() => MoveBy(1));
         }
 
         /// <summary>
         /// Go to previous workout.
         /// </summary>
-        protected virtual void GoPrevious()
+        protected virtual ICommand GetGoPrevious()
         {
-            MoveBy(-1);
+            if (Workouts.IndexOf(CurrentWorkout) - 1 < 0)
+            {
+                return null;
+            }
+
+            return new Command(() => MoveBy(-1));
         }
 
         private void MoveBy(int offset)
@@ -78,5 +111,11 @@ namespace Fitness.ViewModels
                 CurrentWorkout = Workouts[idx];
             }
         }
+
+        private void UpdateeWorkoutNavigation()
+        {
+            PreviousWorkout = GetGoPrevious();
+            NextWorkout = GetGoNext();
+        }
     }
 }
index 3cb05c61d96f50059568cb4b024172bcae50aa5b..6684f84b5f7adc9192c46b38ed23a6bcb4672d36 100644 (file)
@@ -251,10 +251,26 @@ namespace Fitness.ViewModels
         public IExerciseService SquatService { get; private set; }
 
         /// <inheritdoc />
-        protected override void GoPrevious() => ConfirmChangeWorkout(-1);
+        protected override ICommand GetGoPrevious()
+        {
+            if (Workouts.IndexOf(CurrentWorkout) - 1 < 0)
+            {
+                return null;
+            }
+
+            return new Command(() => ConfirmChangeWorkout(-1));
+        }
 
         /// <inheritdoc />
-        protected override void GoNext() => ConfirmChangeWorkout(1);
+        protected override ICommand GetGoNext()
+        {
+            if (Workouts.IndexOf(CurrentWorkout) + 1 >= Workouts.Count)
+            {
+                return null;
+            }
+
+            return new Command(() => ConfirmChangeWorkout(1));
+        }
 
         private void ConfirmChangeWorkout(int offset)
         {
diff --git a/Fitness/Views/Converters/CommandToBoolConverter.cs b/Fitness/Views/Converters/CommandToBoolConverter.cs
new file mode 100644 (file)
index 0000000..3bc1611
--- /dev/null
@@ -0,0 +1,21 @@
+using System;
+using System.Globalization;
+using Tizen.NUI.Binding;
+
+namespace Fitness.Views.Converters
+{
+    public class CommandToBoolConverter : IValueConverter
+    {
+        public static CommandToBoolConverter Converter => new CommandToBoolConverter();
+
+        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+        {
+            return value is Command;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}
index 43f06381635b71c1839db1a98d3dda19f537e4ea..03b61f99ea90b6ee8dabd7de12292148bb65cb1c 100644 (file)
@@ -8,6 +8,7 @@
       xmlns:nui="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
       xmlns:styles="clr-namespace:Fitness.Views.Styles"
       xmlns:behaviors="clr-namespace:Fitness.Views.Behaviors"
+      xmlns:converters="clr-namespace:Fitness.Views.Converters"
       WidthSpecification="{Static LayoutParamPolicies.MatchParent}"
       Size="{views:SizeInUnits Height=30}"
       x:Name="Root">
@@ -16,6 +17,7 @@
                           x:Name="prev"
                           Position="{views:PositionInUnits X=17, Y=10}"
                           Size="{views:SizeInUnits Width=64, Height=20}"
+                          IsEnabled="{Binding PreviousWorkout, Converter={x:Static converters:CommandToBoolConverter.Converter}}"
                           behaviors:StyleSetter.Style="{x:Static styles:Buttons.Previous}"/>
 
     <TextLabel x:Name="title"
@@ -29,6 +31,7 @@
                           x:Name="next"
                           Position="{views:PositionInUnits X=400, Y=10}"
                           Size="{views:SizeInUnits Width=64, Height=20}"
+                          IsEnabled="{Binding NextWorkout, Converter={x:Static converters:CommandToBoolConverter.Converter}}"
                           behaviors:StyleSetter.Style="{x:Static styles:Buttons.Next}"/>
 
 </View>
index 26403d2bb0dd018f77d992ac16db56d5c03cab44..2da02436638760130997fd7b3ec005edbac6f43e 100644 (file)
@@ -3,6 +3,7 @@
            xmlns="http://tizen.org/Tizen.NUI/2018/XAML"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:ctrl="clr-namespace:Fitness.Controls"
+           xmlns:converters="clr-namespace:Fitness.Views.Converters"
            xmlns:vm="clr-namespace:Fitness.ViewModels"
            xmlns:views="clr-namespace:Fitness.Views"
            xmlns:nui="clr-namespace:Tizen.NUI.Components;assembly=Tizen.NUI.Components"
@@ -68,6 +69,7 @@
                                       Text="previous"
                                       x:Name="previousButton"
                                       Command="{Binding PreviousWorkout}"
+                                      IsEnabled="{Binding PreviousWorkout, Converter={x:Static converters:CommandToBoolConverter.Converter}}"
                                       behaviors:StyleSetter.Style="{x:Static styles:Buttons.Previous}"/>
                 
                 <TextLabel BindingContext="{Binding Source={x:Reference context}, Path=CurrentWorkout}"
@@ -85,6 +87,7 @@
                                       x:Name="nextButton"
                                       Margin="{views:ExtentsInUnits Start=10}"
                                       Command="{Binding NextWorkout}"
+                                      IsEnabled="{Binding NextWorkout, Converter={x:Static converters:CommandToBoolConverter.Converter}}"
                                       behaviors:StyleSetter.Style="{x:Static styles:Buttons.Next}"/>
                 
             </View>