Skip to content

Commit

Permalink
Add a donation UI to the more controller
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed Nov 20, 2023
1 parent 9a06c11 commit e6fecb6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
13 changes: 13 additions & 0 deletions OBAKit/Donations/DonationsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import OBAKitCore

/// Manages the visibility of donation requests.
public class DonationsManager {
Expand Down Expand Up @@ -79,4 +80,16 @@ public class DonationsManager {

return donationRequestDismissedDate == nil
}

// MARK: - UI

public static func buildDonationThankYouAlert() -> UIAlertController {
let alert = UIAlertController(
title: Strings.donationThankYouTitle,
message: Strings.donationThankYouBody,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.dismiss, style: .default))

return alert
}
}
21 changes: 18 additions & 3 deletions OBAKit/Settings/MoreViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,29 @@ public class MoreViewController: UIViewController,
"more_controller.donate_description",
value: "Your support helps us improve OneBusAway",
comment: "The call to action for the More controller's donate buton"),
onSelectAction: { _ in
let url = URL(string: "https://www.transifex.com/open-transit-software-foundation/onebusaway-ios/")!
self.application.open(url, options: [:], completionHandler: nil)
onSelectAction: { [weak self] _ in
self?.showDonationUI()
}
)
])
}

private func showDonationUI() {
guard let obacoService = application.obacoService else { return }
let donationModel = DonationModel(obacoService: obacoService, analytics: application.analytics)
let learnMoreView = DonationLearnMoreView { [weak self] donated in
guard donated else { return }

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self?.present(DonationsManager.buildDonationThankYouAlert(), animated: true)
}
}
.environmentObject(donationModel)
.environmentObject(AnalyticsModel(application.analytics))

present(UIHostingController(rootView: learnMoreView), animated: true)
}

// MARK: Updates and alerts section
var updatesAndAlertsSection: OBAListViewSection {
let header = OBALoc(
Expand Down
8 changes: 1 addition & 7 deletions OBAKit/Stops/StopViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,8 @@ public class StopViewController: UIViewController,
let learnMoreView = DonationLearnMoreView { [weak self] donated in
guard donated else { return }

let alert = UIAlertController(
title: OBALoc("donations.thank_you_alert.title", value: "Thank you for your support!", comment: "The title of the alert shown when the user donates."),
message: nil,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.dismiss, style: .default))

DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
self?.present(alert, animated: true)
self?.present(DonationsManager.buildDonationThankYouAlert(), animated: true)
self?.application.donationsManager.dismissDonationsRequests()
self?.refresh()
}
Expand Down
4 changes: 4 additions & 0 deletions OBAKitCore/Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class Strings: NSObject {

public static let donate = OBALoc("common.donate", value: "Donate", comment: "The verb 'to donate', as in to give money to a charitable cause.")

public static let donationThankYouTitle = OBALoc("common.donation_thank_you.title", value: "Thank you for your support!", comment: "Title of an alert to display to the user after they donate to OTSF")

public static let donationThankYouBody = OBALoc("common.donation_thank_you.body", value: "Your support will help us continue to improve OneBusAway.", comment: "The body of the message to display to the user after they donate to OTSF")

public static let confirmDelete = OBALoc("common.confirmdelete", value: "Confirm Delete", comment: "Asks the user to confirm a delete action. Typically this is showned when the user taps a 'delete' button on an important item.")

public static let dismiss = OBALoc("common.dismiss", value: "Dismiss", comment: "The verb 'to dismiss', as in to hide or get rid of something. Used as a button title on alerts.")
Expand Down

0 comments on commit e6fecb6

Please sign in to comment.