Skip to content

Commit

Permalink
Merge release/7.76 into trunk (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao authored Oct 28, 2024
2 parents 4ff64b3 + c4111cf commit e21acbe
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,10 @@ public enum PlayerAction: String, Codable, Equatable {
case archive = "archive"
case addBookmark = "bookmark"
case transcript = "transcript"
case download = "download"
}

extension Array: RawRepresentable where Element: RawRepresentable<String> {
extension Array: @retroactive RawRepresentable where Element: RawRepresentable<String> {
public typealias RawValue = String

public init?(rawValue: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ import Foundation
/// Whether this is a regular episode, or an user episode (File)
var isUserEpisode: Bool { get }
}

extension BaseEpisode {
public var isInDownloadProcess: Bool {
return downloading() || queued() || waitingForWifi()
}
}
3 changes: 3 additions & 0 deletions PocketCastsTests/Tests/Utilities/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ final class SettingsTests: XCTestCase {
.effects,
.sleepTimer,
.routePicker,
.download,
.starEpisode,
.shareEpisode,
.goToPodcast,
Expand All @@ -86,6 +87,7 @@ final class SettingsTests: XCTestCase {
.effects,
.sleepTimer,
.routePicker,
.download,
.starEpisode,
.shareEpisode,
.goToPodcast,
Expand Down Expand Up @@ -113,6 +115,7 @@ final class SettingsTests: XCTestCase {
.effects,
.sleepTimer,
.routePicker,
.download,
.starEpisode,
.shareEpisode,
.goToPodcast,
Expand Down
2 changes: 1 addition & 1 deletion config/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_LONG = 7.76.0.0
VERSION_LONG = 7.76.0.1
VERSION_SHORT = 7.76
9 changes: 9 additions & 0 deletions fastlane/Frozen.strings
Original file line number Diff line number Diff line change
Expand Up @@ -4521,6 +4521,15 @@
/* Auto Downloads Setting - Limits downloads to a number of show episodes. `%1$@' is a placeholder for the number of episodes*/
"auto_download_limit_number_of_episodes_show" = "%1$@ Latest Episodes per Show";

/* Toast message when episode download is removed*/
"player_episode_was_removed" = "Episode was removed";

/* Toast message when episode is queued for download*/
"player_episode_queued_for_download" = "Episode queued for download";

/* Toast message when episode download is cancelled*/
"player_episode_download_cancelled" = "Episode download cancelled";



/* MARK: - InfoPlist.strings */
Expand Down
1 change: 1 addition & 0 deletions podcasts/EffectsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class EffectsViewController: SimpleNotificationsViewController {
updateControls()

if FeatureFlag.customPlaybackSettings.enabled {
PlaybackManager.shared.updateIfPodcastUsedCustomEffectsBefore()
playbackSettingsSegmentedControl.selectedSegmentIndex = PlaybackManager.shared.isCurrentEffectGlobal() ? 0 : 1
}
if let episode = PlaybackManager.shared.currentEpisode() as? Episode, let podcast = episode.parentPodcast() {
Expand Down
23 changes: 22 additions & 1 deletion podcasts/Enumerations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ extension PlayerAction: AnalyticsDescribable {
/// Specify default actions and their order
static var defaultActions: [PlayerAction] {
[
.effects, .sleepTimer, .routePicker, .transcript,
.effects, .sleepTimer, .routePicker, .transcript, .download,
.starEpisode, .shareEpisode, .goToPodcast, .chromecast,
.markPlayed, .addBookmark, .archive
]
Expand Down Expand Up @@ -275,6 +275,8 @@ extension PlayerAction: AnalyticsDescribable {
self = .addBookmark
case 11:
self = .transcript
case 12:
self = .download
default:
return nil
}
Expand Down Expand Up @@ -304,6 +306,8 @@ extension PlayerAction: AnalyticsDescribable {
return 10
case .transcript:
return 11
case .download:
return 12
}
}

Expand Down Expand Up @@ -345,6 +349,11 @@ extension PlayerAction: AnalyticsDescribable {
return L10n.addBookmark
case .transcript:
return L10n.transcript
case .download:
guard let episode else {
return L10n.download
}
return episode.downloaded(pathFinder: DownloadManager.shared) ? L10n.removeDownload : (episode.isInDownloadProcess ? L10n.statusDownloading : L10n.download)
}
}

Expand Down Expand Up @@ -383,6 +392,11 @@ extension PlayerAction: AnalyticsDescribable {
return "bookmarks-shelf-overflow-icon"
case .transcript:
return "transcript"
case .download:
guard let episode else {
return "episode-download"
}
return episode.downloaded(pathFinder: DownloadManager.shared) ? "episode-downloaded" : "episode-download"
}
}

Expand Down Expand Up @@ -410,6 +424,11 @@ extension PlayerAction: AnalyticsDescribable {
return "bookmarks-shelf-icon"
case .transcript:
return "transcript"
case .download:
guard let episode else {
return "episode-download"
}
return episode.downloaded(pathFinder: DownloadManager.shared) ? "episode-downloaded" : "episode-download"
}
}

Expand Down Expand Up @@ -459,6 +478,8 @@ extension PlayerAction: AnalyticsDescribable {
return "bookmark"
case .transcript:
return "transcript"
case .download:
return "download"
}
}
}
Expand Down
55 changes: 53 additions & 2 deletions podcasts/NowPlayingPlayerItemViewController+Shelf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ protocol NowPlayingActionsDelegate: AnyObject {
func archiveTapped()
func bookmarkTapped()
func transcriptTapped()

func downloadTapped()
func sharedRoutePicker(largeSize: Bool) -> PCRoutePickerView
}

extension NowPlayingPlayerItemViewController: NowPlayingActionsDelegate {

@objc func reloadShelfActions() {
guard let playingEpisode = PlaybackManager.shared.currentEpisode() else { return }

let actions = Settings.playerActions()

// don't reload the actions unless we need to
if !lastShelfLoadState.updateRequired(shelfActions: actions, episodeUuid: playingEpisode.uuid, effectsOn: PlaybackManager.shared.effects().effectsEnabled(), sleepTimerOn: PlaybackManager.shared.sleepTimerActive(), episodeStarred: playingEpisode.keepEpisode) { return }
if !lastShelfLoadState.updateRequired(shelfActions: actions, episodeUuid: playingEpisode.uuid, effectsOn: PlaybackManager.shared.effects().effectsEnabled(), sleepTimerOn: PlaybackManager.shared.sleepTimerActive(), episodeStarred: playingEpisode.keepEpisode, episodeStatus: playingEpisode.episodeStatus) { return }

// load the first 4 actions into the player, followed by an overflow icon
playerControlsStackView.removeAllSubviews()
Expand Down Expand Up @@ -151,6 +152,16 @@ extension NowPlayingPlayerItemViewController: NowPlayingActionsDelegate {
button.addTarget(self, action: #selector(transcriptTapped(_:)), for: .touchUpInside)
button.accessibilityLabel = L10n.transcript

addToShelf(on: button)

case .download:
let button = UIButton(frame: CGRect.zero)
button.isPointerInteractionEnabled = true
button.imageView?.tintColor = ThemeColor.playerContrast02()
button.setImage(UIImage(named: action.largeIconName(episode: playingEpisode)), for: .normal)
button.addTarget(self, action: #selector(downloadTapped(_:)), for: .touchUpInside)
button.accessibilityLabel = L10n.download

addToShelf(on: button)
}

Expand Down Expand Up @@ -234,6 +245,41 @@ extension NowPlayingPlayerItemViewController: NowPlayingActionsDelegate {
displayTranscript = true
}

func downloadTapped() {
guard let episode = PlaybackManager.shared.currentEpisode() as? Episode else { return }

AnalyticsEpisodeHelper.shared.currentSource = analyticsSource

if episode.downloaded(pathFinder: DownloadManager.shared) {
let confirmation = OptionsPicker(title: L10n.podcastDetailsRemoveDownload)
let yesAction = OptionAction(label: L10n.remove, icon: nil) {
self.deleteDownloadedFile()
Toast.show(L10n.playerEpisodeWasRemoved)
}
yesAction.destructive = true
confirmation.addAction(action: yesAction)

confirmation.show(statusBarStyle: preferredStatusBarStyle)
} else if episode.isInDownloadProcess {
PlaybackActionHelper.stopDownload(episodeUuid: episode.uuid)
Toast.show(L10n.playerEpisodeDownloadCancelled)
} else {
PlaybackActionHelper.download(episodeUuid: episode.uuid)
Toast.show(L10n.playerEpisodeQueuedForDownload)
}
}

private func deleteDownloadedFile() {
guard let episode = PlaybackManager.shared.currentEpisode() as? Episode else { return }

EpisodeManager.analyticsHelper.currentSource = analyticsSource

PlaybackManager.shared.removeIfPlayingOrQueued(episode: episode, fireNotification: true, userInitiated: false)
EpisodeManager.deleteDownloadedFiles(episode: episode, userInitated: true)

NotificationCenter.postOnMainThread(notification: Constants.Notifications.episodeDownloadStatusChanged, object: episode.uuid)
}

// MARK: - Player Actions
private func presentUsingSheet(_ viewController: UIViewController, forceLarge: Bool = false) {
if let sheetController = viewController.sheetPresentationController {
Expand Down Expand Up @@ -319,6 +365,11 @@ extension NowPlayingPlayerItemViewController: NowPlayingActionsDelegate {
displayTranscript = true
}

@objc private func downloadTapped(_ sender: UIButton) {
shelfButtonTapped(.download)
downloadTapped()
}

// MARK: - Sleep Timer

@objc func sleepTimerUpdated() {
Expand Down
1 change: 1 addition & 0 deletions podcasts/NowPlayingPlayerItemViewController+Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extension NowPlayingPlayerItemViewController {
addCustomObserver(Constants.Notifications.playerActionsUpdated, selector: #selector(reloadShelfActions))
addCustomObserver(UIApplication.willEnterForegroundNotification, selector: #selector(update))
addCustomObserver(Constants.Notifications.episodeStarredChanged, selector: #selector(reloadShelfActions))
addCustomObserver(Constants.Notifications.episodeDownloadStatusChanged, selector: #selector(reloadShelfActions))
}

@objc private func playbackTrackChanged() {
Expand Down
17 changes: 14 additions & 3 deletions podcasts/PlaybackManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -870,14 +870,25 @@ class PlaybackManager: ServerPlaybackDelegate {
let podcast = episode.parentPodcast() else {
return
}
overrideEffectsToggled(applyLocalSettings: applyLocalSettings, for: podcast)
}

func overrideEffectsToggled(applyLocalSettings: Bool, for podcast: Podcast) {
podcast.isEffectsOverridden = applyLocalSettings

DataManager.sharedManager.save(podcast: podcast)
NotificationCenter.postOnMainThread(notification: Constants.Notifications.podcastUpdated, object: podcast.uuid)

let newEffects = loadEffects()
currentEffects = newEffects
handlePlaybackEffectsChanged(effects: newEffects)
effectsChangedExternally()
}

func updateIfPodcastUsedCustomEffectsBefore() {
if let episode = currentEpisode() as? Episode, let podcast = episode.parentPodcast() {
if podcast.overrideGlobalEffects, !podcast.usedCustomEffectsBefore {
podcast.usedCustomEffectsBefore = true
DataManager.sharedManager.save(podcast: podcast)
}
}
}

func isCurrentEffectGlobal() -> Bool {
Expand Down
52 changes: 41 additions & 11 deletions podcasts/PodcastEffectsViewController+Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega
case .playbackSpeed:
let cell = tableView.dequeueReusableCell(withIdentifier: PodcastEffectsViewController.timeStepperCellId, for: indexPath) as! TimeStepperCell
cell.cellLabel?.text = L10n.settingsPlaySpeed
if FeatureFlag.newSettingsStorage.enabled {
if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
cell.cellSecondaryLabel.text = L10n.playbackSpeed(effect.playbackSpeed.localized())
} else if FeatureFlag.newSettingsStorage.enabled {
cell.cellSecondaryLabel.text = L10n.playbackSpeed(podcast.settings.playbackSpeed.localized())
} else {
cell.cellSecondaryLabel.text = L10n.playbackSpeed(podcast.playbackSpeed.localized())
Expand All @@ -57,7 +61,12 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega
cell.timeStepper.maximumValue = 5
cell.timeStepper.smallIncrements = 0.1
cell.timeStepper.smallIncrementThreshold = TimeInterval.greatestFiniteMagnitude
if FeatureFlag.newSettingsStorage.enabled {

if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
cell.timeStepper.currentValue = effect.playbackSpeed
} else if FeatureFlag.newSettingsStorage.enabled {
cell.timeStepper.currentValue = podcast.settings.playbackSpeed
} else {
cell.timeStepper.currentValue = podcast.playbackSpeed
Expand All @@ -73,7 +82,11 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega
cell.cellLabel?.text = L10n.settingsTrimSilence
cell.cellSwitch.onTintColor = podcast.switchTintColor()
cell.setImage(imageName: "player_trim")
if FeatureFlag.newSettingsStorage.enabled {
if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
cell.cellSwitch.isOn = effect.trimSilence != .off
} else if FeatureFlag.newSettingsStorage.enabled {
cell.cellSwitch.isOn = podcast.settings.trimSilence != .off
} else {
cell.cellSwitch.isOn = podcast.trimSilenceAmount > 0
Expand All @@ -90,7 +103,11 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega

let trimAmount: TrimSilenceAmount

if FeatureFlag.newSettingsStorage.enabled {
if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
trimAmount = effect.trimSilence
} else if FeatureFlag.newSettingsStorage.enabled {
trimAmount = podcast.settings.trimSilence.amount
} else {
trimAmount = TrimSilenceAmount(rawValue: Int32(podcast.trimSilenceAmount)) ?? .low
Expand All @@ -103,7 +120,11 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega
cell.cellLabel?.text = L10n.settingsVolumeBoost
cell.cellSwitch.onTintColor = podcast.switchTintColor()
cell.setImage(imageName: "player_volumeboost")
if FeatureFlag.newSettingsStorage.enabled {
if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
cell.cellSwitch.isOn = effect.volumeBoost
} else if FeatureFlag.newSettingsStorage.enabled {
cell.cellSwitch.isOn = podcast.settings.boostVolume
} else {
cell.cellSwitch.isOn = podcast.boostVolume
Expand Down Expand Up @@ -218,18 +239,27 @@ extension PodcastEffectsViewController: UITableViewDataSource, UITableViewDelega
}

@objc private func overrideEffectsToggled(_ sender: UISwitch) {
podcast.isEffectsOverridden = sender.isOn
podcast.syncStatus = SyncStatus.notSynced.rawValue
if FeatureFlag.customPlaybackSettings.enabled && !podcast.usedCustomEffectsBefore {
podcast.usedCustomEffectsBefore = true
if FeatureFlag.customPlaybackSettings.enabled {
PlaybackManager.shared.overrideEffectsToggled(applyLocalSettings: sender.isOn, for: podcast)
effectsTable.reloadData()
} else {
podcast.isEffectsOverridden = sender.isOn
podcast.syncStatus = SyncStatus.notSynced.rawValue
saveUpdates()
}
saveUpdates()

Analytics.track(.podcastSettingsCustomPlaybackEffectsToggled, properties: ["enabled": sender.isOn])
}

private func tableData() -> [[TableRow]] {
let hasTrimSilence = FeatureFlag.newSettingsStorage.enabled ? podcast.settings.trimSilence != .off : podcast.trimSilenceAmount > 0
let hasTrimSilence: Bool
if FeatureFlag.customPlaybackSettings.enabled,
!podcast.usedCustomEffectsBefore {
let effect = PlaybackManager.shared.effects()
hasTrimSilence = effect.trimSilence != .off
} else {
hasTrimSilence = FeatureFlag.newSettingsStorage.enabled ? podcast.settings.trimSilence != .off : podcast.trimSilenceAmount > 0
}
if podcast.isEffectsOverridden && hasTrimSilence {
return [[.customForPodcast], [.playbackSpeed, .trimSilence, .trimSilenceAmount, .volumeBoost]]
}
Expand Down
3 changes: 2 additions & 1 deletion podcasts/ShelfActionsViewController+Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ extension ShelfActionsViewController: UITableViewDelegate, UITableViewDataSource
self.playerActionsDelegate?.bookmarkTapped()
case .transcript:
self.playerActionsDelegate?.transcriptTapped()
return
case.download:
self.playerActionsDelegate?.downloadTapped()
}
}
}
Expand Down
Loading

0 comments on commit e21acbe

Please sign in to comment.