[OAPSAN-4414] ProcessManager implementation (#2)
authorLukasz Stanislawski/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <l.stanislaws@samsung.com>
Mon, 9 Mar 2020 13:22:53 +0000 (14:22 +0100)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 9 Mar 2020 13:22:53 +0000 (14:22 +0100)
* ProcessManager implementation

Oobe/Oobe/Managers/ProcessManager.cs [new file with mode: 0644]
Oobe/Oobe/Oobe.cs
Oobe/Oobe/Views/MainView.cs [moved from Oobe/Oobe/Views/OobeViewSwitcher.cs with 97% similarity]
Oobe/OobeCommon/Interfaces/IProcessNavigation.cs
Oobe/OobeCommon/Interfaces/ProcessInfo.cs [deleted file]
Oobe/OobeCommon/Interfaces/ProcessStep.cs
Oobe/OobeLanguage/LanguageStep.cs
Oobe/OobeLanguage/OobeLanguage.csproj
Oobe/OobeRegion/Class1.cs [deleted file]
Oobe/OobeRegion/OobeRegion.csproj
Oobe/OobeRegion/RegionStep.cs [new file with mode: 0644]

diff --git a/Oobe/Oobe/Managers/ProcessManager.cs b/Oobe/Oobe/Managers/ProcessManager.cs
new file mode 100644 (file)
index 0000000..2de00b5
--- /dev/null
@@ -0,0 +1,77 @@
+using System.Collections.Generic;
+using Oobe.Common.Interfaces;
+using Oobe.Language;
+using Oobe.Views;
+using Tizen.NUI;
+using Oobe.Region;
+using System;
+ namespace Oobe
+ {
+     public class ProcessManager : IProcessNavigation
+     {
+        private MainView ui;
+        private LinkedList<Lazy<ProcessStep>> steps;
+        private LinkedListNode<Lazy<ProcessStep>> current;
+
+        public ProcessManager()
+        {
+            //TODO consider loading this from xaml, xml or something...
+            steps = new LinkedList<Lazy<ProcessStep>>(new List<Lazy<ProcessStep>>{
+                new Lazy<ProcessStep>(() => new LanguageStep()),
+                new Lazy<ProcessStep>(() => new RegionStep())}
+            );
+        }
+
+        public void Start()
+        {
+            ui = new MainView(Window.Instance);
+
+            current = steps.First;
+            current.Value.Value.Initialize();
+            ui.Push(current.Value.Value.CreateView(this));
+            current.Next?.Value.Value.Initialize();
+        }
+
+        /// <summary>
+        /// Next shows next view in the process or finish the process
+        /// </summary>
+        public void Next()
+        {
+            // end process if all steps are done
+            if (current.Next == null)
+            {
+                Exit();
+                return;
+            }
+
+            current = current.Next;
+            ui.Push(current.Value.Value.CreateView(this));
+            current.Next?.Value.Value.Initialize();
+        }
+
+        /// <summary>
+        /// Finishes process and exits application
+        /// </summary>
+        public void Exit()
+        {
+            foreach (Lazy<ProcessStep> step in steps)
+            {
+                step.Value.Shutdown();
+            }
+            NUIApplication.Current.Exit();
+        }
+
+        /// <summary>
+        /// Previous shows previous view in the process
+        /// </summary>
+        public void Previous()
+        {
+            if (current.Previous != null)
+            {
+                current = current.Previous;
+                ui.Pop();
+            }
+        }
+    }
+}
index 1c5899d..3fc8495 100644 (file)
@@ -1,15 +1,12 @@
-using System;
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
+using Tizen.NUI;
 using Tizen.NUI.Components;
-using Oobe.Controls;
-using Oobe.Views;
+using System;
 
 namespace Oobe
 {
     class Program : NUIApplication
     {
-        private OobeViewSwitcher switcher;
+        private ProcessManager processManager;
 
         protected override void OnCreate()
         {
@@ -17,69 +14,36 @@ namespace Oobe
             Initialize();
         }
 
-        TextLabel makeLabel(string txt, Color color)
-        {
-            TextLabel text2 = new TextLabel(txt);
-            text2.HorizontalAlignment = HorizontalAlignment.Center;
-            text2.VerticalAlignment = VerticalAlignment.Center;
-            text2.TextColor = Color.Black;
-            text2.PointSize = 12.0f;
-            text2.HeightResizePolicy = ResizePolicyType.FillToParent;
-            text2.WidthResizePolicy = ResizePolicyType.FillToParent;
-
-            return text2;
-        }
-
         void Initialize()
         {
-            Window.Instance.KeyEvent += OnKeyEvent;
-
-            switcher = new OobeViewSwitcher(Window.Instance);
+            processManager = new ProcessManager();
+            processManager.Start();
 
             Button button = new Button();
-            button.Text = "Push";
+            button.Text = "Next";
             button.BackgroundColor = Color.Blue;
             button.Size2D = new Size2D(100, 80);
             button.Position2D.X = 48;
             button.Position2D.Y = 720;
-            button.ClickEvent += PushClicked;
+            button.ClickEvent += NextClicked;
             Window.Instance.GetDefaultLayer().Add(button);
-            
+
             button = new Button();
-            button.Text = "Pop";
+            button.Text = "Previous";
             button.Position2D = new Position2D(250, 720);
             button.BackgroundColor = Color.White;
             button.Size2D = new Size2D(100, 80);
-            button.ClickEvent += PopClicked;
+            button.ClickEvent += PrevClicked;
             Window.Instance.GetDefaultLayer().Add(button);
-
         }
-        int current = 0;
-        public static Color[] PossibleColors = new Color[]{
-            Color.White,
-            Color.White,
-            Color.White
-        };
-
-        public void PushClicked(object sender, EventArgs args)
-        {
-            Tizen.Log.Debug("ViewStack", "Push");
-            TextLabel text = makeLabel("More text", PossibleColors[current++ % PossibleColors.Length]);
-            switcher.Push(text);
-        }
-
-        public void PopClicked(object sender, EventArgs args)
+        public void NextClicked(object sender, EventArgs args)
         {
-            Tizen.Log.Debug("ViewStack", "Pop");
-            switcher.Pop();
+            processManager.Next();
         }
 
-        public void OnKeyEvent(object sender, Window.KeyEventArgs e)
+        public void PrevClicked(object sender, EventArgs args)
         {
-            if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
-            {
-                Exit();
-            }
+            processManager.Previous();
         }
 
         static void Main(string[] args)
similarity index 97%
rename from Oobe/Oobe/Views/OobeViewSwitcher.cs
rename to Oobe/Oobe/Views/MainView.cs
index a9b64c6..70e6f48 100644 (file)
@@ -7,13 +7,13 @@ namespace Oobe.Views
     /// <summary>
     /// Implementation of OOBE GUI Guideline for IoT Headed
     /// </summary>
-    public class OobeViewSwitcher
+    public class MainView
     {
         private ViewStack stack;
         private Animation dimEffectAnimation;
         private const int TransitionTime = 750;
 
-        public OobeViewSwitcher(Window win)
+        public MainView(Window win)
         {
             View backImage = new View();
             backImage.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.svg";
index e37350b..6ebe946 100644 (file)
@@ -4,8 +4,14 @@ namespace Oobe.Common.Interfaces
 {
     public interface IProcessNavigation
     {
+        /// <summary>
+        /// Goto next process step.
+        /// </summary>
         void Next();
+
+        /// <summary>
+        /// Goto previous process step.
+        /// </summary>
         void Previous();
-        ProcessInfo CurrentStep();
     }
 }
\ No newline at end of file
diff --git a/Oobe/OobeCommon/Interfaces/ProcessInfo.cs b/Oobe/OobeCommon/Interfaces/ProcessInfo.cs
deleted file mode 100644 (file)
index 8af119a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-
-
-namespace Oobe.Common.Interfaces
-{
-    public struct ProcessInfo
-    {
-        int CurrentStep;
-        int StepsCount;
-    }
-}
\ No newline at end of file
index 9d9b383..e777611 100644 (file)
@@ -1,25 +1,52 @@
 using System;
 using Tizen.NUI.BaseComponents;
+using Oobe.Common.Interfaces;
 
 namespace Oobe.Common.Interfaces
 {
-    public abstract class ProcessStep
-    {
+     public abstract class ProcessStep
+     {
         protected IProcessNavigation Navigation { get; private set; }
+        private bool initialized;
 
-        protected ProcessStep(IProcessNavigation nav)
+        public void Initialize()
         {
-            Navigation = nav;
+            if (initialized)
+                return;
+
+            this.OnInitialized();
+            initialized = true;
         }
-        public virtual void Initialize()
+
+        public virtual void Shutdown()
         {
+            if (!initialized)
+                return;
+
+            this.OnShutdown();
+            initialized = false;
         }
+
         public virtual void Reset()
         {
+            OnReset();
         }
-        public virtual void Shutdown()
-        {       
+
+        public virtual void OnInitialized()
+        {
+        }
+
+        public virtual void OnShutdown()
+        {
+        }
+
+        public virtual void OnReset()
+        {
+        }
+
+        public virtual View CreateView(IProcessNavigation nav)
+        {
+            return null;
         }
-        public View View => null;
-    }
-}
\ No newline at end of file
+     }
+ }
index a5e8c1e..ddbff3c 100644 (file)
@@ -1,12 +1,27 @@
 using System;\r
 using Oobe.Common.Interfaces;\r
+using Tizen.NUI;\r
+using Tizen.NUI.BaseComponents;\r
 \r
 namespace Oobe.Language\r
 {\r
-    public class LanguageStep : ProcessStep\r
-    {\r
-        public LanguageStep(IProcessNavigation navi) : base(navi)\r
+     public class LanguageStep : ProcessStep\r
+     {\r
+        public LanguageStep() : base()\r
         {\r
+\r
         }\r
-    }\r
-}
\ No newline at end of file
+\r
+        public override View CreateView(IProcessNavigation nav)\r
+        {\r
+            TextLabel text2 = new TextLabel("Choose Language");\r
+            text2.HorizontalAlignment = HorizontalAlignment.Center;\r
+            text2.VerticalAlignment = VerticalAlignment.Center;\r
+            text2.TextColor = Color.Black;\r
+            text2.PointSize = 12.0f;\r
+            text2.HeightResizePolicy = ResizePolicyType.FillToParent;\r
+            text2.WidthResizePolicy = ResizePolicyType.FillToParent;\r
+            return text2;\r
+         }\r
+     }\r
+}\r
index 2b5632b..eb29790 100644 (file)
@@ -12,7 +12,7 @@
     </PackageReference>\r
   </ItemGroup>\r
 \r
-  <ItemGroup>
-    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />
+  <ItemGroup>\r
+    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />\r
   </ItemGroup>\r
 </Project>\r
diff --git a/Oobe/OobeRegion/Class1.cs b/Oobe/OobeRegion/Class1.cs
deleted file mode 100644 (file)
index 8eda6fe..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-using System;\r
-\r
-namespace OobeRegion\r
-{\r
-    public class Class1\r
-    {\r
-    }\r
-}\r
index ed55487..c8c933c 100644 (file)
@@ -11,4 +11,7 @@
       <ExcludeAssets>Runtime</ExcludeAssets>\r
     </PackageReference>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />\r
+  </ItemGroup>\r
 </Project>\r
diff --git a/Oobe/OobeRegion/RegionStep.cs b/Oobe/OobeRegion/RegionStep.cs
new file mode 100644 (file)
index 0000000..a940245
--- /dev/null
@@ -0,0 +1,27 @@
+using System;\r
+using Tizen.NUI;\r
+using Tizen.NUI.BaseComponents;\r
+using Oobe.Common.Interfaces;\r
+\r
+namespace Oobe.Region\r
+{\r
+     public class RegionStep : ProcessStep\r
+     {\r
+        public RegionStep() : base()\r
+        {\r
+\r
+        }\r
+\r
+        public override View CreateView(IProcessNavigation nav)\r
+        {\r
+            TextLabel text2 = new TextLabel("Choose Country");\r
+            text2.HorizontalAlignment = HorizontalAlignment.Center;\r
+            text2.VerticalAlignment = VerticalAlignment.Center;\r
+            text2.TextColor = Color.Black;\r
+            text2.PointSize = 12.0f;\r
+            text2.HeightResizePolicy = ResizePolicyType.FillToParent;\r
+            text2.WidthResizePolicy = ResizePolicyType.FillToParent;\r
+            return text2;\r
+         }\r
+     }\r
+}\r