Skip to content

Commit

Permalink
Merge pull request #1085 from TortugaPower/sleeptimer-translations
Browse files Browse the repository at this point in the history
Rebrand sticky timer to auto timer
  • Loading branch information
GianniCarlo authored Jan 29, 2024
2 parents 4230996 + 7eb8b05 commit b72104f
Show file tree
Hide file tree
Showing 29 changed files with 158 additions and 71 deletions.
4 changes: 2 additions & 2 deletions BookPlayer/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@
"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 Expand Up @@ -305,3 +303,5 @@ We're working hard on providing a seamless experience, if possible, please conta
"storage_artwork_cache_title" = "Artwork cache size";
"settings_share_debug_information" = "Share debug information";
"settings_autlock_section_title" = "Autolock";
"settings_sleeptimer_auto_title" = "Auto Sleep Timer";
"settings_sleeptimer_auto_description" = "Restart the last active sleep timer when playback is resumed";
50 changes: 18 additions & 32 deletions BookPlayer/Player/Player Screen/PlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,23 +395,7 @@ class PlayerViewModel: ViewModelProtocol {
)
)

let formatter = DateComponentsFormatter()

formatter.unitsStyle = .full
formatter.allowedUnits = [.hour, .minute]

for interval in SleepTimer.shared.intervals {
guard let formattedDuration = formatter.string(from: interval) else { continue }

actions.append(
BPActionItem(
title: String.localizedStringWithFormat("sleep_interval_title".localized, formattedDuration),
handler: {
SleepTimer.shared.setTimer(.countdown(interval))
}
)
)
}
actions.append(contentsOf: getCountdownActions())

