Skip to content

Commit

Permalink
Merge pull request #710 from OneBusAway/cleave-features
Browse files Browse the repository at this point in the history
Properly separate optional features into config files
  • Loading branch information
aaronbrethorst committed Jan 17, 2024
2 parents cb396e0 + 9cd5f30 commit c122b8d
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xEC",
"green" : "0x96",
"red" : "0x45"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xEC",
"green" : "0x96",
"red" : "0x45"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 3 additions & 3 deletions Apps/KiedyBus/Assets.xcassets/Colors/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
9 changes: 1 addition & 8 deletions Apps/OneBusAway/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,9 @@ targets:
- path: Apps/OneBusAway
name: App
group: OneBusAway
- path: Apps/Shared/Analytics
name: Analytics
group: OneBusAway
- path: Apps/Shared/CommonClient
name: Common
group: OneBusAway
- path: Apps/Shared/OneSignal
name: OneSignal
group: OneBusAway
dependencies:
- package: OneSignal
entitlements:
path: Apps/OneBusAway/OneBusAway.entitlements
properties:
Expand Down Expand Up @@ -107,6 +99,7 @@ include:
- path: Apps/Shared/app_shared.yml
- path: Apps/Shared/analytics_fx_config.yml
- path: Apps/Shared/push_config.yml
- path: Apps/Shared/donations_config.yml
- path: OBAKitCore/project.yml
- path: OBAKit/project.yml
- path: OBAKitTests/project.yml
Expand Down
4 changes: 4 additions & 0 deletions Apps/Shared/analytics_fx_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ targets:
product: FirebaseAnalytics
- package: Firebase
product: FirebaseCrashlytics
sources:
- path: ./Analytics
name: Analytics
group: Features
6 changes: 0 additions & 6 deletions Apps/Shared/app_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ packages:
MarqueeLabel:
url: https://github.com/cbpowell/MarqueeLabel.git
exactVersion: 4.3.0
OneSignal:
url: https://github.com/OneSignal/OneSignal-iOS-SDK.git
minorVersion: 3.11.2
stripe-ios-spm:
url: https://github.com/stripe/stripe-ios-spm.git
minorVersion: 23.18.2
SwiftProtobuf:
url: https://github.com/apple/swift-protobuf.git
minorVersion: 1.19.1
19 changes: 19 additions & 0 deletions Apps/Shared/donations_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
targets:
App:
info:
path: Apps/OneBusAway/Info.plist
properties:
NSCameraUsageDescription: This app uses Stripe to process credit cards. You can use Stripe to scan your credit card number with your camera.
OBAKit:
dependencies:
- package: stripe-ios-spm
product: Stripe
- package: stripe-ios-spm
product: StripeApplePay
- package: stripe-ios-spm
product: StripePaymentSheet

packages:
stripe-ios-spm:
url: https://github.com/stripe/stripe-ios-spm.git
minorVersion: 23.18.2
13 changes: 12 additions & 1 deletion Apps/Shared/push_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@ targets:
SystemCapabilities:
com.apple.Push:
enabled: 1
dependencies:
- package: OneSignal
entitlements:
properties:
aps-environment: development
info:
properties:
UIBackgroundModes:
- remote-notification
- remote-notification
sources:
- path: ./OneSignal
name: OneSignal
group: Features

packages:
OneSignal:
url: https://github.com/OneSignal/OneSignal-iOS-SDK.git
minorVersion: 3.11.2
4 changes: 4 additions & 0 deletions OBAKit/Donations/DonationLearnMoreView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import SwiftUI
import UIKit
import OBAKitCore

#if canImport(Stripe)

