diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index 1627789..b6cbac9 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading.Tasks; using Float.Core.UI; using Float.Core.UX; using Float.FileDownloader; @@ -110,7 +111,7 @@ public override void Start() } else { - Device.BeginInvokeOnMainThread(() => + Device.BeginInvokeOnMainThread(async () => { try { @@ -127,8 +128,7 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; - - NavigationContext.PresentPage(CreateDownloadStatusPage(downloadStatus)); + await ShowDownloadStatus(CreateDownloadStatusPage(downloadStatus)); }); } } @@ -138,7 +138,31 @@ public override void Start() /// /// The download status page. /// Download status. - protected abstract BaseContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus); + protected abstract ContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus); + + /// + /// Shows the download status page. + /// + /// The download status page. + /// A representing the asynchronous operation. + protected virtual async Task ShowDownloadStatus(ContentPage downloadStatusPage) + { + if (downloadStatusPage is null) + { + throw new ArgumentNullException(nameof(downloadStatusPage)); + } + + await NavigationContext.PresentPageAsync(downloadStatusPage); + } + + /// + /// Dismisses the download status page. + /// + /// A representing the asynchronous operation. + protected virtual async Task DismissDownloadStatus() + { + await NavigationContext.PopPageAsync(); + } /// /// Creates the activity complete page. @@ -341,8 +365,7 @@ protected virtual async void HandleDownloadCompleted(object sender, EventArgs ar startLocation = Activity.MetaData.StartLocation; isCreatingRunner = true; - - await NavigationContext.DismissPageAsync(); + await DismissDownloadStatus(); CreateRunnerAndHandleErrors(); @@ -360,7 +383,7 @@ protected virtual async void HandleDownloadCompleted(object sender, EventArgs ar /// /// The sending object. /// Arguments related to the event. - protected virtual void HandleDownloadCancelled(object sender, EventArgs args) + protected virtual async void HandleDownloadCancelled(object sender, EventArgs args) { if (downloadStatus != null) { @@ -368,7 +391,8 @@ protected virtual void HandleDownloadCancelled(object sender, EventArgs args) downloadStatus.DownloadsCancelled -= HandleDownloadCancelled; } - NavigationContext.DismissPage(); + await DismissDownloadStatus(); + downloadStatus = null; }