Skip to content

Instantly share code, notes, and snippets.

View rdelrosario's full-sized avatar

Rendy Del Rosario rdelrosario

View GitHub Profile
@rdelrosario
rdelrosario / StartupTaskSequencer.cs
Created May 10, 2022 21:03
StartupTaskSequencer.cs
private class StartupTaskSequencer : IStartupTaskSequencer
{
public StartupTaskSequencer(Queue<IStartupTask> tasks) => _tasks = tasks;
public async Task StartAsync(IStartupTask task, IStartupTaskParameters parameters = null)
{
parameters ??= StartupTaskParameters.None;
foreach (var next in _tasks.SkipWhile(x => x != task))
{
public abstract class StartupPage : ContentPage, IStartupTask
{
...
async Task<IStartupTaskParameters> IStartupTask.RunAsync(IStartupTaskParameters parameters)
{
_tcs = new TaskCompletionSource<IStartupTaskParameters>();
await OnStartAsync(parameters);
await App.Current.MainPage.Navigation.PushModalAsync(this);
public interface IStartupTaskSequencer
{
Task StartAsync();
Task StartAsync(IStartupTask task, IStartupTaskParameters parameters = null);
}
public partial class LoginPage : StartupPage
{
public ICommand NextCommand { get; }
public LoginPage() : base()
{
InitializeComponent();
NextCommand = new Command(async() =>
{
await CompleteAsync(new StartupTaskParameters()
public partial class HomePage : TabbedPage, IStartupTask
{
public HomePage()
{
InitializeComponent();
}
public Task<bool> CanRunAsync() => Task.FromResult(true);
public async Task<IStartupTaskParameters> RunAsync(IStartupTaskParameters parameters)
{
public interface IStartupTask
{
Task<bool> CanRunAsync();
Task<IStartupTaskParameters> RunAsync(IStartupTaskParameters parameters);
}
public interface IStartupTaskParameters : IDictionary<string, object>{}
public class StartupTaskParameters : Dictionary<string, object>, IStartupTaskParameters
{
public static IStartupTaskParameters None => _none ??= new StartupTaskParameters();
private static IStartupTaskParameters _none;
}
public partial class AdvertisingPage : StartupPage
{
public AdvertisingPage()
{
InitializeComponent();
}
protected override Task<bool> CanRunAsync() => Task.FromResult(App.VersionType == VersionType.Free);
}
public partial class App : Application
{
public static VersionType VersionType => VersionType.Paid;
public App ()
{
InitializeComponent();
MainPage = new SplashPage();
}
public partial class SplashPage : ContentPage
{
IStartupTaskSequencer sequencer;
HomePage homePage = new HomePage();
public SplashPage()
{
InitializeComponent();
sequencer = new StartupTaskBuilder()