enum DonationRecurrence: String, CaseIterable, Identifiable {
case oneTime
case recurring
Expand Down Expand Up @@ -241,3 +243,5 @@ struct DonationLearnMoreView: View {
// abxoxo - needs environment object added.
// DonationLearnMoreView()
// }

#endif
19 changes: 6 additions & 13 deletions OBAKit/Donations/DonationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,12 @@
// Created by Aaron Brethorst on 11/11/23.
//

#if canImport(Stripe)
import StripePaymentSheet
import SwiftUI
import OBAKitCore
import PassKit

extension PaymentSheetResult: Equatable {
public static func == (lhs: PaymentSheetResult, rhs: PaymentSheetResult) -> Bool {
switch (lhs, rhs) {
case (.completed, .completed), (.canceled, .canceled):
return true
case (.failed(let lhsError), .failed(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
default:
return false
}
}
}

/// `DonationModel` is an `ObservableObject` for use in SwiftUI that manages the donation process.
///
/// It manages the donation data, communicates with the server, and provides updates to the UI.
Expand Down Expand Up @@ -239,3 +227,8 @@ class DonationModel: ObservableObject {
}
}
}

#else
class DonationModel: ObservableObject {
}
#endif
37 changes: 33 additions & 4 deletions OBAKit/Donations/DonationsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@

import Foundation
import OBAKitCore
import StripeApplePay
import SwiftUI

public enum DonationsUserDefaultsKeys: String, RawRepresentable {
case forceStripeTestModeDefaultsKey = "forceStripeTestMode"
}

#if canImport(Stripe)
import StripeApplePay

/// Manages the visibility of donation requests.
public class DonationsManager {

Expand All @@ -29,7 +35,7 @@ public class DonationsManager {
self.analytics = analytics

self.userDefaults.register(
defaults: [DonationsManager.forceStripeTestModeDefaultsKey: false]
defaults: [DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue: false]
)
}

Expand All @@ -44,7 +50,6 @@ public class DonationsManager {
private let userDefaults: UserDefaults
private static let donationRequestDismissedDateKey = "donationRequestDismissedDateKey"
private static let donationRequestReminderDateKey = "donationRequestReminderDateKey"
public static let forceStripeTestModeDefaultsKey = "forceStripeTestMode"

// MARK: - Dismiss Donations Request

Expand Down Expand Up @@ -103,7 +108,7 @@ public class DonationsManager {
#if DEBUG
return true
#else
return userDefaults.bool(forKey: DonationsManager.forceStripeTestModeDefaultsKey)
return userDefaults.bool(forKey: DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue)
#endif
}

Expand Down Expand Up @@ -161,3 +166,27 @@ public class DonationsManager {
.environmentObject(AnalyticsModel(analytics))
}
}
#else
public class DonationsManager {
public init(
bundle: Bundle,
userDefaults: UserDefaults,
obacoService: ObacoAPIService?,
analytics: Analytics?
) {}

public var donationsEnabled: Bool {
false
}

public var shouldRequestDonations: Bool {
false
}

public func dismissDonationsRequests() {}

public func remindUserLater() {}

public func refreshStripePublishableKey() {}
}
#endif
23 changes: 23 additions & 0 deletions OBAKit/Donations/StripeExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// StripeExtensions.swift
// OBAKit
//
// Created by Aaron Brethorst on 1/16/24.
//

#if canImport(Stripe)
import StripePaymentSheet

extension PaymentSheetResult: Equatable {
public static func == (lhs: PaymentSheetResult, rhs: PaymentSheetResult) -> Bool {
switch (lhs, rhs) {
case (.completed, .completed), (.canceled, .canceled):
return true
case (.failed(let lhsError), .failed(let rhsError)):
return lhsError.localizedDescription == rhsError.localizedDescription
default:
return false
}
}
}
#endif
8 changes: 8 additions & 0 deletions OBAKit/Orchestration/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import OBAKitCore
import SafariServices
import MapKit
import SwiftUI
#if canImport(Stripe)
import StripeApplePay
#endif

// MARK: - Protocols

Expand Down Expand Up @@ -289,10 +291,12 @@ public class Application: CoreApplication, PushServiceDelegate {
}

private func presentDonationUI(_ presentingController: UIViewController, id: String?) {
#if canImport(Stripe)
analytics?.reportEvent?(.userAction, label: AnalyticsLabels.donationPushNotificationTapped, value: id)

let learnMoreView = donationsManager.buildLearnMoreView(presentingController: presentingController, donationPushNotificationID: id)
presentingController.present(UIHostingController(rootView: learnMoreView), animated: true)
#endif
}

// MARK: - Alerts Store
Expand Down Expand Up @@ -414,9 +418,11 @@ public class Application: CoreApplication, PushServiceDelegate {

@MainActor
@objc public func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
#if canImport(Stripe)
if StripeAPI.handleURLCallback(with: url) {
return true
}
#endif

guard let scheme = Bundle.main.extensionURLScheme else {
return false
Expand All @@ -437,8 +443,10 @@ public class Application: CoreApplication, PushServiceDelegate {
override public func apiServicesRefreshed() {
super.apiServicesRefreshed()

#if canImport(Stripe)
donationsManager.obacoService = obacoService
donationsManager.refreshStripePublishableKey()
#endif
}

// MARK: - Appearance and Themes
Expand Down
3 changes: 3 additions & 0 deletions OBAKit/Settings/MoreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ public class MoreViewController: UIViewController,

private func showDonationUI() {
guard application.donationsManager.donationsEnabled else { return }

#if canImport(Stripe)
let view = application.donationsManager.buildLearnMoreView(presentingController: self)
let hostingController = UIHostingController(rootView: view)
present(hostingController, animated: true)
#endif
}

// MARK: Updates and alerts section
Expand Down
20 changes: 11 additions & 9 deletions OBAKit/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SettingsViewController: FormViewController {
AgencyAlertsStore.UserDefaultKeys.displayRegionalTestAlerts: application.userDefaults.bool(forKey: AgencyAlertsStore.UserDefaultKeys.displayRegionalTestAlerts),
RegionsService.alwaysRefreshRegionsOnLaunchUserDefaultsKey: application.userDefaults.bool(forKey: RegionsService.alwaysRefreshRegionsOnLaunchUserDefaultsKey),
MapRegionManager.mapViewShowsStopAnnotationLabelsDefaultsKey: application.userDefaults.bool(forKey: MapRegionManager.mapViewShowsStopAnnotationLabelsDefaultsKey),
DonationsManager.forceStripeTestModeDefaultsKey: application.userDefaults.bool(forKey: DonationsManager.forceStripeTestModeDefaultsKey),
DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue: application.userDefaults.bool(forKey: DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue),
debugModeEnabled: application.userDataStore.debugMode
])
}
Expand Down Expand Up @@ -110,8 +110,8 @@ class SettingsViewController: FormViewController {
application.userDefaults.set(false, forKey: RegionsService.alwaysRefreshRegionsOnLaunchUserDefaultsKey)
}

if let forceStripeTestMode = values[DonationsManager.forceStripeTestModeDefaultsKey] as? Bool {
application.userDefaults.set(forceStripeTestMode, forKey: DonationsManager.forceStripeTestModeDefaultsKey)
if application.donationsManager.donationsEnabled, let forceStripeTestMode = values[DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue] as? Bool {
application.userDefaults.set(forceStripeTestMode, forKey: DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue)
application.donationsManager.refreshStripePublishableKey()
}
}
Expand Down Expand Up @@ -235,12 +235,14 @@ class SettingsViewController: FormViewController {
}
}

section <<< SwitchRow {
$0.tag = DonationsManager.forceStripeTestModeDefaultsKey
$0.title = OBALoc("settings_controller.debug_section.force_stripe_test_mode", value: "Force Stripe test mode", comment: "Settings > Debug section > Force Stripe test mode")
$0.hidden = Condition.function([debugModeEnabled], { form in
return !((form.rowBy(tag: self.debugModeEnabled) as? SwitchRow)?.value ?? false)
})
if application.donationsManager.donationsEnabled {
section <<< SwitchRow {
$0.tag = DonationsUserDefaultsKeys.forceStripeTestModeDefaultsKey.rawValue
$0.title = OBALoc("settings_controller.debug_section.force_stripe_test_mode", value: "Force Stripe test mode", comment: "Settings > Debug section > Force Stripe test mode")
$0.hidden = Condition.function([debugModeEnabled], { form in
return !((form.rowBy(tag: self.debugModeEnabled) as? SwitchRow)?.value ?? false)
})
}
}

section <<< TextRow {
Expand Down
Loading

0 comments on commit c122b8d

Please sign in to comment.