From: Lukasz Stanislawski Date: Thu, 1 Oct 2020 09:02:07 +0000 (+0200) Subject: Basic MVVM architecture X-Git-Tag: accepted/tizen/unified/20210915.100113~162 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46b9a46880cb4ee1084bddba9aa7e933695138fb;p=profile%2Fiot%2Fapps%2Fdotnet%2Ffitness.git Basic MVVM architecture --- diff --git a/Fitness/Fitness.csproj b/Fitness/Fitness.csproj index 52b1ac5..d2c4b45 100644 --- a/Fitness/Fitness.csproj +++ b/Fitness/Fitness.csproj @@ -23,11 +23,20 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive all + + + + + + + + diff --git a/Fitness/FitnessApp.cs b/Fitness/FitnessApp.cs index ccc7f9e..ef14fd0 100644 --- a/Fitness/FitnessApp.cs +++ b/Fitness/FitnessApp.cs @@ -1,5 +1,6 @@ using System; using Fitness.Services; +using Fitness.Views; using Tizen.NUI; using Tizen.NUI.BaseComponents; @@ -15,30 +16,7 @@ namespace Fitness public void Initialize() { - Window.Instance.KeyEvent += OnKeyEvent; - - TextLabel text = new TextLabel("Hello Tizen NUI World"); - text.HorizontalAlignment = HorizontalAlignment.Center; - text.VerticalAlignment = VerticalAlignment.Center; - text.TextColor = Color.Blue; - text.PointSize = 12.0f; - text.HeightResizePolicy = ResizePolicyType.FillToParent; - text.WidthResizePolicy = ResizePolicyType.FillToParent; - Window.Instance.GetDefaultLayer().Add(text); - - Animation animation = new Animation(2000); - animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(180.0f)), PositionAxis.X), 0, 500); - animation.AnimateTo(text, "Orientation", new Rotation(new Radian(new Degree(0.0f)), PositionAxis.X), 500, 1000); - animation.Looping = true; - animation.Play(); - } - - public void OnKeyEvent(object sender, Window.KeyEventArgs e) - { - if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape")) - { - Exit(); - } + Window.Instance.GetDefaultLayer().Add(new MainView()); } protected override void OnCreate() diff --git a/Fitness/ViewModels/BaseViewModel.cs b/Fitness/ViewModels/BaseViewModel.cs new file mode 100644 index 0000000..1c45321 --- /dev/null +++ b/Fitness/ViewModels/BaseViewModel.cs @@ -0,0 +1,21 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Fitness.ViewModels +{ + /// + /// Common Base class for all ViewModels + /// + public abstract class BaseViewModel : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Raises PropertyChanged event + /// + protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/Fitness/ViewModels/MainViewModel.cs b/Fitness/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..65c48c8 --- /dev/null +++ b/Fitness/ViewModels/MainViewModel.cs @@ -0,0 +1,28 @@ +using System; + +namespace Fitness.ViewModels +{ + public class MainViewModel : BaseViewModel + { + private string text; + + public MainViewModel() + { + Text = "Fitness App"; + } + + public string Text + { + get + { + return text; + } + + set + { + text = value; + RaisePropertyChanged(); + } + } + } +} diff --git a/Fitness/Views/MainView.xaml.cs b/Fitness/Views/MainView.xaml.cs new file mode 100644 index 0000000..ffd5a79 --- /dev/null +++ b/Fitness/Views/MainView.xaml.cs @@ -0,0 +1,12 @@ +using Tizen.NUI.BaseComponents; + +namespace Fitness.Views +{ + public partial class MainView : View + { + public MainView() + { + InitializeComponent(); + } + } +} diff --git a/Fitness/res/layout/1280x720/MainView.xaml b/Fitness/res/layout/1280x720/MainView.xaml new file mode 100644 index 0000000..ceedc22 --- /dev/null +++ b/Fitness/res/layout/1280x720/MainView.xaml @@ -0,0 +1,14 @@ + + + + + + + + + +