mirror of
https://github.com/osukey/osukey.git
synced 2025-04-29 10:47:22 +09:00
Refactor PowerStatus (now called BatteryInfo)
This commit is contained in:
parent
b7e16c2fcc
commit
43b97fe0ad
@ -75,12 +75,10 @@ namespace osu.Android
|
|||||||
|
|
||||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
||||||
|
|
||||||
protected override PowerStatus CreatePowerStatus() => new AndroidPowerStatus();
|
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
||||||
|
|
||||||
private class AndroidPowerStatus : PowerStatus
|
private class AndroidBatteryInfo : BatteryInfo
|
||||||
{
|
{
|
||||||
public override double BatteryCutoff => 0.20;
|
|
||||||
|
|
||||||
public override double ChargeLevel => Battery.ChargeLevel;
|
public override double ChargeLevel => Battery.ChargeLevel;
|
||||||
|
|
||||||
public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
||||||
|
@ -64,7 +64,6 @@
|
|||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Used for obtaining battery info. -->
|
|
||||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||||
|
@ -49,8 +49,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
[Cached]
|
[Cached]
|
||||||
private readonly VolumeOverlay volumeOverlay;
|
private readonly VolumeOverlay volumeOverlay;
|
||||||
|
|
||||||
[Cached(typeof(PowerStatus))]
|
[Cached(typeof(BatteryInfo))]
|
||||||
private readonly LocalPowerStatus powerStatus = new LocalPowerStatus();
|
private readonly LocalBatteryInfo batteryInfo = new LocalBatteryInfo();
|
||||||
|
|
||||||
private readonly ChangelogOverlay changelogOverlay;
|
private readonly ChangelogOverlay changelogOverlay;
|
||||||
|
|
||||||
@ -302,8 +302,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
// set charge status and level
|
// set charge status and level
|
||||||
AddStep("load player", () => resetPlayer(false, () =>
|
AddStep("load player", () => resetPlayer(false, () =>
|
||||||
{
|
{
|
||||||
powerStatus.SetCharging(isCharging);
|
batteryInfo.SetCharging(isCharging);
|
||||||
powerStatus.SetChargeLevel(chargeLevel);
|
batteryInfo.SetChargeLevel(chargeLevel);
|
||||||
}));
|
}));
|
||||||
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
||||||
AddAssert($"notification {(shouldWarn ? "triggered" : "not triggered")}", () => notificationOverlay.UnreadCount.Value == (shouldWarn ? 1 : 0));
|
AddAssert($"notification {(shouldWarn ? "triggered" : "not triggered")}", () => notificationOverlay.UnreadCount.Value == (shouldWarn ? 1 : 0));
|
||||||
@ -381,16 +381,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mutable dummy PowerStatus class for <see cref="TestScenePlayerLoader.TestLowBatteryNotification"/>
|
/// Mutable dummy BatteryInfo class for <see cref="TestScenePlayerLoader.TestLowBatteryNotification"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
private class LocalPowerStatus : PowerStatus
|
private class LocalBatteryInfo : BatteryInfo
|
||||||
{
|
{
|
||||||
private bool isCharging = true;
|
private bool isCharging = true;
|
||||||
private double chargeLevel = 1;
|
private double chargeLevel = 1;
|
||||||
|
|
||||||
public override double BatteryCutoff => 0.2;
|
|
||||||
|
|
||||||
public override bool IsCharging => isCharging;
|
public override bool IsCharging => isCharging;
|
||||||
|
|
||||||
public override double ChargeLevel => chargeLevel;
|
public override double ChargeLevel => chargeLevel;
|
||||||
|
@ -157,7 +157,7 @@ namespace osu.Game
|
|||||||
|
|
||||||
protected override UserInputManager CreateUserInputManager() => new OsuUserInputManager();
|
protected override UserInputManager CreateUserInputManager() => new OsuUserInputManager();
|
||||||
|
|
||||||
protected virtual PowerStatus CreatePowerStatus() => null;
|
protected virtual BatteryInfo CreateBatteryInfo() => null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum volume at which audio tracks should playback. This can be set lower than 1 to create some head-room for sound effects.
|
/// The maximum volume at which audio tracks should playback. This can be set lower than 1 to create some head-room for sound effects.
|
||||||
@ -285,7 +285,7 @@ namespace osu.Game
|
|||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||||
|
|
||||||
var powerStatus = CreatePowerStatus();
|
var powerStatus = CreateBatteryInfo();
|
||||||
if (powerStatus != null)
|
if (powerStatus != null)
|
||||||
dependencies.CacheAs(powerStatus);
|
dependencies.CacheAs(powerStatus);
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ namespace osu.Game.Screens.Play
|
|||||||
private AudioManager audioManager { get; set; }
|
private AudioManager audioManager { get; set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private PowerStatus powerStatus { get; set; }
|
private BatteryInfo batteryInfo { get; set; }
|
||||||
|
|
||||||
public PlayerLoader(Func<Player> createPlayer)
|
public PlayerLoader(Func<Player> createPlayer)
|
||||||
{
|
{
|
||||||
@ -483,11 +483,11 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
private void showBatteryWarningIfNeeded()
|
private void showBatteryWarningIfNeeded()
|
||||||
{
|
{
|
||||||
if (powerStatus == null) return;
|
if (batteryInfo == null) return;
|
||||||
|
|
||||||
if (!batteryWarningShownOnce.Value)
|
if (!batteryWarningShownOnce.Value)
|
||||||
{
|
{
|
||||||
if (powerStatus.IsLowBattery)
|
if (batteryInfo.IsLowBattery)
|
||||||
{
|
{
|
||||||
notificationOverlay?.Post(new BatteryWarningNotification());
|
notificationOverlay?.Post(new BatteryWarningNotification());
|
||||||
batteryWarningShownOnce.Value = true;
|
batteryWarningShownOnce.Value = true;
|
||||||
|
@ -5,15 +5,9 @@ namespace osu.Game.Utils
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to the system's power status.
|
/// Provides access to the system's power status.
|
||||||
/// Currently implemented on iOS and Android only.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class PowerStatus
|
public abstract class BatteryInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// The maximum battery level considered as low, from 0 to 1.
|
|
||||||
/// </summary>
|
|
||||||
public abstract double BatteryCutoff { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The charge level of the battery, from 0 to 1.
|
/// The charge level of the battery, from 0 to 1.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -23,8 +17,8 @@ namespace osu.Game.Utils
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the battery is currently low in charge.
|
/// Whether the battery is currently low in charge.
|
||||||
/// Returns true if not charging and current charge level is lower than or equal to <see cref="BatteryCutoff"/>.
|
/// Returns true if not charging and current charge level is lower than or equal to 25%.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsLowBattery => !IsCharging && ChargeLevel <= BatteryCutoff;
|
public bool IsLowBattery => !IsCharging && ChargeLevel <= 0.25;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,12 +16,10 @@ namespace osu.iOS
|
|||||||
|
|
||||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
||||||
|
|
||||||
protected override PowerStatus CreatePowerStatus() => new IOSPowerStatus();
|
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
|
||||||
|
|
||||||
private class IOSPowerStatus : PowerStatus
|
private class IOSBatteryInfo : BatteryInfo
|
||||||
{
|
{
|
||||||
public override double BatteryCutoff => 0.25;
|
|
||||||
|
|
||||||
public override double ChargeLevel => Battery.ChargeLevel;
|
public override double ChargeLevel => Battery.ChargeLevel;
|
||||||
|
|
||||||
public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
public override bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
||||||
|
@ -117,7 +117,6 @@
|
|||||||
</ImageAsset>
|
</ImageAsset>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<!-- Used for obtaining battery info. -->
|
|
||||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user