Skip to content

Commit

Permalink
Merge pull request #704 from OneBusAway/first-run-donations
Browse files Browse the repository at this point in the history
Make the donations UI work on first app launch
  • Loading branch information
aaronbrethorst authored Dec 16, 2023
2 parents 7696c57 + a923214 commit a30b0ac
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 1 addition & 3 deletions OBAKit/Donations/DonationsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class DonationsManager {
/// - Parameters:
/// - bundle: The application bundle. Usually, `Bundle.main`
/// - userDefaults: The user defaults object.
/// - obacoService: The Obaco API service.
/// - analytics: The Analytics object.
public init(
bundle: Bundle,
Expand All @@ -27,7 +26,6 @@ public class DonationsManager {
) {
self.bundle = bundle
self.userDefaults = userDefaults
self.obacoService = obacoService
self.analytics = analytics

self.userDefaults.register(
Expand All @@ -38,7 +36,7 @@ public class DonationsManager {
// MARK: - Data

private let bundle: Bundle
private let obacoService: ObacoAPIService?
var obacoService: ObacoAPIService?
private let analytics: Analytics?

// MARK: - User Defaults
Expand Down
10 changes: 8 additions & 2 deletions OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ public class Application: CoreApplication, PushServiceDelegate {
}

@objc public func application(_ application: UIApplication, didFinishLaunching options: [AnyHashable: Any]) {
donationsManager.refreshStripePublishableKey()

application.shortcutItems = nil

configurePushNotifications(launchOptions: options)
Expand Down Expand Up @@ -436,6 +434,13 @@ public class Application: CoreApplication, PushServiceDelegate {
return true
}

override public func apiServicesRefreshed() {
super.apiServicesRefreshed()

donationsManager.obacoService = obacoService
donationsManager.refreshStripePublishableKey()
}

// MARK: - Appearance and Themes

/// Sets default styles for several UIAppearance proxies in order to customize the app's look and feel
Expand All @@ -458,6 +463,7 @@ public class Application: CoreApplication, PushServiceDelegate {
}

// MARK: - Regions Management

public func regionsService(_ service: RegionsService, changedAutomaticRegionSelection value: Bool) {
let label = value ? AnalyticsLabels.setRegionAutomatically : AnalyticsLabels.setRegionManually
analytics?.reportEvent?(.userAction, label: label, value: nil)
Expand Down
2 changes: 1 addition & 1 deletion OBAKitCore/Extensions/UIKitExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public extension UIColor {
}

// MARK: - From UIColor to String

/// Generates a hex value from the receiver
///
/// The hex values _do not_ have leading `#` values.
Expand Down
15 changes: 13 additions & 2 deletions OBAKitCore/Orchestration/CoreApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,20 @@ open class CoreApplication: NSObject,
Task {
await regionsService.updateRegionsList()
}
refreshServices()
}

/// This function reloads the REST API and Obaco Services.
private func refreshServices() {
refreshRESTAPIService()
refreshObacoService()
apiServicesRefreshed()
}

/// Called after the REST API and Obaco Services have been reloaded.
/// The default implementation is a no-op.
open func apiServicesRefreshed() {
// nop
}

// MARK: - Agency Alerts
Expand Down Expand Up @@ -178,8 +190,7 @@ open class CoreApplication: NSObject,
}()

open func regionsService(_ service: RegionsService, willUpdateToRegion region: Region) {
refreshRESTAPIService()
refreshObacoService()
refreshServices()
}

open func regionsService(_ service: RegionsService, updatedRegion region: Region) {
Expand Down

0 comments on commit a30b0ac

Please sign in to comment.