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

Add setting to control auto-downloads on follow #2493

Merged
merged 11 commits into from
Dec 3, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fix refresh of the navigation bar buttons when switchin tabs [#2294](https://github.com/Automattic/pocket-casts-ios/issues/2294)
- Fix sharing of Referrals, Episodes and EOY when using the radioactivity theme [#2485](https://github.com/Automattic/pocket-casts-ios/pull/2485)
- Fix playback of bookmarks that are created on other platforms and never loaded locally [#1667](https://github.com/Automattic/pocket-casts-ios/issues/1667)
- Add new setting on Auto-Downloads settings to define the on follow behaviour. [#2493](https://github.com/Automattic/pocket-casts-ios/pull/2493)

7.77
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ extension ServerPodcastManager {
let autoDownloadCount = DataManager.sharedManager.count(query: autoDownloadQuery, values: nil)
let totalCount = (DataManager.sharedManager.count(query: totalQuery, values: nil) - 1) // -1 because the podcast we're currently adding could be returned by this query
let shouldTriggerAutoDownload: Bool
if FeatureFlag.autoDownloadOnSubscribe.enabled, autoDownload {
shouldTriggerAutoDownload = (AutoDownloadSetting(rawValue: podcast.autoDownloadSetting) ?? .off) != .off
if FeatureFlag.autoDownloadOnSubscribe.enabled {
shouldTriggerAutoDownload = autoDownload
} else {
shouldTriggerAutoDownload = (totalCount > 0) && (autoDownloadCount >= totalCount)
}
Expand Down
1 change: 1 addition & 0 deletions podcasts/Analytics/AnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ enum AnalyticsEvent: String {
case settingsAutoDownloadShown
case settingsAutoDownloadUpNextToggled
case settingsAutoDownloadNewEpisodesToggled
case settingsAutoDownloadOnFollowPodcastToggled
case settingsAutoDownloadLimitDownloadsChanged
case settingsAutoDownloadPodcastsChanged
case settingsAutoDownloadFiltersChanged
Expand Down
2 changes: 1 addition & 1 deletion podcasts/AppDelegate+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension AppDelegate {

// Disable dark up next theme for new users
Settings.darkUpNextTheme = false

Settings.setAutoDownloadOnFollow(true)
setWhatsNewAcknowledgeToLatest()
}

Expand Down
35 changes: 28 additions & 7 deletions podcasts/DownloadSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DownloadSettingsViewController: PCViewController, UITableViewDataSource, U
}
}

private enum TableRow { case upNext, podcastAutoDownload, podcastSelection, downloadLimits, filterSelection, onlyOnWifi }
private enum TableRow { case upNext, podcastAutoDownload, podcastSelection, downloadOnFollow, downloadLimits, filterSelection, onlyOnWifi }
private let podcastDownloadOffData: [[TableRow]] = [[.upNext], [.podcastAutoDownload], [.filterSelection], [.onlyOnWifi]]
private let podcastDownloadOnData: [[TableRow]] = [[.upNext], [.podcastAutoDownload, .podcastSelection], [.filterSelection], [.onlyOnWifi]]

Expand Down Expand Up @@ -54,15 +54,16 @@ class DownloadSettingsViewController: PCViewController, UITableViewDataSource, U
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
let firstRowInSection = tableRows()[section][0]

if firstRowInSection == .upNext {
switch firstRowInSection {
case .upNext:
return L10n.settingsAutoDownloadsSubtitleUpNext
} else if firstRowInSection == .podcastAutoDownload {
case .podcastAutoDownload:
return L10n.settingsAutoDownloadsSubtitleNewEpisodes
} else if firstRowInSection == .filterSelection {
case .filterSelection:
return L10n.settingsAutoDownloadsSubtitleFilters
default:
return nil
}

return nil
}

func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
Expand Down Expand Up @@ -104,6 +105,15 @@ class DownloadSettingsViewController: PCViewController, UITableViewDataSource, U
cell.cellLabel.text = L10n.selectedPodcastCount(allWithAutoDownloadOn.count)
cell.cellSecondaryLabel.text = ""

return cell
case .downloadOnFollow:
let cell = tableView.dequeueReusableCell(withIdentifier: DownloadSettingsViewController.switchCellId, for: indexPath) as! SwitchCell

cell.cellLabel.text = L10n.settingsAutoDownloadsOnFollow
cell.cellSwitch.isOn = Settings.autoDownloadOnFollow()
cell.cellSwitch.removeTarget(self, action: nil, for: UIControl.Event.valueChanged)
cell.cellSwitch.addTarget(self, action: #selector(automaticDownloadOnFollowToggled(_:)), for: UIControl.Event.valueChanged)

return cell
case .downloadLimits:
let cell = tableView.dequeueReusableCell(withIdentifier: DownloadSettingsViewController.disclosureCellId, for: indexPath) as! DisclosureCell
Expand Down Expand Up @@ -228,6 +238,11 @@ class DownloadSettingsViewController: PCViewController, UITableViewDataSource, U
settingsTable.reloadData()
}

@objc private func automaticDownloadOnFollowToggled(_ slider: UISwitch) {
Settings.setAutoDownloadOnFollow(slider.isOn, userInitiated: true)
settingsTable.reloadData()
}

@objc private func downloadUpNextToggled(_ slider: UISwitch) {
Settings.setDownloadUpNextEpisodes(slider.isOn)

Expand All @@ -243,9 +258,15 @@ class DownloadSettingsViewController: PCViewController, UITableViewDataSource, U

var data = autoDownloadPodcastsEnabled ? podcastDownloadOnData : podcastDownloadOffData

if autoDownloadPodcastsEnabled, FeatureFlag.autoDownloadOnSubscribe.enabled {
if FeatureFlag.autoDownloadOnSubscribe.enabled {
data = podcastDownloadOnData
data[1].append(.downloadOnFollow)
data[1].append(.downloadLimits)
if !autoDownloadPodcastsEnabled {
data[1].remove(at: 1)
}
}

return data
}
}
Expand Down
4 changes: 2 additions & 2 deletions podcasts/PodcastViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,9 @@ class PodcastViewController: FakeNavViewController, PodcastActionsDelegate, Sync

podcast.subscribed = 1
podcast.syncStatus = SyncStatus.notSynced.rawValue
podcast.autoDownloadSetting = (FeatureFlag.autoDownloadOnSubscribe.enabled && Settings.autoDownloadEnabled() ? AutoDownloadSetting.latest : AutoDownloadSetting.off).rawValue
podcast.autoDownloadSetting = (FeatureFlag.autoDownloadOnSubscribe.enabled && Settings.autoDownloadEnabled() && Settings.autoDownloadOnFollow() ? AutoDownloadSetting.latest : AutoDownloadSetting.off).rawValue
DataManager.sharedManager.save(podcast: podcast)
ServerPodcastManager.shared.updateLatestEpisodeInfo(podcast: podcast, setDefaults: true, autoDownloadLimit: Settings.autoDownloadLimits().rawValue)
ServerPodcastManager.shared.updateLatestEpisodeInfo(podcast: podcast, setDefaults: true, autoDownloadLimit: Settings.autoDownloadOnFollow() ? Settings.autoDownloadLimits().rawValue : 0)
loadLocalEpisodes(podcast: podcast, animated: true)

if featuredPodcast {
Expand Down
4 changes: 2 additions & 2 deletions podcasts/ServerPodcastManager+Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import PocketCastsUtils
extension ServerPodcastManager {

func subscribe(to podcastUuid: String, completion: ((Bool) -> ())?) {
let limits = Settings.autoDownloadEnabled() && FeatureFlag.autoDownloadOnSubscribe.enabled ? Settings.autoDownloadLimits().rawValue : 0
let limits = Settings.autoDownloadEnabled() && FeatureFlag.autoDownloadOnSubscribe.enabled && Settings.autoDownloadOnFollow() ? Settings.autoDownloadLimits().rawValue : 0
self.addFromUuid(podcastUuid: podcastUuid, subscribe: true, autoDownloads: limits, completion: completion)
}

func subscribeFromItunesId(_ itunesId: Int, completion: ((Bool, String?) -> ())?) {
let limits = Settings.autoDownloadEnabled() && FeatureFlag.autoDownloadOnSubscribe.enabled ? Settings.autoDownloadLimits().rawValue : 0
let limits = Settings.autoDownloadEnabled() && FeatureFlag.autoDownloadOnSubscribe.enabled && Settings.autoDownloadOnFollow() ? Settings.autoDownloadLimits().rawValue : 0
self.addFromiTunesId(itunesId, subscribe: true, autoDownloads: limits, completion: completion)
}
}
15 changes: 15 additions & 0 deletions podcasts/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ class Settings: NSObject {
trackValueToggled(.settingsAutoDownloadNewEpisodesToggled, enabled: allow)
}

private static let autoDownloadOnFollowKey = "AutoDownloadOnFollow"
class func autoDownloadOnFollow() -> Bool {
guard UserDefaults.standard.object(forKey: Settings.autoDownloadOnFollowKey) != nil else {
return false
}
return UserDefaults.standard.bool(forKey: Settings.autoDownloadOnFollowKey)
}

class func setAutoDownloadOnFollow(_ allow: Bool, userInitiated: Bool = false) {
UserDefaults.standard.set(allow, forKey: Settings.autoDownloadOnFollowKey)

guard userInitiated else { return }
trackValueToggled(.settingsAutoDownloadOnFollowPodcastToggled, enabled: allow)
}

private static let autoDownloadLimitKey = "AutoDownloadLimit"
class func autoDownloadLimits() -> AutoDownloadLimit {
AutoDownloadLimit(rawValue: UserDefaults.standard.integer(forKey: Settings.autoDownloadLimitKey)) ?? .two
Expand Down
6 changes: 4 additions & 2 deletions podcasts/Strings+Generated.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions podcasts/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@
"settings_auto_downloads_subtitle_filters" = "Download the top episodes in a filter.";

/* Subtitle explaining the toggle to auto download New Episodes. */
"settings_auto_downloads_subtitle_new_episodes" = "Automatically download new episodes as they’re released, and manage your storage by setting a limit on how many episodes are saved.";
"settings_auto_downloads_subtitle_new_episodes" = "Automatically download new episodes, save episodes from newly followed shows, and manage your storage by setting a limit on how many episodes are saved.";

/* Subtitle explaining the toggle to auto download items in the Up Next Queue. */
"settings_auto_downloads_subtitle_up_next" = "Download episodes added to Up Next.";
Expand Down Expand Up @@ -4598,7 +4598,7 @@
"week" = "week";

/* Auto Downloads Setting - Limits downloads row title*/
"auto_download_limit_downloads" = "Limit downloads";
"auto_download_limit_downloads" = "Limit Downloads";

/* Auto Downloads Setting - Limits downloads picker title*/
"auto_download_limit_auto_downloads" = "Limit auto downloads";
Expand Down Expand Up @@ -4696,3 +4696,5 @@
/* Referrals - Share Pass message. `%1$@' is a placeholder for the duration of free period offered on the Plus subscription*/
"referrals_share_pass_long_message" = "Hi there!\n\nHere is a %1$@ guest pass for Pocket Casts Plus–my favorite podcast player. It's packed with unique features like bookmarks, folders, and more that you won't find anywhere else. I think you'll love it too!\n";

/* Auto Downloads Setting - Auto download on follow of a blog*/
"settings_auto_downloads_on_follow" = "On Follow";