mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Apply review suggestions
This commit is contained in:
parent
0266410368
commit
2ea8b105d5
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.Content;
|
using Android.Content;
|
||||||
using Android.Content.PM;
|
using Android.Content.PM;
|
||||||
@ -38,10 +37,9 @@ namespace osu.Android
|
|||||||
|
|
||||||
protected override void OnNewIntent(Intent intent)
|
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)
|
if (intent.Action == Intent.ActionSend)
|
||||||
@ -53,14 +51,13 @@ namespace osu.Android
|
|||||||
|
|
||||||
private void handleImportFromUri(Uri uri)
|
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);
|
var filename_column = cursor.GetColumnIndex(OpenableColumns.DisplayName);
|
||||||
cursor.MoveToFirst();
|
cursor.MoveToFirst();
|
||||||
|
|
||||||
var stream = ContentResolver.OpenInputStream(uri);
|
var stream = ContentResolver.OpenInputStream(uri);
|
||||||
if (stream != null)
|
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.ScheduleImport(stream, cursor.GetString(filename_column));
|
||||||
game.WaitForReady(() => game, _ => Task.Run(() => game.Import(stream, cursor.GetString(filename_column))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Android.App;
|
using Android.App;
|
||||||
using Android.OS;
|
using Android.OS;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -65,6 +67,13 @@ namespace osu.Android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Schedules a file to be imported once the game is loaded.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">A stream to the file to import.</param>
|
||||||
|
/// <param name="filename">The filename of the file to import.</param>
|
||||||
|
public void ScheduleImport(Stream stream, string filename) => WaitForReady(() => this, _ => Task.Run(() => Import(stream, filename)));
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
@ -483,7 +483,7 @@ namespace osu.Game
|
|||||||
/// <param name="retrieveInstance">A function to retrieve a (potentially not-yet-constructed) target instance.</param>
|
/// <param name="retrieveInstance">A function to retrieve a (potentially not-yet-constructed) target instance.</param>
|
||||||
/// <param name="action">The action to perform on the instance when load is confirmed.</param>
|
/// <param name="action">The action to perform on the instance when load is confirmed.</param>
|
||||||
/// <typeparam name="T">The type of the target instance.</typeparam>
|
/// <typeparam name="T">The type of the target instance.</typeparam>
|
||||||
public void WaitForReady<T>(Func<T> retrieveInstance, Action<T> action)
|
protected void WaitForReady<T>(Func<T> retrieveInstance, Action<T> action)
|
||||||
where T : Drawable
|
where T : Drawable
|
||||||
{
|
{
|
||||||
var instance = retrieveInstance();
|
var instance = retrieveInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user