Skip to content

Commit

Permalink
Merge branch 'develop' into refactor-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Jan 29, 2024
2 parents 7523ba0 + eebcba9 commit 7f342dc
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/devicekit/DeviceKit.git",
"state" : {
"revision" : "66837ecf1516e41fd4251bbb684dc4b1997f08ab",
"version" : "5.1.0"
"revision" : "e1c258c6070ddd6465265fe4692f29717404aede",
"version" : "5.2.1"
}
},
{
Expand All @@ -23,35 +23,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/iosdevzone/IDZSwiftCommonCrypto.git",
"state" : {
"revision" : "d824371e670bd57eb456bbc41139b4997f7207b8",
"version" : "0.13.1"
"revision" : "47f9747d12137cd59d783ab376e3ccab7206319b",
"version" : "0.16.1"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "c75584ac759cbb16b204d0a7de3ebf53ea6b304d",
"version" : "7.9.0"
"revision" : "3ec0ab0bca4feb56e8b33e289c9496e89059dd08",
"version" : "7.10.2"
}
},
{
"identity" : "marqueelabel",
"kind" : "remoteSourceControl",
"location" : "https://github.com/cbpowell/MarqueeLabel.git",
"state" : {
"revision" : "bc00d4cbff7f6c416035e3d16c21885452cd159e",
"version" : "4.3.1"
"revision" : "ae3cf7c647dd7f67f1946658285f5f0ce2476caf",
"version" : "4.4.0"
}
},
{
"identity" : "purchases-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/RevenueCat/purchases-ios.git",
"state" : {
"revision" : "ec48897eff464c040bf774741b5f1d5a97053436",
"version" : "4.25.1"
"revision" : "ff4907a2b01fb6e0e891f36e9a14421a5500cc04",
"version" : "4.31.9"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions BookPlayer/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
"error_loading_chapters" = "Chapters couldn't be loaded from: \n%@";
"error_empty_chapters" = "Chapters are empty, please verify the contents of the folder: %@";
"sleeptimer_option_custom" = "Custom";
"sleeptimer_option_sticky_on" = "Sticky ✓";
"sleeptimer_option_sticky_off" = "Sticky";
"sleeptimer_custom_alert_title" = "Custom sleep timer";
"settings_progresslabels_title" = "Progress Labels";
"settings_playerinterface_list_title" = "Opens";
Expand Down
22 changes: 21 additions & 1 deletion BookPlayer/Player/Player Screen/PlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ class PlayerViewModel: ViewModelProtocol {
}
)
)


let formatter = DateComponentsFormatter()

Expand Down Expand Up @@ -430,7 +431,26 @@ class PlayerViewModel: ViewModelProtocol {
}
)
)


if(SleepTimer.shared.getSticky()){
actions.append(
BPActionItem(
title: "sleeptimer_option_sticky_on".localized,
handler: {
SleepTimer.shared.setSticky(stickyState:false)
}
)
)
} else {
actions.append(
BPActionItem(
title: "sleeptimer_option_sticky_off".localized,
handler: {
SleepTimer.shared.setSticky(stickyState:true)
}
)
)
}
actions.append(BPActionItem.cancelAction)

sendEvent(.sleepTimerAlert(
Expand Down
8 changes: 8 additions & 0 deletions BookPlayer/Player/PlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ extension PlayerManager {

handleSmartRewind(currentItem)

handleStickyTimer()

fadeTimer?.invalidate()
shakeMotionService.stopMotionUpdates()
boostVolume = UserDefaults.standard.bool(forKey: Constants.UserDefaults.boostVolumeEnabled)
Expand Down Expand Up @@ -772,6 +774,12 @@ extension PlayerManager {
self.audioPlayer.seek(to: CMTime(seconds: newPlayerTime, preferredTimescale: CMTimeScale(NSEC_PER_SEC)))
}
}

func handleStickyTimer() {
if(SleepTimer.shared.getSticky()){
SleepTimer.shared.restartTimer()
}
}

func setSpeed(_ newValue: Float) {
self.speedService.setSpeed(newValue, relativePath: self.currentItem?.relativePath)
Expand Down
18 changes: 14 additions & 4 deletions BookPlayer/Player/SleepTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class SleepTimer {
/// Current time left on the timer
@Published public var state: SleepTimerState = .off
/// Last manually set sleep timer
private var lastActivedState: SleepTimerState = .off
private var lastActiveState: SleepTimerState = .off
/// Default available options
public let intervals: [TimeInterval] = [
300.0,
Expand All @@ -39,6 +39,8 @@ final class SleepTimer {
1800.0,
3600.0
]

public var sticky = false

/// Publisher when the countdown timer reaches the defined threshold
public var countDownThresholdPublisher = PassthroughSubject<Bool, Never>()
Expand Down Expand Up @@ -91,11 +93,19 @@ final class SleepTimer {

// MARK: Public methods

public func setSticky(stickyState: Bool){
sticky = stickyState
}

public func getSticky() -> Bool{
return sticky
}

public func setTimer(_ newState: SleepTimerState) {
/// Always cancel any ongoing timer
reset()
state = newState
lastActivedState = newState
lastActiveState = newState

switch newState {
case .off:
Expand All @@ -114,9 +124,9 @@ final class SleepTimer {
NotificationCenter.default.addObserver(self, selector: #selector(self.end), name: .chapterChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(self.end), name: .bookEnd, object: nil)
}
}
}

public func restartTimer() {
setTimer(lastActivedState)
setTimer(lastActiveState)
}
}
2 changes: 2 additions & 0 deletions BookPlayer/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
"error_loading_chapters" = "Chapters couldn't be loaded from: \n%@";
"error_empty_chapters" = "Chapters are empty, please verify the contents of the folder: %@";
"sleeptimer_option_custom" = "Custom";
"sleeptimer_option_sticky_on" = "Sticky ✓";
"sleeptimer_option_sticky_off" = "Sticky";
"sleeptimer_custom_alert_title" = "Custom sleep timer";
"settings_progresslabels_title" = "Progress Labels";
"settings_playerinterface_list_title" = "Opens";
Expand Down

0 comments on commit 7f342dc

Please sign in to comment.