Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sleep mode #518

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

AstroTheAstronaut
Copy link
Contributor

@AstroTheAstronaut AstroTheAstronaut commented Sep 19, 2023

This PR adds a Sleep Mode to Findroid. (Fixes a request on Discord)
At the moment, if the user falls asleep while watching a show, the screen will remain on for the remainder of the show/movie, maybe even more, depending if it's a show or a movie (if it is a show, the rest of the episodes in the series will play). This isn't ideal as it consumes battery needlessly.
This PR implements a timer that, when it's finished, shows a new screen that explains that Sleep Mode has been enabled and that the screen will turn off on its own to prevent unnecessary battery consumption.
This feature can be disabled in the app's settings if people don't want to have this option (Not sure if this should be removed)

Screenshots:

Screenshot_20230919-122416
Setting in the Player section

Screenshot_20230919-122524
Button next to the lock button to show the Sleep Mode button

Screenshot_20230919-122531
Sleep Mode timer dialog

Screenshot_20230919-122650
Sleep Mode screen with unlock button

To do:

  • Test for bugs
  • Add option for "Until media ends" in the dialog
  • Test on big screens

UPDATE: Tested it with MPV and it works just fine also.


private fun disableSleepMode() {
binding.playerView.player?.playWhenReady = true
window.addFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint issue here, just remove the space after addFlag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines 484 to 488
"Sleep Mode will be enabled in $hours $hourText and $minutes $minuteText"
hours > 0 ->
"Sleep Mode will be enabled in $hours $hourText"
else ->
"Sleep Mode will be enabled in $minutes $minuteText"
Copy link
Contributor

@Yash-Garg Yash-Garg Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this to a string resource will be better for Translations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this to a string resource will be better for Translations.

I think I moved everything to a string resource, but I had to use @SuppressLint("StringFormatMatches") for that function because I couldn't figure out what the thing wanted from me. It works fine tho.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AstroTheAstronaut StringFormatMatches lint is probably because you used %1$s while you are passing a number value which expects %1$d in some places like hours, minutes, etc.

@jarnedemeulemeester jarnedemeulemeester changed the title Feat: Add Sleep Mode feat: sleep mode Nov 1, 2023
@arjunluthra
Copy link

Poking this feature, hope this can get in soon. Looking forward to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants