@@ -170,7 +170,9 @@ public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IUIFactory f
170170
171171 uiStateMachine = new StateMachineType ( UIViewType . None ) ;
172172 triggers = new Dictionary < Trigger , StateMachineType . TriggerWithParameters < ViewWithData > > ( ) ;
173+
173174 ConfigureUIHandlingStates ( ) ;
175+
174176 }
175177
176178 public IObservable < LoadData > SelectFlow ( UIControllerFlow choice )
@@ -257,12 +259,12 @@ public void Start([AllowNull] IConnection conn)
257259
258260 public void Jump ( ViewWithData where )
259261 {
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 )
262264 return ;
263265
264266 requestedTarget = where ;
265- if ( activeFlow == where . Flow )
267+ if ( activeFlow == where . ActiveFlow )
266268 Fire ( Trigger . Next , where ) ;
267269 }
268270
@@ -295,8 +297,7 @@ void ConfigureUIHandlingStates()
295297 . OnEntry ( tr => stopping = false )
296298 . PermitDynamic ( Trigger . Next , ( ) =>
297299 {
298- var loggedIn = connection != null && hosts . LookupHost ( connection . HostAddress ) . IsLoggedIn ;
299- activeFlow = loggedIn ? mainFlow : UIControllerFlow . Authentication ;
300+ activeFlow = SelectActiveFlow ( ) ;
300301 return Go ( Trigger . Next ) ;
301302 } )
302303 . PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
@@ -352,6 +353,18 @@ void ConfigureUIHandlingStates()
352353 . PermitDynamic ( Trigger . Cancel , ( ) => Go ( Trigger . Cancel ) )
353354 . PermitDynamic ( Trigger . Finish , ( ) => Go ( Trigger . Finish ) ) ;
354355
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+
355368 uiStateMachine . Configure ( UIViewType . End )
356369 . OnEntryFrom ( Trigger . Cancel , ( ) => End ( false ) )
357370 . OnEntryFrom ( Trigger . Next , ( ) => End ( true ) )
@@ -518,6 +531,43 @@ void ConfigureLogicStates()
518531 logic . Configure ( UIViewType . End )
519532 . Permit ( Trigger . Next , UIViewType . None ) ;
520533 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 ;
521571 }
522572
523573 static LoadDirection CalculateDirection ( StateMachineType . Transition tr )
@@ -580,12 +630,14 @@ void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = nu
580630 requestedTarget = null ;
581631 }
582632
633+ if ( arg == null )
634+ arg = new ViewWithData { ActiveFlow = activeFlow , MainFlow = mainFlow , ViewType = viewType } ;
583635 bool firstTime = CreateViewAndViewModel ( viewType , arg ) ;
584636 var view = GetObjectsForFlow ( activeFlow ) [ viewType ] . View ;
585637 transition . OnNext ( new LoadData
586638 {
587639 View = view ,
588- Data = arg ?? new ViewWithData { Flow = activeFlow , ViewType = viewType } ,
640+ Data = arg ,
589641 Direction = direction
590642 } ) ;
591643
@@ -660,7 +712,7 @@ void SetupView(UIViewType viewType, IView view)
660712 /// </summary>
661713 /// <param name="viewType"></param>
662714 /// <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 )
664716 {
665717 var list = GetObjectsForFlow ( activeFlow ) ;
666718 if ( viewType == UIViewType . Login )
0 commit comments