@@ -170,7 +170,9 @@ public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IUIFactory f
170
170
171
171
uiStateMachine = new StateMachineType ( UIViewType . None ) ;
172
172
triggers = new Dictionary < Trigger , StateMachineType . TriggerWithParameters < ViewWithData > > ( ) ;
173
+
173
174
ConfigureUIHandlingStates ( ) ;
175
+
174
176
}
175
177
176
178
public IObservable < LoadData > SelectFlow ( UIControllerFlow choice )
@@ -257,12 +259,12 @@ public void Start([AllowNull] IConnection conn)
257
259
258
260
public void Jump ( ViewWithData where )
259
261
{
260
- Debug . Assert ( where . Flow == mainFlow , "Jump called for flow " + where . Flow + " but this is " + mainFlow ) ;
261
- if ( where . Flow != mainFlow )
262
+ Debug . Assert ( where . ActiveFlow == mainFlow , "Jump called for flow " + where . ActiveFlow + " but this is " + mainFlow ) ;
263
+ if ( where . ActiveFlow != mainFlow )
262
264
return ;
263
265
264
266
requestedTarget = where ;
265
- if ( activeFlow == where . Flow )
267
+ if ( activeFlow == where . ActiveFlow )
266
268
Fire ( Trigger . Next , where ) ;
267
269
}
268
270
@@ -295,8 +297,7 @@ void ConfigureUIHandlingStates()
295
297
. OnEntry ( tr => stopping = false )
296
298
. PermitDynamic ( Trigger . Next , ( ) =>
297
299
{
298
- var loggedIn = connection != null && hosts . LookupHost ( connection . HostAddress ) . IsLoggedIn ;
299
- activeFlow = loggedIn ? mainFlow : UIControllerFlow . Authentication ;
300
+ activeFlow = SelectActiveFlow ( ) ;
300
301
return Go ( Trigger . Next ) ;
301
302
} )
302
303
. PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
@@ -352,6 +353,18 @@ void ConfigureUIHandlingStates()
352
353
. PermitDynamic ( Trigger . Cancel , ( ) => Go ( Trigger . Cancel ) )
353
354
. PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
354
355
356
+ uiStateMachine . Configure ( UIViewType . Gist )
357
+ . OnEntry ( tr => RunView ( UIViewType . Gist , CalculateDirection ( tr ) ) )
358
+ . PermitDynamic ( Trigger . Next , ( ) => Go ( Trigger . Next ) )
359
+ . PermitDynamic ( Trigger . Cancel , ( ) => Go ( Trigger . Cancel ) )
360
+ . PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
361
+
362
+ uiStateMachine . Configure ( UIViewType . LogoutRequired )
363
+ . OnEntry ( tr => RunView ( UIViewType . LogoutRequired , CalculateDirection ( tr ) ) )
364
+ . PermitDynamic ( Trigger . Next , ( ) => Go ( Trigger . Next ) )
365
+ . PermitDynamic ( Trigger . Cancel , ( ) => Go ( Trigger . Cancel ) )
366
+ . PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
367
+
355
368
uiStateMachine . Configure ( UIViewType . End )
356
369
. OnEntryFrom ( Trigger . Cancel , ( ) => End ( false ) )
357
370
. OnEntryFrom ( Trigger . Next , ( ) => End ( true ) )
@@ -518,6 +531,43 @@ void ConfigureLogicStates()
518
531
logic . Configure ( UIViewType . End )
519
532
. Permit ( Trigger . Next , UIViewType . None ) ;
520
533
machines . Add ( UIControllerFlow . PullRequests , logic ) ;
534
+
535
+ // gist flow
536
+ logic = new StateMachine < UIViewType , Trigger > ( UIViewType . None ) ;
537
+ logic . Configure ( UIViewType . None )
538
+ . Permit ( Trigger . Next , UIViewType . Gist )
539
+ . Permit ( Trigger . Finish , UIViewType . End ) ;
540
+ logic . Configure ( UIViewType . Gist )
541
+ . Permit ( Trigger . Next , UIViewType . End )
542
+ . Permit ( Trigger . Cancel , UIViewType . End )
543
+ . Permit ( Trigger . Finish , UIViewType . End ) ;
544
+ logic . Configure ( UIViewType . End )
545
+ . Permit ( Trigger . Next , UIViewType . None ) ;
546
+ machines . Add ( UIControllerFlow . Gist , logic ) ;
547
+
548
+ // logout required flow
549
+ logic = new StateMachine < UIViewType , Trigger > ( UIViewType . None ) ;
550
+ logic . Configure ( UIViewType . None )
551
+ . Permit ( Trigger . Next , UIViewType . LogoutRequired )
552
+ . Permit ( Trigger . Finish , UIViewType . End ) ;
553
+ logic . Configure ( UIViewType . LogoutRequired )
554
+ . Permit ( Trigger . Next , UIViewType . End )
555
+ . Permit ( Trigger . Cancel , UIViewType . End )
556
+ . Permit ( Trigger . Finish , UIViewType . End ) ;
557
+ logic . Configure ( UIViewType . End )
558
+ . Permit ( Trigger . Next , UIViewType . None ) ;
559
+ machines . Add ( UIControllerFlow . LogoutRequired , logic ) ;
560
+ }
561
+
562
+ UIControllerFlow SelectActiveFlow ( )
563
+ {
564
+ var host = connection != null ? hosts . LookupHost ( connection . HostAddress ) : null ;
565
+ var loggedIn = host ? . IsLoggedIn ?? false ;
566
+ if ( ! loggedIn || mainFlow != UIControllerFlow . Gist )
567
+ return loggedIn ? mainFlow : UIControllerFlow . Authentication ;
568
+
569
+ var supportsGist = host ? . SupportsGist ?? false ;
570
+ return supportsGist ? mainFlow : UIControllerFlow . LogoutRequired ;
521
571
}
522
572
523
573
static LoadDirection CalculateDirection ( StateMachineType . Transition tr )
@@ -580,12 +630,14 @@ void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = nu
580
630
requestedTarget = null ;
581
631
}
582
632
633
+ if ( arg == null )
634
+ arg = new ViewWithData { ActiveFlow = activeFlow , MainFlow = mainFlow , ViewType = viewType } ;
583
635
bool firstTime = CreateViewAndViewModel ( viewType , arg ) ;
584
636
var view = GetObjectsForFlow ( activeFlow ) [ viewType ] . View ;
585
637
transition . OnNext ( new LoadData
586
638
{
587
639
View = view ,
588
- Data = arg ?? new ViewWithData { Flow = activeFlow , ViewType = viewType } ,
640
+ Data = arg ,
589
641
Direction = direction
590
642
} ) ;
591
643
@@ -660,7 +712,7 @@ void SetupView(UIViewType viewType, IView view)
660
712
/// </summary>
661
713
/// <param name="viewType"></param>
662
714
/// <returns>true if the View/ViewModel didn't exist and had to be created</returns>
663
- bool CreateViewAndViewModel ( UIViewType viewType , [ AllowNull ] ViewWithData data = null )
715
+ bool CreateViewAndViewModel ( UIViewType viewType , ViewWithData data = null )
664
716
{
665
717
var list = GetObjectsForFlow ( activeFlow ) ;
666
718
if ( viewType == UIViewType . Login )
0 commit comments