Skip to content

Commit

Permalink
Abstracting Splash to logic class
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrynixon committed Sep 22, 2016
1 parent dfcdfd2 commit e7fc033
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions Template10 (Library)/Common/BootStrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ public INavigationService NavigationServiceFactory(BackButton backButton, Existi
public enum States
{
None,
Splashing,
Running,
BeforeInit,
AfterInit,
Expand Down Expand Up @@ -556,12 +555,12 @@ private async Task InitializeFrameAsync(IActivatedEventArgs e)

DebugWrite($"{nameof(IActivatedEventArgs)}:{e.Kind}");

ShowSplashScreen(e);
CallShowSplashScreen(e);
await CallOnInitializeAsync(true, e);
SetupCustomTitleBar();

// if there's custom content then there's nothing to do
if (CurrentState == States.Splashing)
if (_SplashLogic.Splashing)
{
Window.Current.Content = CreateRootElement(e);
}
Expand All @@ -580,7 +579,7 @@ private async Task InitializeFrameAsync(IActivatedEventArgs e)
WindowLogic _WindowLogic = new WindowLogic();
void CallActivateWindow(WindowLogic.ActivateWindowSources source)
{
_WindowLogic.ActivateWindow(source, CurrentState, SplashScreenPopup);
_WindowLogic.ActivateWindow(source, _SplashLogic);
CurrentState = States.Running;
}

Expand Down Expand Up @@ -659,22 +658,14 @@ private async Task CallOnStartAsync(bool canRepeat, StartKind startKind)
CurrentState = States.AfterStart;
}

internal Popup SplashScreenPopup = null;
private void ShowSplashScreen(IActivatedEventArgs e)
SplashLogic _SplashLogic = new SplashLogic();
private void CallShowSplashScreen(IActivatedEventArgs e)
{
DebugWrite();

if (SplashFactory == null)
return;

CurrentState = States.Splashing;
var splash = SplashFactory(e.SplashScreen);
var service = new PopupService();
SplashScreenPopup = service.Show(PopupService.PopupSize.FullScreen, splash);
CallActivateWindow(WindowLogic.ActivateWindowSources.SplashScreen);
_SplashLogic.Show(e.SplashScreen, SplashFactory, _WindowLogic);
}


[Obsolete("Use RootElementFactory.", true)]
protected virtual Frame CreateRootFrame(IActivatedEventArgs e)
{
Expand Down Expand Up @@ -857,7 +848,7 @@ private async Task SuspendAllFramesAsync()
}
}

public class WindowLogic
private class WindowLogic
{
public enum ActivateWindowSources { Launching, Activating, SplashScreen, Resuming }
/// <summary>
Expand All @@ -866,17 +857,39 @@ public enum ActivateWindowSources { Launching, Activating, SplashScreen, Resumin
/// One scenario might be a delayed activation for Splash Screen.
/// </summary>
/// <param name="source">Reason for the call from Template 10</param>
public void ActivateWindow(ActivateWindowSources source, States state, Popup splashScreenPopup)
public void ActivateWindow(ActivateWindowSources source, SplashLogic splashLogic)
{
DebugWrite($"source:{source}");

if (source != ActivateWindowSources.SplashScreen)
{
splashScreenPopup?.Hide();
splashLogic.Hide();
}

Window.Current.Activate();
}
}

private class SplashLogic
{
private Popup popup;

public void Show(SplashScreen splashScreen, Func<SplashScreen, UserControl> splashFactory, WindowLogic windowLogic)
{
if (splashFactory == null)
return;
var splash = splashFactory(splashScreen);
var service = new PopupService();
popup = service.Show(PopupService.PopupSize.FullScreen, splash);
windowLogic.ActivateWindow(WindowLogic.ActivateWindowSources.SplashScreen, this);
}

public void Hide()
{
popup?.Hide();
}

public bool Splashing => popup?.IsOpen ?? false;
}
}
}

0 comments on commit e7fc033

Please sign in to comment.