This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StartupTaskBuilder | |
{ | |
... | |
private class StartupTaskSequencer : IStartupTaskSequencer | |
{ | |
public StartupTaskSequencer(Queue<IStartupTask> tasks) => _tasks = tasks; | |
public async Task StartAsync(IStartupTask task) | |
{ | |
foreach (var next in _tasks.SkipWhile(x => x != task)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IStartupTaskSequencer | |
{ | |
Task StartAsync(); | |
Task StartAsync(IStartupTask task); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class SplashPage : ContentPage | |
{ | |
IStartupTaskSequencer sequencer; | |
public SplashPage() | |
{ | |
InitializeComponent(); | |
sequencer = new StartupTaskBuilder() | |
.Add(new SimulateDownloadDataStartupTask()) | |
.Add(new UpdateVersionStartupTask()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StartupTaskBuilder | |
{ | |
public StartupTaskBuilder() => _tasks = new Queue<IStartupTask>(); | |
public StartupTaskBuilder Add(IStartupTask task) | |
{ | |
QueueTask(task); | |
return this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IStartupTaskSequencer | |
{ | |
Task StartAsync(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class StartupPage : ContentPage, IStartupTask | |
{ | |
protected virtual Task<bool> CanRunAsync() => Task.FromResult(true); | |
protected async Task CompleteAsync() | |
{ | |
await Navigation.PopModalAsync(false); | |
_tcs?.SetResult(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class OnboardingPage : StartupPage | |
{ | |
public ICommand NextCommand { get; } | |
public OnboardingPage() | |
{ | |
InitializeComponent(); | |
NextCommand = new Command(async() => | |
{ | |
await CompleteAsync(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<ContentPage | |
xmlns="http://xamarin.com/schemas/2014/forms" | |
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | |
x:Class="StartupTaskSequenceSample.Views.SplashPage" | |
BackgroundColor="{StaticResource AppPrimaryColor}"> | |
<ContentPage.Content> | |
<StackLayout VerticalOptions="CenterAndExpand" | |
Spacing="30"> | |
<Label Text="♜" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UpdateVersionStartupTask : IStartupTask | |
{ | |
public Task<bool> CanRunAsync() => Task.FromResult(true); | |
public Task RunAsync() | |
{ | |
//TODO: Do Store version code here, can't do it since this app is not in the store | |
return App.Current.MainPage.DisplayAlert("New Version", "There is a new version of this app available. Would you like to update now?", "Yes", "No"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimulateDownloadDataStartupTask : IStartupTask | |
{ | |
public Task<bool> CanRunAsync() => Task.FromResult(true); | |
public Task RunAsync() => Task.Delay(5000); | |
} |