Fix navigation issue.
authorLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Tue, 31 Mar 2020 14:51:40 +0000 (16:51 +0200)
committerLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Tue, 31 Mar 2020 14:56:56 +0000 (16:56 +0200)
Remove possibility that step could navigate to Next
step even though the step wasn't the current one.

Oobe/Oobe/Managers/ProcessManager.cs

index 488a162..e17021d 100644 (file)
@@ -17,10 +17,45 @@ namespace Oobe
         private MainView ui;
         private LinkedList<Lazy<ProcessStep>> steps;
         private LinkedListNode<Lazy<ProcessStep>> current;
-        private Lazy<ProcessStep> welcome;
 
         static private string doneFile = Tizen.Applications.CoreUIApplication.Current.DirectoryInfo.Data + "oobe_done";
 
+        private class NavigationController : IProcessNavigation
+        {
+            private ProcessStep step;
+            private ProcessManager manager;
+
+            public NavigationController(ProcessManager manager, ProcessStep step)
+            {
+                this.step = step;
+                this.manager = manager;
+            }
+
+            public void Next()
+            {
+                if (manager.CurrentStep == step)
+                {
+                    manager.Next();
+                }
+            }
+
+            public void Previous()
+            {
+                if (manager.CurrentStep == step)
+                {
+                    manager.Previous();
+                }
+            }
+
+            public void Finish()
+            {
+                if (manager.CurrentStep == step)
+                {
+                    manager.Finish();
+                }
+            }
+        }
+
         public ProcessManager()
         {
             //TODO consider loading this from xaml, xml or something...
@@ -29,20 +64,22 @@ namespace Oobe
                 new Lazy<ProcessStep>(() => new RegionStep()),
                 new Lazy<ProcessStep>(() => new TermsStep()),
                 new Lazy<ProcessStep>(() => new WifiStep()),
+                new Lazy<ProcessStep>(() => new WelcomeStep()),
                 }
             );
-            welcome = new Lazy<ProcessStep>(() => new WelcomeStep());
         }
 
+        public ProcessStep CurrentStep { get => current.Value.Value; }
+
         public void Start()
         {
             ui = new MainView(Window.Instance);
             ui.PaginationVisible = true;
-            ui.PagesCount = steps.Count;
+            ui.PagesCount = steps.Count - 1;
 
             current = steps.First;
             current.Value.Value.Initialize();
-            ui.Push(current.Value.Value.CreateView(this));
+            ui.Push(current.Value.Value.CreateView(new NavigationController(this, current.Value.Value)));
             current.Next?.Value.Value.Initialize();
         }
 
@@ -51,24 +88,17 @@ namespace Oobe
         /// </summary>
         public void Next()
         {
-            // end process if all steps are done
+            // do not show pagination on last page
             if (current.Next == null)
             {
-                ShowWelcomeScreen();
-                return;
+                ui.PaginationVisible = false;
             }
 
             current = current.Next;
-            ui.Push(current.Value.Value.CreateView(this));
+            ui.Push(current.Value.Value.CreateView(new NavigationController(this, current.Value.Value)));
             current.Next?.Value.Value.Initialize();
         }
 
-        private void ShowWelcomeScreen()
-        {
-            ui.PaginationVisible = false;
-            ui.Push(welcome.Value.CreateView(this));
-        }
-
         /// <summary>
         /// Finishes process and exits application
         /// </summary>