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
Sleep Timer: add the option to select the number of episodes #1640
Conversation
Allowing customization of number of episodes
Generated by 🚫 Danger |
@@ -0,0 +1,188 @@ | |||
import UIKit | |||
|
|||
class CustomStepper: UIControl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not proud of copying/pasting CustomTimeStepper
here. I tried playing with generics but forgot that Storyboard only plays nice with Obj-C. 🤡
podcasts/SleepTimerManager.swift
Outdated
// Here we watch the current episode until it actually starts playing to | ||
// restart the timer per episode. | ||
// This avoid issues because the Sleep Timer per episode pauses on the end | ||
// of the last episode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this comment conveys the complexity of restarting the sleep timer. I tried many different events and logic, and ultimately everything — besides this solution — failed.
I'll be more verbose here to try to explain:
- When we finish a sleep timer per episode, we play at the end of the last played episode;
- When we tap play again, this episode will still be queued to play and the timer will restart
- However, we can't differentiate if this episode "playing" is what was playing before or not. And due to the nature of
PlaybackManager
,currentEpisode()
already changes to the next one (even though the whole player displays the previous one). - If we restart the timer, this "end of episode" will be counted as a one-played episode, which leads to if the timer is set to 1 episode, nothing happens. The app thinks that this episode that just finished was the episode meant to be played. If it's bigger than 1 episode, 1 will be deduced and the timer will start with one less episode.
- As none of this is enough, buffering is also part of the equation: we can't restart the timer unless an episode is playing (thus the check here).
I spent a good amount of hours trying to make that simpler but I couldn't. So any suggestion on improving this comment — if it's not clear — would be appreciated.
var bigIncrements: Int = 1 | ||
var smallIncrements: Int = 1 | ||
var smallIncrementThreshold: Int = 1 | ||
var currentValue: Int = 1 { | ||
didSet { | ||
accessibilityValue = "\(currentValue)" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional Suggestion: Instead of generics why not abstract this to a protocol and have two implementations one for Int and another for TimeInterval that you can set on init
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working great! Tested the scenarios presented and all working correctly.
Adds the option for the user to configure the number of episodes for Sleep Timer.
To test
Go to Profile > Settings > Beta Features > enable
tracksLogging
.🔵 Tracked: player_sleep_timer_enabled ["number_of_episodes": 3, "time": "end_of_episode"]
is tracked🔵 Tracked: player_sleep_timer_restarted ["number_of_episodes": 3, "time": "end_of_episode"]
is trackedExtending
🔵 Tracked: player_sleep_timer_extended ["number_of_episodes": 3, "amount": "end_of_episode"]
is trackedChecklist
CHANGELOG.md
if necessary.