From 2ea8b105d51a42491b7663c2f5b6c01d6a467843 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 5 Dec 2020 20:42:07 +0100 Subject: [PATCH] Apply review suggestions --- osu.Android/OsuGameActivity.cs | 11 ++++------- osu.Android/OsuGameAndroid.cs | 9 +++++++++ osu.Game/OsuGame.cs | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/osu.Android/OsuGameActivity.cs b/osu.Android/OsuGameActivity.cs index b331f3d734..a56206c969 100644 --- a/osu.Android/OsuGameActivity.cs +++ b/osu.Android/OsuGameActivity.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; @@ -38,10 +37,9 @@ namespace osu.Android protected override void OnNewIntent(Intent intent) { - if (intent.Action == Intent.ActionDefault) + if (intent.Action == Intent.ActionDefault && intent.Scheme == ContentResolver.SchemeContent) { - if (intent.Scheme == ContentResolver.SchemeContent) - handleImportFromUri(intent.Data); + handleImportFromUri(intent.Data); } if (intent.Action == Intent.ActionSend) @@ -53,14 +51,13 @@ namespace osu.Android private void handleImportFromUri(Uri uri) { - var cursor = ContentResolver.Query(uri, null, null, null); + var cursor = ContentResolver.Query(uri, new[] { OpenableColumns.DisplayName }, null, null); var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName); cursor.MoveToFirst(); var stream = ContentResolver.OpenInputStream(uri); if (stream != null) - // intent handler may run before the game has even loaded so we need to wait for the file importers to load before launching import - game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column)))); + game.ScheduleImport(stream, cursor.GetString(filename_column)); } } } diff --git a/osu.Android/OsuGameAndroid.cs b/osu.Android/OsuGameAndroid.cs index 21d6336b2c..81945ee083 100644 --- a/osu.Android/OsuGameAndroid.cs +++ b/osu.Android/OsuGameAndroid.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.IO; +using System.Threading.Tasks; using Android.App; using Android.OS; using osu.Framework.Allocation; @@ -65,6 +67,13 @@ namespace osu.Android } } + /// + /// Schedules a file to be imported once the game is loaded. + /// + /// A stream to the file to import. + /// The filename of the file to import. + public void ScheduleImport(Stream stream, string filename) => WaitForReady(() => this, _ => Task.Run(() => Import(stream, filename))); + protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 5b6b90fba5..2c1db67d24 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -483,7 +483,7 @@ namespace osu.Game /// A function to retrieve a (potentially not-yet-constructed) target instance. /// The action to perform on the instance when load is confirmed. /// The type of the target instance. - public void WaitForReady(Func retrieveInstance, Action action) + protected void WaitForReady(Func retrieveInstance, Action action) where T : Drawable { var instance = retrieveInstance();