Skip to content

Commit

Permalink
Merge pull request #14 from Baka632/240601-GlanceViewOptimization
Browse files Browse the repository at this point in the history
优化概览模式的播放状态显示及调低亮度过程
  • Loading branch information
Baka632 authored Jun 1, 2024
2 parents dcc6ba2 + 76e4596 commit 157bdae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/MonsterSiren.Uwp/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="Baka632.MonsterSiren.Uwp"
Publisher="CN=Baka632"
Version="1.1.1.0" />
Version="1.1.2.0" />

<mp:PhoneIdentity PhoneProductId="c4f5a7b1-db02-4855-b1bd-304559dec527" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion src/MonsterSiren.Uwp/Services/MusicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static MusicService()
mediaPlayer.Source = mediaPlaybackList;
CurrentMediaPlaybackList = new NowPlayingList(mediaPlaybackList.Items);

//下面的事件处理器在 UI 线程引发事件,这样可以让与 UI 相关的代码在处理这些事件时不会出错
// 下面的事件处理器在 UI 线程引发事件,这样可以让与 UI 相关的代码在处理这些事件时不会出错
mediaPlayer.VolumeChanged += async (sender, arg) =>
{
double volume = sender.Volume;
Expand Down
4 changes: 2 additions & 2 deletions src/MonsterSiren.Uwp/ViewModels/GlanceViewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed partial class GlanceViewViewModel : ObservableObject
[ObservableProperty]
private double _contentOffset;
[ObservableProperty]
private bool showPausedState = MusicService.PlayerPlayBackState == MediaPlaybackState.Paused;
private bool showPlayState = MusicService.PlayerPlayBackState is MediaPlaybackState.Paused or MediaPlaybackState.Buffering or MediaPlaybackState.Opening;
[ObservableProperty]
private bool showMuteState = MusicService.IsPlayerMuted;
[ObservableProperty]
Expand All @@ -40,7 +40,7 @@ private void OnMusicServicePlayerMuteStateChanged(bool state)

private void OnMusicServicePlayerPlaybackStateChanged(MediaPlaybackState state)
{
ShowPausedState = state == MediaPlaybackState.Paused;
ShowPlayState = state is MediaPlaybackState.Paused or MediaPlaybackState.Buffering or MediaPlaybackState.Opening;
}

~GlanceViewViewModel()
Expand Down
6 changes: 3 additions & 3 deletions src/MonsterSiren.Uwp/Views/GlanceViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
x:Load="{x:Bind ViewModel.ShowMeteredInternet, Mode=OneWay}"
Symbol="FourBars" />
<FontIcon
x:Name="PausedStateIcon"
x:Name="PlayStateIcon"
Margin="0,0,10,0"
x:Load="{x:Bind ViewModel.ShowPausedState, Mode=OneWay}"
x:Load="{x:Bind ViewModel.ShowPlayState, Mode=OneWay}"
FontSize="18"
Glyph="&#xE102;" />
Glyph="{x:Bind ViewModel.MusicInfo.PlayIconGlyph, Mode=OneWay}" />
<FontIcon
x:Name="MuteStateIcon"
Margin="0,0,10,0"
Expand Down
29 changes: 14 additions & 15 deletions src/MonsterSiren.Uwp/Views/GlanceViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ public GlanceViewPage()
}

SizeChanged += OnPageSizeChanged;

if (SettingsHelper.TryGet(CommonValues.AppGlanceModeUseLowerBrightnessSettingsKey, out bool useLowerBrightness) && useLowerBrightness)
{
Task brightnessTask = UIThreadHelper.RunOnUIThread(() =>
{
_brightnessOverride = BrightnessOverride.GetForCurrentView();
if (_brightnessOverride.IsSupported)
{
_brightnessOverride.SetBrightnessLevel(0.1, DisplayBrightnessOverrideOptions.UseDimmedPolicyWhenBatteryIsLow);
_brightnessOverride.StartOverride();
}
});
brightnessTask.Wait(300);
}
}

private void OnPageSizeChanged(object sender, SizeChangedEventArgs e)
Expand Down Expand Up @@ -92,7 +78,7 @@ private void AdjustContentPosition()
}
}

protected override void OnNavigatedTo(NavigationEventArgs e)
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);

Expand All @@ -101,6 +87,19 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
view.TryEnterFullScreenMode();
}

if (SettingsHelper.TryGet(CommonValues.AppGlanceModeUseLowerBrightnessSettingsKey, out bool useLowerBrightness) && useLowerBrightness)
{
await UIThreadHelper.RunOnUIThread(() =>
{
_brightnessOverride = BrightnessOverride.GetForCurrentView();
if (_brightnessOverride.IsSupported)
{
_brightnessOverride.SetBrightnessLevel(0.1, DisplayBrightnessOverrideOptions.UseDimmedPolicyWhenBatteryIsLow);
_brightnessOverride.StartOverride();
}
});
}
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
Expand Down

0 comments on commit 157bdae

Please sign in to comment.