actions.append(
BPActionItem(
Expand All @@ -431,21 +415,6 @@ class PlayerViewModel: ViewModelProtocol {
)
)

let stickyAction = SleepTimer.shared.getSticky()
? BPActionItem(
title: "sleeptimer_option_sticky_on".localized,
handler: {
SleepTimer.shared.setSticky(stickyState: false)
}
)
: BPActionItem(
title: "sleeptimer_option_sticky_off".localized,
handler: {
SleepTimer.shared.setSticky(stickyState: true)
}
)

actions.append(stickyAction)
actions.append(BPActionItem.cancelAction)

sendEvent(.sleepTimerAlert(
Expand Down Expand Up @@ -488,6 +457,23 @@ class PlayerViewModel: ViewModelProtocol {

return storedTime
}

private func getCountdownActions() -> [BPActionItem] {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full
formatter.allowedUnits = [.hour, .minute]

return SleepTimer.shared.intervals.compactMap { interval in
guard let formattedDuration = formatter.string(from: interval) else { return nil }

return BPActionItem(
title: String.localizedStringWithFormat("sleep_interval_title".localized, formattedDuration),
handler: {
SleepTimer.shared.setTimer(.countdown(interval))
}
)
}
}
}

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

handleSmartRewind(currentItem)

handleStickyTimer()
handleAutoTimer()

fadeTimer?.invalidate()
shakeMotionService.stopMotionUpdates()
boostVolume = UserDefaults.standard.bool(forKey: Constants.UserDefaults.boostVolumeEnabled)
Expand Down Expand Up @@ -775,10 +775,10 @@ extension PlayerManager {
}
}

func handleStickyTimer() {
if SleepTimer.shared.getSticky() {
SleepTimer.shared.restartTimer()
}
func handleAutoTimer() {
guard UserDefaults.standard.bool(forKey: Constants.UserDefaults.autoTimerEnabled) else { return }

SleepTimer.shared.restartTimer()
}

func setSpeed(_ newValue: Float) {
Expand Down
15 changes: 3 additions & 12 deletions BookPlayer/Player/SleepTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ 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 @@ -92,25 +90,17 @@ 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
lastActiveState = newState

switch newState {
case .off:
donateTimerIntent(with: .cancel)
case .countdown(let interval):
lastActiveState = newState
if let option = TimeParser.getTimerOption(from: interval) {
donateTimerIntent(with: option)
}
Expand All @@ -120,11 +110,12 @@ final class SleepTimer {
self?.update()
}
case .endOfChapter:
lastActiveState = newState
donateTimerIntent(with: .endChapter)
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(lastActiveState)
Expand Down
56 changes: 48 additions & 8 deletions BookPlayer/Settings/Base.lproj/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<string key="footerTitle">SKAN is Apple's privacy-first attribution solution that enables measuring how effective a campaign was without compromising the user privacy</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="z7s-7T-Ue2" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="893.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="921.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="z7s-7T-Ue2" id="585-78-tbb">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand Down Expand Up @@ -1998,12 +1998,51 @@
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection footerTitle="Restart the last active sleep timer when playback is resumed" id="vIz-ti-1ab">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="h7A-iW-714" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="299.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="h7A-iW-714" id="d1f-wd-r7D">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Hao-jf-1z7">
<rect key="frame" x="310" y="6.5" width="51" height="31"/>
<constraints>
<constraint firstAttribute="width" constant="49" id="hsz-jf-rOL"/>
</constraints>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Auto Sleep Timer" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OdU-iJ-lVp" customClass="LocalizableLabel" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="16" y="11.5" width="286" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="localizedKey" value="settings_sleeptimer_auto_title"/>
</userDefinedRuntimeAttributes>
</label>
</subviews>
<constraints>
<constraint firstItem="OdU-iJ-lVp" firstAttribute="leading" secondItem="d1f-wd-r7D" secondAttribute="leading" constant="16" id="6Po-Ck-T1f"/>
<constraint firstItem="OdU-iJ-lVp" firstAttribute="centerY" secondItem="d1f-wd-r7D" secondAttribute="centerY" id="BuU-Ly-hCh"/>
<constraint firstItem="Hao-jf-1z7" firstAttribute="leading" secondItem="OdU-iJ-lVp" secondAttribute="trailing" constant="8" id="Dv5-Lx-P6f"/>
<constraint firstAttribute="trailing" secondItem="Hao-jf-1z7" secondAttribute="trailing" constant="16" id="f4N-RF-KfP"/>
<constraint firstItem="Hao-jf-1z7" firstAttribute="centerY" secondItem="d1f-wd-r7D" secondAttribute="centerY" id="tZS-w5-yec"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="customLabel" destination="OdU-iJ-lVp" id="3Hv-uf-PVC"/>
</connections>
</tableViewCell>
</cells>
</tableViewSection>
<tableViewSection id="ndB-eX-83q">
<string key="footerTitle">Doubles the volume.
Use with caution and care for your hearing.</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="7L4-ZR-6Y1" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="299.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="407.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="7L4-ZR-6Y1" id="X9G-J4-qAq">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand Down Expand Up @@ -2042,7 +2081,7 @@ Use with caution and care for your hearing.</string>
<tableViewSection footerTitle="Set speed across all books." id="lcf-oa-ncd">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="biN-UB-ceL" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="407.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="515.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="biN-UB-ceL" id="9dd-C5-rSL">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand Down Expand Up @@ -2081,7 +2120,7 @@ Use with caution and care for your hearing.</string>
<tableViewSection footerTitle="Adjust what the list button in the player screen opens" id="04N-lB-8ix">
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="none" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="Ydn-hQ-kXZ" detailTextLabel="Jbk-jB-Hyp" imageView="wIP-hW-J0B" style="IBUITableViewCellStyleValue1" id="oMW-vV-SO2" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="499.5" width="375" height="44"/>
<rect key="frame" x="0.0" y="607.5" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="oMW-vV-SO2" id="8zv-VN-kiu">
<rect key="frame" x="0.0" y="0.0" width="348.5" height="44"/>
Expand Down Expand Up @@ -2117,7 +2156,7 @@ Use with caution and care for your hearing.</string>
<string key="footerTitle">Toggle between displaying the remaining time, total duration and progress of either the chapter or the book in the player screen</string>
<cells>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="BJG-C7-5Vg" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="619" width="375" height="44"/>
<rect key="frame" x="0.0" y="727" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BJG-C7-5Vg" id="dpV-7M-H3x">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
Expand Down Expand Up @@ -2152,19 +2191,19 @@ Use with caution and care for your hearing.</string>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="vru-07-FFi" customClass="StaticCellView" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="0.0" y="663" width="375" height="44"/>
<rect key="frame" x="0.0" y="771" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vru-07-FFi" id="V6Q-pu-WgH">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jzV-Oj-QRt">
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="jzV-Oj-QRt">
<rect key="frame" x="310" y="6.5" width="51" height="31"/>
<constraints>
<constraint firstAttribute="width" constant="49" id="dX3-2o-B6Y"/>
</constraints>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Use Chapter Context" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="jWe-Ru-KOW" customClass="LocalizableLabel" customModule="BookPlayer" customModuleProvider="target">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Use Chapter Context" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="jWe-Ru-KOW" customClass="LocalizableLabel" customModule="BookPlayer" customModuleProvider="target">
<rect key="frame" x="16" y="11.5" width="286" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
Expand Down Expand Up @@ -2196,6 +2235,7 @@ Use with caution and care for your hearing.</string>
</tableView>
<navigationItem key="navigationItem" title="Player Controls" leftItemsSupplementBackButton="YES" largeTitleDisplayMode="never" id="gST-Cn-uPB"/>
<connections>
<outlet property="autoSleepTimerSwitch" destination="Hao-jf-1z7" id="aV4-Cs-ZbU"/>
<outlet property="boostVolumeSwitch" destination="REu-u1-fwP" id="ORF-rl-zos"/>
<outlet property="chapterTimeSwitch" destination="jzV-Oj-QRt" id="lY1-Fl-C2d"/>
<outlet property="forwardIntervalLabel" destination="hD8-4g-KSV" id="kFR-tA-8kv"/>
Expand Down
Loading

0 comments on commit b72104f

Please sign in to comment.