From d8509e938bade736cbf48cd3b9010bc60c858068 Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Thu, 21 Jul 2022 12:06:44 -0500 Subject: [PATCH 1/5] Allow a popup page as the download page --- .../ActivityLaunchCoordinator.cs | 54 +++++++++++++++++-- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index 1627789..d6f03c2 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -9,6 +9,9 @@ using Float.TinCan.LocalLRSServer; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Rg.Plugins.Popup.Extensions; +using Rg.Plugins.Popup.Pages; +using Rg.Plugins.Popup.Services; using TinCan; using Xamarin.Forms; @@ -30,6 +33,7 @@ public abstract class ActivityLaunchCoordinator : Coordinator string startLocation; DownloadStatus downloadStatus; bool isCreatingRunner; + PopupPage downloadPopupPage; /// /// Initializes a new instance of the class. @@ -128,7 +132,19 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; - NavigationContext.PresentPage(CreateDownloadStatusPage(downloadStatus)); + if (CreateDownloadStatusPopupPage(downloadStatus) is PopupPage popupPage) + { + downloadPopupPage = popupPage; + PopupNavigation.Instance.PushAsync(downloadPopupPage, true); + } + else if (CreateDownloadStatusPage(downloadStatus) is BaseContentPage page) + { + NavigationContext.PresentPage(page); + } + else + { + throw new MissingMethodException("One of CreateDownloadStatusPopupPage or CreateDownloadStatusPage must be implemented."); + } }); } } @@ -138,7 +154,20 @@ public override void Start() /// /// The download status page. /// Download status. - protected abstract BaseContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus); + protected virtual BaseContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus) + { + return null; + } + + /// + /// Creates the download status popup page. + /// + /// The download status popup page. + /// Download status. + protected virtual PopupPage CreateDownloadStatusPopupPage(DownloadStatus downloadStatus) + { + return null; + } /// /// Creates the activity complete page. @@ -342,7 +371,15 @@ protected virtual async void HandleDownloadCompleted(object sender, EventArgs ar startLocation = Activity.MetaData.StartLocation; isCreatingRunner = true; - await NavigationContext.DismissPageAsync(); + if (downloadPopupPage != null) + { + await PopupNavigation.Instance.RemovePageAsync(downloadPopupPage, true); + downloadPopupPage = null; + } + else + { + await NavigationContext.PopPageAsync(); + } CreateRunnerAndHandleErrors(); @@ -368,7 +405,16 @@ protected virtual void HandleDownloadCancelled(object sender, EventArgs args) downloadStatus.DownloadsCancelled -= HandleDownloadCancelled; } - NavigationContext.DismissPage(); + if (downloadPopupPage != null) + { + PopupNavigation.Instance.RemovePageAsync(downloadPopupPage, true); + downloadPopupPage = null; + } + else + { + NavigationContext.PopPageAsync(); + } + downloadStatus = null; } From ad59b308a2022ddd8efe4f2bd38ef4d89f82f1b5 Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Thu, 21 Jul 2022 14:54:04 -0500 Subject: [PATCH 2/5] Adjustments based on Dan's comments --- .../ActivityLaunchCoordinator.cs | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index d6f03c2..ae80f18 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -108,7 +108,7 @@ public override void Start() var fileLocation = Path.Combine(FileStorage.PackagedContentDirectory, startPath); - if (DownloadChecker.IsActivityDownloaded(fileLocation)) + if (DownloadChecker.IsActivityDownloaded(fileLocation) && false) { CreateRunnerAndHandleErrors(); } @@ -132,18 +132,15 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; - if (CreateDownloadStatusPopupPage(downloadStatus) is PopupPage popupPage) + var statusPage = CreateDownloadStatusPage(downloadStatus); + if (statusPage is PopupPage popupPage) { downloadPopupPage = popupPage; PopupNavigation.Instance.PushAsync(downloadPopupPage, true); } - else if (CreateDownloadStatusPage(downloadStatus) is BaseContentPage page) - { - NavigationContext.PresentPage(page); - } else { - throw new MissingMethodException("One of CreateDownloadStatusPopupPage or CreateDownloadStatusPage must be implemented."); + NavigationContext.PresentPage(statusPage); } }); } @@ -154,20 +151,7 @@ public override void Start() /// /// The download status page. /// Download status. - protected virtual BaseContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus) - { - return null; - } - - /// - /// Creates the download status popup page. - /// - /// The download status popup page. - /// Download status. - protected virtual PopupPage CreateDownloadStatusPopupPage(DownloadStatus downloadStatus) - { - return null; - } + protected abstract ContentPage CreateDownloadStatusPage(DownloadStatus downloadStatus); /// /// Creates the activity complete page. From ff14b14590b8efeacec01e1b10bd20f65458f91d Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Thu, 21 Jul 2022 14:56:28 -0500 Subject: [PATCH 3/5] Will not want this... --- Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index ae80f18..273866d 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -108,7 +108,7 @@ public override void Start() var fileLocation = Path.Combine(FileStorage.PackagedContentDirectory, startPath); - if (DownloadChecker.IsActivityDownloaded(fileLocation) && false) + if (DownloadChecker.IsActivityDownloaded(fileLocation)) { CreateRunnerAndHandleErrors(); } From 60fa0ace1f0f80c1c1da3510d6fcece5b14bc458 Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Fri, 22 Jul 2022 11:58:05 -0500 Subject: [PATCH 4/5] More based on Dan's suggestions --- .../ActivityLaunchCoordinator.cs | 64 +++++++++---------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index 273866d..b2d40db 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; @@ -9,9 +10,6 @@ using Float.TinCan.LocalLRSServer; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using Rg.Plugins.Popup.Extensions; -using Rg.Plugins.Popup.Pages; -using Rg.Plugins.Popup.Services; using TinCan; using Xamarin.Forms; @@ -33,7 +31,6 @@ public abstract class ActivityLaunchCoordinator : Coordinator string startLocation; DownloadStatus downloadStatus; bool isCreatingRunner; - PopupPage downloadPopupPage; /// /// Initializes a new instance of the class. @@ -131,17 +128,7 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; - - var statusPage = CreateDownloadStatusPage(downloadStatus); - if (statusPage is PopupPage popupPage) - { - downloadPopupPage = popupPage; - PopupNavigation.Instance.PushAsync(downloadPopupPage, true); - } - else - { - NavigationContext.PresentPage(statusPage); - } + ShowDownloadStatus(CreateDownloadStatusPage(downloadStatus)); }); } } @@ -153,6 +140,30 @@ public override void Start() /// Download status. 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. /// @@ -354,16 +365,7 @@ protected virtual async void HandleDownloadCompleted(object sender, EventArgs ar startLocation = Activity.MetaData.StartLocation; isCreatingRunner = true; - - if (downloadPopupPage != null) - { - await PopupNavigation.Instance.RemovePageAsync(downloadPopupPage, true); - downloadPopupPage = null; - } - else - { - await NavigationContext.PopPageAsync(); - } + await DismissDownloadStatus(); CreateRunnerAndHandleErrors(); @@ -381,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) { @@ -389,15 +391,7 @@ protected virtual void HandleDownloadCancelled(object sender, EventArgs args) downloadStatus.DownloadsCancelled -= HandleDownloadCancelled; } - if (downloadPopupPage != null) - { - PopupNavigation.Instance.RemovePageAsync(downloadPopupPage, true); - downloadPopupPage = null; - } - else - { - NavigationContext.PopPageAsync(); - } + await DismissDownloadStatus(); downloadStatus = null; } From aa78b15f82fd44687c45cea8ca55f8cb91647417 Mon Sep 17 00:00:00 2001 From: Eric Busch Date: Mon, 25 Jul 2022 10:56:54 -0500 Subject: [PATCH 5/5] Use the async state --- Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs index b2d40db..b6cbac9 100644 --- a/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs +++ b/Float.TinCan.ActivityLibrary/ActivityLaunchCoordinator.cs @@ -111,7 +111,7 @@ public override void Start() } else { - Device.BeginInvokeOnMainThread(() => + Device.BeginInvokeOnMainThread(async () => { try { @@ -128,7 +128,7 @@ public override void Start() downloadStatus.DownloadsCompleted += HandleDownloadCompleted; downloadStatus.DownloadsCancelled += HandleDownloadCancelled; - ShowDownloadStatus(CreateDownloadStatusPage(downloadStatus)); + await ShowDownloadStatus(CreateDownloadStatusPage(downloadStatus)); }); } }