From: Lukasz Stanislawski Date: Wed, 28 Oct 2020 11:59:13 +0000 (+0100) Subject: Basic App navigation X-Git-Tag: accepted/tizen/unified/20210915.100113~152 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9391ad2346ec5fd91ec912568d98c6b6f982459a;p=profile%2Fiot%2Fapps%2Fdotnet%2Ffitness.git Basic App navigation 1. Add set of controls for stack based navigation 2. Add NavigationService to manager all navigation and make it available to user from ViewModels --- diff --git a/Fitness/Controls/INavigationStack.cs b/Fitness/Controls/INavigationStack.cs new file mode 100644 index 0000000..b29d399 --- /dev/null +++ b/Fitness/Controls/INavigationStack.cs @@ -0,0 +1,15 @@ +namespace Fitness.Controls +{ + public interface INavigationStack + { + /// + /// Pushes page on navigation stack + /// + void Push(Page page); + + /// + /// Pops top page from navigation stack + /// + void Pop(); + } +} diff --git a/Fitness/Controls/NavigationStack.cs b/Fitness/Controls/NavigationStack.cs new file mode 100644 index 0000000..55c9a28 --- /dev/null +++ b/Fitness/Controls/NavigationStack.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; + +namespace Fitness.Controls +{ + /// + /// Implements stack-based navigation + /// + public class NavigationStack : Control, INavigationStack + { + private Stack pages = new Stack(); + + public NavigationStack() + : base() + { + WidthResizePolicy = ResizePolicyType.FillToParent; + HeightResizePolicy = ResizePolicyType.FillToParent; + } + + public List Pages { get => new List(pages); } + + public void Push(Page page) + { + Add(page); + pages.Push(page); + } + + public void Pop() + { + if (pages.TryPeek(out Page last)) + { + Remove(last); + pages.Pop(); + } + } + } +} diff --git a/Fitness/Controls/Page.cs b/Fitness/Controls/Page.cs new file mode 100644 index 0000000..0a553e4 --- /dev/null +++ b/Fitness/Controls/Page.cs @@ -0,0 +1,19 @@ +using Tizen.NUI; +using Tizen.NUI.BaseComponents; +using Tizen.NUI.Components; + +namespace Fitness.Controls +{ + /// + /// Base class for full-screen page navigation + /// + public class Page : Control + { + public Page() + : base() + { + WidthResizePolicy = ResizePolicyType.FillToParent; + HeightResizePolicy = ResizePolicyType.FillToParent; + } + } +} diff --git a/Fitness/FitnessApp.cs b/Fitness/FitnessApp.cs index ef14fd0..a1508f1 100644 --- a/Fitness/FitnessApp.cs +++ b/Fitness/FitnessApp.cs @@ -1,6 +1,5 @@ using System; using Fitness.Services; -using Fitness.Views; using Tizen.NUI; using Tizen.NUI.BaseComponents; @@ -16,7 +15,7 @@ namespace Fitness public void Initialize() { - Window.Instance.GetDefaultLayer().Add(new MainView()); + NavigationService.Instance.NavigateToMainView(); } protected override void OnCreate() diff --git a/Fitness/Services/NavigationService.cs b/Fitness/Services/NavigationService.cs new file mode 100644 index 0000000..4ad075f --- /dev/null +++ b/Fitness/Services/NavigationService.cs @@ -0,0 +1,56 @@ +using Fitness.Controls; +using Fitness.Views; +using Tizen.NUI; + +namespace Fitness.Services +{ + public sealed class NavigationService + { + private static NavigationService instance; + private NavigationStack navigation; + + private NavigationService() + { + navigation = new NavigationStack(); + Window.Instance.GetDefaultLayer().Add(navigation); + } + + public static NavigationService Instance + { + get + { + if (instance == null) + { + instance = new NavigationService(); + } + + return instance; + } + } + + public void NavigateToMainView() + { + navigation.Push(new MainView()); + } + + public void NavigateToExercisingView() + { + navigation.Push(new ExercisingView()); + } + + public void NavigateToExercisePreviewView() + { + navigation.Push(new ExercisePreviewView()); + } + + public void NavigateToScanningView() + { + navigation.Push(new ScanningView()); + } + + public void NavigateToLoadingView() + { + navigation.Push(new LoadingView()); + } + } +} diff --git a/Fitness/ViewModels/MainViewModel.cs b/Fitness/ViewModels/MainViewModel.cs index 9cc1517..6fc03c7 100644 --- a/Fitness/ViewModels/MainViewModel.cs +++ b/Fitness/ViewModels/MainViewModel.cs @@ -1,7 +1,10 @@ using System; using System.Collections.ObjectModel; +using System.Windows.Input; using Fitness.Models; +using Fitness.Services; using Tizen.Applications; +using Tizen.NUI.Binding; namespace Fitness.ViewModels { @@ -132,11 +135,24 @@ namespace Fitness.ViewModels ThumbnailUrl = Application.Current.DirectoryInfo.Resource + "media/video-0002.jpeg", }, }); + + WatchPreview = new Command(() => { NavigationService.Instance.NavigateToExercisePreviewView(); }); + StartWorkout = new Command(() => { NavigationService.Instance.NavigateToExercisingView(); }); } /// /// List of all available workouts /// public ObservableCollection Workouts { get; private set; } + + /// + /// Watch selected workout preview + /// + public ICommand WatchPreview { get; private set; } + + /// + /// Start selected workout. + /// + public ICommand StartWorkout { get; private set; } } } diff --git a/Fitness/Views/ExercisePreviewView.cs b/Fitness/Views/ExercisePreviewView.cs index 08fb6c0..5dfbf3c 100644 --- a/Fitness/Views/ExercisePreviewView.cs +++ b/Fitness/Views/ExercisePreviewView.cs @@ -1,8 +1,9 @@ +using Fitness.Controls; using Tizen.NUI.BaseComponents; namespace Fitness.Views { - public partial class ExercisePreviewView : View + public partial class ExercisePreviewView : Page { public ExercisePreviewView() { diff --git a/Fitness/Views/ExercisingView.cs b/Fitness/Views/ExercisingView.cs index 60e7bb9..2f3888e 100644 --- a/Fitness/Views/ExercisingView.cs +++ b/Fitness/Views/ExercisingView.cs @@ -1,8 +1,9 @@ +using Fitness.Controls; using Tizen.NUI.BaseComponents; namespace Fitness.Views { - public partial class ExercisingView : View + public partial class ExercisingView : Page { public ExercisingView() { diff --git a/Fitness/Views/LoadingView.cs b/Fitness/Views/LoadingView.cs index 6585649..4d41d0f 100644 --- a/Fitness/Views/LoadingView.cs +++ b/Fitness/Views/LoadingView.cs @@ -1,8 +1,9 @@ +using Fitness.Controls; using Tizen.NUI.BaseComponents; namespace Fitness.Views { - public partial class LoadingView : View + public partial class LoadingView : Page { public LoadingView() { diff --git a/Fitness/Views/MainView.xaml.cs b/Fitness/Views/MainView.xaml.cs index 79763f1..725fc1b 100644 --- a/Fitness/Views/MainView.xaml.cs +++ b/Fitness/Views/MainView.xaml.cs @@ -1,9 +1,10 @@ +using Fitness.Controls; using Tizen.NUI; using Tizen.NUI.BaseComponents; namespace Fitness.Views { - public partial class MainView : View + public partial class MainView : Fitness.Controls.Page { public MainView() { diff --git a/Fitness/Views/ScanningView.cs b/Fitness/Views/ScanningView.cs index e48c2a5..3de6211 100644 --- a/Fitness/Views/ScanningView.cs +++ b/Fitness/Views/ScanningView.cs @@ -1,8 +1,9 @@ +using Fitness.Controls; using Tizen.NUI.BaseComponents; namespace Fitness.Views { - public partial class ScanningView : View + public partial class ScanningView : Page { public ScanningView() { diff --git a/Fitness/res/layout/ExercisePreviewView.xaml b/Fitness/res/layout/ExercisePreviewView.xaml index 8efd3de..4bc9d70 100644 --- a/Fitness/res/layout/ExercisePreviewView.xaml +++ b/Fitness/res/layout/ExercisePreviewView.xaml @@ -1,6 +1,7 @@ - - + xmlns:ctrl="clr-namespace:Fitness.Controls" + HeightResizePolicy="FillToParent" WidthResizePolicy="FillToParent" BackgroundColor="Red" ParentOrigin="Center" PivotPoint="Center" PositionUsesPivotPoint="true"> + diff --git a/Fitness/res/layout/ExercisingView.xaml b/Fitness/res/layout/ExercisingView.xaml index 940f50f..b137d76 100644 --- a/Fitness/res/layout/ExercisingView.xaml +++ b/Fitness/res/layout/ExercisingView.xaml @@ -1,6 +1,7 @@ - - + xmlns:ctrl="clr-namespace:Fitness.Controls" + HeightResizePolicy="FillToParent" WidthResizePolicy="FillToParent" BackgroundColor="Red" ParentOrigin="Center" PivotPoint="Center" PositionUsesPivotPoint="true"> + diff --git a/Fitness/res/layout/LoadingView.xaml b/Fitness/res/layout/LoadingView.xaml index b0377a5..d43e190 100644 --- a/Fitness/res/layout/LoadingView.xaml +++ b/Fitness/res/layout/LoadingView.xaml @@ -1,6 +1,7 @@ - - + diff --git a/Fitness/res/layout/MainView.xaml b/Fitness/res/layout/MainView.xaml index c96009e..6018a36 100644 --- a/Fitness/res/layout/MainView.xaml +++ b/Fitness/res/layout/MainView.xaml @@ -1,17 +1,18 @@ - - - - + + + @@ -22,11 +23,11 @@ - - + + - + diff --git a/Fitness/res/layout/ScanningView.xaml b/Fitness/res/layout/ScanningView.xaml index e111ae9..2cdf024 100644 --- a/Fitness/res/layout/ScanningView.xaml +++ b/Fitness/res/layout/ScanningView.xaml @@ -1,6 +1,7 @@ - - +