mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 03:42:57 +08: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 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 bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
||||
|
@ -64,7 +64,6 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- Used for obtaining battery info. -->
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
||||
|
@ -49,8 +49,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[Cached]
|
||||
private readonly VolumeOverlay volumeOverlay;
|
||||
|
||||
[Cached(typeof(PowerStatus))]
|
||||
private readonly LocalPowerStatus powerStatus = new LocalPowerStatus();
|
||||
[Cached(typeof(BatteryInfo))]
|
||||
private readonly LocalBatteryInfo batteryInfo = new LocalBatteryInfo();
|
||||
|
||||
private readonly ChangelogOverlay changelogOverlay;
|
||||
|
||||
@ -302,8 +302,8 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
// set charge status and level
|
||||
AddStep("load player", () => resetPlayer(false, () =>
|
||||
{
|
||||
powerStatus.SetCharging(isCharging);
|
||||
powerStatus.SetChargeLevel(chargeLevel);
|
||||
batteryInfo.SetCharging(isCharging);
|
||||
batteryInfo.SetChargeLevel(chargeLevel);
|
||||
}));
|
||||
AddUntilStep("wait for player", () => player?.LoadState == LoadState.Ready);
|
||||
AddAssert($"notification {(shouldWarn ? "triggered" : "not triggered")}", () => notificationOverlay.UnreadCount.Value == (shouldWarn ? 1 : 0));
|
||||
@ -381,16 +381,14 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mutable dummy PowerStatus class for <see cref="TestScenePlayerLoader.TestLowBatteryNotification"/>
|
||||
/// Mutable dummy BatteryInfo class for <see cref="TestScenePlayerLoader.TestLowBatteryNotification"/>
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
private class LocalPowerStatus : PowerStatus
|
||||
private class LocalBatteryInfo : BatteryInfo
|
||||
{
|
||||
private bool isCharging = true;
|
||||
private double chargeLevel = 1;
|
||||
|
||||
public override double BatteryCutoff => 0.2;
|
||||
|
||||
public override bool IsCharging => isCharging;
|
||||
|
||||
public override double ChargeLevel => chargeLevel;
|
||||
|
@ -157,7 +157,7 @@ namespace osu.Game
|
||||
|
||||
protected override UserInputManager CreateUserInputManager() => new OsuUserInputManager();
|
||||
|
||||
protected virtual PowerStatus CreatePowerStatus() => null;
|
||||
protected virtual BatteryInfo CreateBatteryInfo() => null;
|
||||
|
||||
/// <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.
|
||||
@ -285,7 +285,7 @@ namespace osu.Game
|
||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||
|
||||
var powerStatus = CreatePowerStatus();
|
||||
var powerStatus = CreateBatteryInfo();
|
||||
if (powerStatus != null)
|
||||
dependencies.CacheAs(powerStatus);
|
||||
|
||||
|
@ -114,7 +114,7 @@ namespace osu.Game.Screens.Play
|
||||
private AudioManager audioManager { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private PowerStatus powerStatus { get; set; }
|
||||
private BatteryInfo batteryInfo { get; set; }
|
||||
|
||||
public PlayerLoader(Func<Player> createPlayer)
|
||||
{
|
||||
@ -483,11 +483,11 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private void showBatteryWarningIfNeeded()
|
||||
{
|
||||
if (powerStatus == null) return;
|
||||
if (batteryInfo == null) return;
|
||||
|
||||
if (!batteryWarningShownOnce.Value)
|
||||
{
|
||||
if (powerStatus.IsLowBattery)
|
||||
if (batteryInfo.IsLowBattery)
|
||||
{
|
||||
notificationOverlay?.Post(new BatteryWarningNotification());
|
||||
batteryWarningShownOnce.Value = true;
|
||||
|
@ -5,15 +5,9 @@ namespace osu.Game.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the system's power status.
|
||||
/// Currently implemented on iOS and Android only.
|
||||
/// </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>
|
||||
/// The charge level of the battery, from 0 to 1.
|
||||
/// </summary>
|
||||
@ -23,8 +17,8 @@ namespace osu.Game.Utils
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
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 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 bool IsCharging => Battery.PowerSource != BatteryPowerSource.Battery;
|
||||
|
@ -117,7 +117,6 @@
|
||||
</ImageAsset>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<!-- Used for obtaining battery info. -->
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
|
Loading…
Reference in New Issue
Block a user