Fix nullability-related warnings in Android project

This commit is contained in:
Bartłomiej Dach 2023-06-24 17:05:52 +02:00
parent e3a89a6273
commit 34e2540331
No known key found for this signature in database
4 changed files with 14 additions and 12 deletions

View File

@ -11,7 +11,7 @@ namespace osu.Android
{
public partial class GameplayScreenRotationLocker : Component
{
private Bindable<bool> localUserPlaying;
private Bindable<bool> localUserPlaying = null!;
[Resolved]
private OsuGameActivity gameActivity { get; set; } = null!;

View File

@ -13,6 +13,7 @@
using Android.OS;
using Android.Views;
using osu.Framework.Android;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Game.Database;
using Debug = System.Diagnostics.Debug;
using Uri = Android.Net.Uri;
@ -49,11 +50,11 @@ public class OsuGameActivity : AndroidGameActivity
/// <remarks>Adjusted on startup to match expected UX for the current device type (phone/tablet).</remarks>
public ScreenOrientation DefaultOrientation = ScreenOrientation.Unspecified;
private OsuGameAndroid game;
private OsuGameAndroid game = null!;
protected override Framework.Game CreateGame() => game = new OsuGameAndroid(this);
protected override void OnCreate(Bundle savedInstanceState)
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
@ -90,15 +91,15 @@ protected override void OnCreate(Bundle savedInstanceState)
Assembly.Load("osu.Game.Rulesets.Mania");
}
protected override void OnNewIntent(Intent intent) => handleIntent(intent);
protected override void OnNewIntent(Intent? intent) => handleIntent(intent);
private void handleIntent(Intent intent)
private void handleIntent(Intent? intent)
{
switch (intent.Action)
switch (intent?.Action)
{
case Intent.ActionDefault:
if (intent.Scheme == ContentResolver.SchemeContent)
handleImportFromUris(intent.Data);
handleImportFromUris(intent.Data.AsNonNull());
else if (osu_url_schemes.Contains(intent.Scheme))
game.HandleLink(intent.DataString);
break;
@ -112,7 +113,7 @@ private void handleIntent(Intent intent)
{
var content = intent.ClipData?.GetItemAt(i);
if (content != null)
uris.Add(content.Uri);
uris.Add(content.Uri.AsNonNull());
}
handleImportFromUris(uris.ToArray());

View File

@ -6,6 +6,7 @@
using Microsoft.Maui.Devices;
using osu.Framework.Allocation;
using osu.Framework.Android.Input;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Input.Handlers;
using osu.Framework.Platform;
using osu.Game;
@ -30,7 +31,7 @@ public override Version AssemblyVersion
{
get
{
var packageInfo = Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0);
var packageInfo = Application.Context.ApplicationContext!.PackageManager!.GetPackageInfo(Application.Context.ApplicationContext.PackageName!, 0).AsNonNull();
try
{
@ -43,7 +44,7 @@ public override Version AssemblyVersion
// Basic conversion format (as done in Fastfile): 2020.606.0 -> 202006060
// https://stackoverflow.com/questions/52977079/android-sdk-28-versioncode-in-packageinfo-has-been-deprecated
string versionName = string.Empty;
string versionName;
if (OperatingSystem.IsAndroidVersionAtLeast(28))
{
@ -66,7 +67,7 @@ public override Version AssemblyVersion
{
}
return new Version(packageInfo.VersionName);
return new Version(packageInfo.VersionName.AsNonNull());
}
}

View File

@ -13,7 +13,7 @@ public class MainActivity : AndroidGameActivity
{
protected override Framework.Game CreateGame() => new OsuTestBrowser();
protected override void OnCreate(Bundle savedInstanceState)
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);