Skip to content

Commit ba0ab70

Browse files
CopilotYBTopaz8
andcommitted
Address code review feedback: track screen-on flag and remove redundant call
Co-authored-by: YBTopaz8 <41630728+YBTopaz8@users.noreply.github.com>
1 parent 7810394 commit ba0ab70

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Dimmer/Dimmer.Droid/ViewsAndPages/NativeViews/LyricsViewFragment.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal class LyricsViewFragment : Fragment
2626
private LyricsAdapter _adapter;
2727
private ImageView _backgroundImageView;
2828
private TextView _songTitleTv, _artistAlbumTv;
29+
private bool _isScreenKeepOnSetByThisFragment = false;
2930

3031
public LyricsViewFragment(BaseViewModelAnd viewModel)
3132
{
@@ -123,7 +124,6 @@ public override void OnViewCreated(View view, Bundle? savedInstanceState)
123124
{
124125
base.OnViewCreated(view, savedInstanceState);
125126
viewModel.CurrentFragment = this;
126-
UpdateScreenKeepOn();
127127
}
128128

129129
public override void OnResume()
@@ -140,17 +140,19 @@ public override void OnPause()
140140

141141
private void UpdateScreenKeepOn()
142142
{
143-
if (viewModel?.KeepScreenOnDuringLyrics == true && Activity?.Window != null)
143+
if (viewModel?.KeepScreenOnDuringLyrics == true && Activity?.Window != null && !_isScreenKeepOnSetByThisFragment)
144144
{
145145
Activity.Window.AddFlags(WindowManagerFlags.KeepScreenOn);
146+
_isScreenKeepOnSetByThisFragment = true;
146147
}
147148
}
148149

149150
private void ClearScreenKeepOn()
150151
{
151-
if (Activity?.Window != null)
152+
if (_isScreenKeepOnSetByThisFragment && Activity?.Window != null)
152153
{
153154
Activity.Window.ClearFlags(WindowManagerFlags.KeepScreenOn);
155+
_isScreenKeepOnSetByThisFragment = false;
154156
}
155157
}
156158
private void SetupBindings()

0 commit comments

Comments
 (0)