Skip to content

Commit

Permalink
Check for logged in user state and reset button if the feature flag e…
Browse files Browse the repository at this point in the history
…nables later
  • Loading branch information
danielebogo committed Nov 1, 2024
1 parent b3ce3d4 commit b239de6
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions podcasts/UpNextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,7 @@ class UpNextViewController: UIViewController, UIGestureRecognizerDelegate {
remainingLabel.style = .primaryText02
remainingLabel.themeOverride = themeOverride

if FeatureFlag.upNextShuffle.enabled {
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: Constants.Notifications.themeChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(subscriptionStatusDidChange), name: ServerNotifications.subscriptionStatusChanged, object: nil)
themeDidChange()
if SubscriptionHelper.hasActiveSubscription() {
shuffleButton.isSelected = Settings.upNextShuffleEnabled()
}
shuffleButton.addTarget(self, action: #selector(shuffleButtonTapped), for: .touchUpInside)
} else {
clearQueueButton.setTitle(L10n.queueClearQueue, for: .normal)
clearQueueButton.setTitleColor(AppTheme.colorForStyle(.primaryText02, themeOverride: themeOverride), for: .normal)
clearQueueButton.setTitleColor(AppTheme.colorForStyle(.primaryText02, themeOverride: themeOverride).withAlphaComponent(0.5), for: .disabled)
clearQueueButton.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .bold)
clearQueueButton.addTarget(self, action: #selector(clearQueueTapped), for: .touchUpInside)
}
setupActionButtonsIfNecessary()

contentInseter.setupInsetAdjustmentsForMiniPlayer(scrollView: upNextTable)

Expand All @@ -169,7 +155,10 @@ class UpNextViewController: UIViewController, UIGestureRecognizerDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateNavBarButtons()
themeDidChange()
setupActionButtonsIfNecessary()
if FeatureFlag.upNextShuffle.enabled {
themeDidChange()
}
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -230,7 +219,7 @@ class UpNextViewController: UIViewController, UIGestureRecognizerDelegate {
}

@objc private func themeDidChange() {
if !SubscriptionHelper.hasActiveSubscription() {
if !SubscriptionHelper.hasActiveSubscription() || !SyncManager.isUserLoggedIn() {
shuffleButton.setImage(UIImage(named: "shuffle-plus"), for: .normal)
} else {
let unselected = UIImage(named: "shuffle")?.withTintColor(AppTheme.colorForStyle(.primaryIcon02, themeOverride: themeOverride), renderingMode: .alwaysOriginal)
Expand All @@ -243,11 +232,33 @@ class UpNextViewController: UIViewController, UIGestureRecognizerDelegate {
@objc private func subscriptionStatusDidChange() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
if FeatureFlag.upNextShuffle.enabled {
// Update UI
setupActionButtonsIfNecessary()
themeDidChange()
updateNavBarButtons()
reloadTable()
}
}
}

// Update UI
private func setupActionButtonsIfNecessary() {
if FeatureFlag.upNextShuffle.enabled {
guard shuffleButton.allTargets.isEmpty else { return }
NotificationCenter.default.addObserver(self, selector: #selector(themeDidChange), name: Constants.Notifications.themeChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(subscriptionStatusDidChange), name: ServerNotifications.subscriptionStatusChanged, object: nil)
themeDidChange()
updateNavBarButtons()
reloadTable()
if SubscriptionHelper.hasActiveSubscription() {
shuffleButton.isSelected = Settings.upNextShuffleEnabled()
}
shuffleButton.addTarget(self, action: #selector(shuffleButtonTapped), for: .touchUpInside)
} else {
guard clearQueueButton.allTargets.isEmpty else { return }
clearQueueButton.setTitle(L10n.queueClearQueue, for: .normal)
clearQueueButton.setTitleColor(AppTheme.colorForStyle(.primaryText02, themeOverride: themeOverride), for: .normal)
clearQueueButton.setTitleColor(AppTheme.colorForStyle(.primaryText02, themeOverride: themeOverride).withAlphaComponent(0.5), for: .disabled)
clearQueueButton.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .bold)
clearQueueButton.addTarget(self, action: #selector(clearQueueTapped), for: .touchUpInside)
}
}

Expand Down

0 comments on commit b239de6

Please sign in to comment.