Skip to content

Commit

Permalink
Analytics audit: Add missing sleep timer settings (#2698)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioEstevao authored Jan 24, 2025
2 parents 7fa1112 + bf855cf commit db1e1ce
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-----
- Use new Share UI for bookmarks sharing [#2656](https://github.com/Automattic/pocket-casts-ios/pull/2656)
- Remove the option to share bookmarks from users file [#2661](https://github.com/Automattic/pocket-casts-ios/pull/2661)
- Add direct access to sleep timer settings from player [#2698](https://github.com/Automattic/pocket-casts-ios/pull/2698)

7.80
-----
Expand Down
1 change: 1 addition & 0 deletions podcasts/Analytics/AnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ enum AnalyticsEvent: String {
case playerSleepTimerExtended
case playerSleepTimerCancelled
case playerSleepTimerRestarted
case playerSleepTimerSettingsTapped

// MARK: - Player: Shelf

Expand Down
16 changes: 15 additions & 1 deletion podcasts/GeneralSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class GeneralSettingsViewController: PCViewController, UITableViewDelegate, UITa
private let switchCellId = "SwitchCell"
private let disclosureCellId = "DisclosureCell"

var scrollToRow: TableRow?

let debounce = Debounce(delay: Constants.defaultDebounceTime)

private enum TableRow { case skipForward, skipBack, keepScreenAwake, openPlayer, intelligentPlaybackResumption, defaultRowAction, extraMediaActions, defaultAddToUpNextSwipe, defaultGrouping, defaultArchive, playUpNextOnTap, legacyBluetooth, multiSelectGesture, openLinksInBrowser, publishChapterTitles, autoplay, autoRestartSleepTimer, shakeToRestartSleepTimer, isLockScreenScrubberDisabled }
enum TableRow { case skipForward, skipBack, keepScreenAwake, openPlayer, intelligentPlaybackResumption, defaultRowAction, extraMediaActions, defaultAddToUpNextSwipe, defaultGrouping, defaultArchive, playUpNextOnTap, legacyBluetooth, multiSelectGesture, openLinksInBrowser, publishChapterTitles, autoplay, autoRestartSleepTimer, shakeToRestartSleepTimer, isLockScreenScrubberDisabled }
private var tableData: [[TableRow]] = [[.defaultRowAction, .defaultGrouping, .defaultArchive, .defaultAddToUpNextSwipe, .openLinksInBrowser], [.skipForward, .skipBack, .keepScreenAwake, .openPlayer, .isLockScreenScrubberDisabled, .intelligentPlaybackResumption], [.autoRestartSleepTimer], [.shakeToRestartSleepTimer], [.playUpNextOnTap], [.extraMediaActions], [.legacyBluetooth], [.multiSelectGesture], [.publishChapterTitles], [.autoplay]]

@IBOutlet var settingsTable: UITableView! {
Expand All @@ -29,6 +31,10 @@ class GeneralSettingsViewController: PCViewController, UITableViewDelegate, UITa
insetAdjuster.setupInsetAdjustmentsForMiniPlayer(scrollView: settingsTable)

Analytics.track(.settingsGeneralShown)

if let scrollToRow {
self.scrollToRow(scrollToRow)
}
}

override func viewDidAppear(_ animated: Bool) {
Expand All @@ -43,6 +49,14 @@ class GeneralSettingsViewController: PCViewController, UITableViewDelegate, UITa
}
}

private func scrollToRow(_ row: TableRow) {
for (sectionIndex, section) in tableData.enumerated() {
if let row = section.firstIndex(of: row) {
settingsTable.scrollToRow(at: IndexPath(row: row, section: sectionIndex), at: .middle, animated: true)
}
}
}

// MARK: - UITableView Methods

func numberOfSections(in tableView: UITableView) -> Int {
Expand Down
21 changes: 20 additions & 1 deletion podcasts/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Combine
import PocketCastsUtils

class MainTabBarController: UITabBarController, NavigationProtocol {

enum Tab { case podcasts, filter, discover, profile, upNext }

var pcTabs = [Tab]()
Expand Down Expand Up @@ -158,7 +159,7 @@ class MainTabBarController: UITabBarController, NavigationProtocol {

private func fixTarBarTraitCollectionOnIpadForiOS18() {
if #available(iOS 18.0, *),
UIDevice.current.userInterfaceIdiom == .pad {
UIDevice.current.userInterfaceIdiom == .pad {
traitOverrides.horizontalSizeClass = .compact
if let rootHorizontalSizeClass = view.window?.traitCollection.horizontalSizeClass {
tabBar.traitOverrides.horizontalSizeClass = rootHorizontalSizeClass
Expand Down Expand Up @@ -478,6 +479,24 @@ class MainTabBarController: UITabBarController, NavigationProtocol {
}
}

func showGeneralSettings(row: GeneralSettingsViewController.TableRow?) {
let state = NavigationManager.sharedManager.miniPlayer?.playerOpenState

// Dismiss any presented views if the player is not already open/dismissing since it will dismiss itself
if state != .open, state != .animating {
dismissPresentedViewController()
}

switchToTab(.profile)
if let navController = selectedViewController as? UINavigationController {
navController.popToRootViewController(animated: false)
navController.pushViewController(SettingsViewController(), animated: false)
let generalSettingsController = GeneralSettingsViewController()
generalSettingsController.scrollToRow = row
navController.pushViewController(generalSettingsController, animated: true)
}
}

func showSupporterSignIn(podcastInfo: PodcastInfo) {
let supporterVC = SupporterGratitudeViewController(podcastInfo: podcastInfo)
let controller = view.window?.rootViewController
Expand Down
5 changes: 5 additions & 0 deletions podcasts/NavigationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class NavigationManager {
static let endOfYearStories = "endOfYearStories"
static let onboardingFlow = "onboardingFlow"

static let settingsGeneralKey = "generalSettingsPage"
static let settingsGeneralRowKey = "generalSettingsRow"

static let sharedManager = NavigationManager()

private weak var mainController: NavigationProtocol?
Expand Down Expand Up @@ -210,6 +213,8 @@ class NavigationManager {
} else if place == NavigationManager.onboardingFlow {
let flow: OnboardingFlow.Flow? = data?["flow"] as? OnboardingFlow.Flow
mainController?.showOnboardingFlow(flow: flow)
} else if place == NavigationManager.settingsGeneralKey {
mainController?.showGeneralSettings(row: data?[NavigationManager.settingsGeneralRowKey] as? GeneralSettingsViewController.TableRow)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions podcasts/NavigationProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protocol NavigationProtocol: AnyObject {
func showPromotionFinishedAcknowledge()
func showProfilePage()
func showHeadphoneSettings()
func showGeneralSettings(row: GeneralSettingsViewController.TableRow?)
func showRedeemGuestPass(url: URL)

func showSupporterSignIn(podcastInfo: PodcastInfo)
Expand Down
10 changes: 10 additions & 0 deletions podcasts/SleepTimerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import PocketCastsUtils
import UIKit

class SleepTimerViewController: SimpleNotificationsViewController {

@IBOutlet var settingsBtn: UIButton!

@IBOutlet var plusFiveBtn: UIButton! {
didSet {
plusFiveBtn.setTitle(L10n.sleepTimerAdd5Mins, for: .normal)
Expand Down Expand Up @@ -210,6 +213,8 @@ class SleepTimerViewController: SimpleNotificationsViewController {

customTimeStepper.tintColor = ThemeColor.playerContrast01()
customEpisodeStepper.tintColor = ThemeColor.playerContrast01()

settingsBtn.tintColor = ThemeColor.playerContrast02()
}

private func updateSleepRemainingTime() {
Expand Down Expand Up @@ -272,6 +277,11 @@ class SleepTimerViewController: SimpleNotificationsViewController {

// MARK: - Sleep Timer Actions

@IBAction func settingsTapped(_ sender: Any) {
Analytics.track(.playerSleepTimerSettingsTapped)
NavigationManager.sharedManager.navigateTo(NavigationManager.settingsGeneralKey, data: [NavigationManager.settingsGeneralRowKey: GeneralSettingsViewController.TableRow.autoRestartSleepTimer])
}

@IBAction func fiveMinutesTapped(_ sender: Any) {
PlaybackManager.shared.setSleepTimerInterval(5.minutes)
dismiss(animated: true, completion: nil)
Expand Down
Loading

0 comments on commit db1e1ce

Please sign in to comment.