Improves handling of non-patron Patreon accounts

This commit is contained in:
Riley Testut
2019-09-12 13:08:38 -07:00
parent 502a5488b0
commit 6214f1044b
2 changed files with 46 additions and 32 deletions

View File

@@ -25,7 +25,7 @@ extension PatreonAPI
} }
var data: Data var data: Data
var included: [PatronResponse] var included: [PatronResponse]?
} }
} }
@@ -52,7 +52,7 @@ class PatreonAccount: NSManagedObject, Fetchable
self.name = response.data.attributes.full_name self.name = response.data.attributes.full_name
self.firstName = response.data.attributes.first_name self.firstName = response.data.attributes.first_name
if let patronResponse = response.included.first if let patronResponse = response.included?.first
{ {
let patron = Patron(response: patronResponse) let patron = Patron(response: patronResponse)
self.isPatron = (patron.status == .active) self.isPatron = (patron.status == .active)

View File

@@ -104,48 +104,62 @@ private extension PatreonViewController
headerView.supportButton.addTarget(self, action: #selector(PatreonViewController.openPatreonURL(_:)), for: .primaryActionTriggered) headerView.supportButton.addTarget(self, action: #selector(PatreonViewController.openPatreonURL(_:)), for: .primaryActionTriggered)
headerView.accountButton.removeTarget(self, action: nil, for: .primaryActionTriggered) headerView.accountButton.removeTarget(self, action: nil, for: .primaryActionTriggered)
let defaultSupportButtonTitle = NSLocalizedString("Become a patron", comment: "")
let isPatronSupportButtonTitle = NSLocalizedString("View Patreon", comment: "")
let defaultText = NSLocalizedString("""
Hey y'all,
You can support future development of my apps by donating to me on Patreon. In return, you'll gain access to beta versions of all of my apps and be among the first to try the latest features.
Thanks for all your support 💜
Riley
""", comment: "")
let isPatronText = NSLocalizedString("""
Hey ,
Youre the best. Your account was linked successfully, so you now have access to the beta versions of all of my apps. You can find them all in the Browse tab.
Thanks for all of your support. Enjoy!
Riley
""", comment: "")
if let account = DatabaseManager.shared.patreonAccount(), PatreonAPI.shared.isAuthenticated if let account = DatabaseManager.shared.patreonAccount(), PatreonAPI.shared.isAuthenticated
{ {
headerView.accountButton.addTarget(self, action: #selector(PatreonViewController.signOut(_:)), for: .primaryActionTriggered) headerView.accountButton.addTarget(self, action: #selector(PatreonViewController.signOut(_:)), for: .primaryActionTriggered)
headerView.supportButton.setTitle(NSLocalizedString("View Patreon", comment: ""), for: .normal)
headerView.accountButton.setTitle(String(format: NSLocalizedString("Unlink %@", comment: ""), account.name), for: .normal) headerView.accountButton.setTitle(String(format: NSLocalizedString("Unlink %@", comment: ""), account.name), for: .normal)
let text = """ if account.isPatron
Hey , {
headerView.supportButton.setTitle(isPatronSupportButtonTitle, for: .normal)
Youre the best. Your account was linked successfully, so you now have access to the beta versions of all of my apps. You can find them all in the Browse tab. let font = UIFont.systemFont(ofSize: 16)
Thanks for all of your support. Enjoy! let attributedText = NSMutableAttributedString(string: isPatronText, attributes: [.font: font,
Riley .foregroundColor: UIColor.white])
"""
let font = UIFont.systemFont(ofSize: 16) let boldedName = NSAttributedString(string: account.firstName ?? account.name,
attributes: [.font: UIFont.boldSystemFont(ofSize: font.pointSize),
.foregroundColor: UIColor.white])
attributedText.insert(boldedName, at: 4)
let attributedText = NSMutableAttributedString(string: text, attributes: [.font: font, headerView.textView.attributedText = attributedText
.foregroundColor: UIColor.white]) }
else
let boldedName = NSAttributedString(string: account.firstName ?? account.name, attributes: [.font: UIFont.boldSystemFont(ofSize: font.pointSize), {
.foregroundColor: UIColor.white]) headerView.supportButton.setTitle(defaultSupportButtonTitle, for: .normal)
attributedText.insert(boldedName, at: 4) headerView.textView.text = defaultText
}
headerView.textView.attributedText = attributedText
} }
else else
{ {
headerView.accountButton.addTarget(self, action: #selector(PatreonViewController.authenticate(_:)), for: .primaryActionTriggered) headerView.accountButton.addTarget(self, action: #selector(PatreonViewController.authenticate(_:)), for: .primaryActionTriggered)
headerView.supportButton.setTitle(NSLocalizedString("Become a patron", comment: ""), for: .normal) headerView.supportButton.setTitle(defaultSupportButtonTitle, for: .normal)
headerView.accountButton.setTitle(NSLocalizedString("Link Patreon account", comment: ""), for: .normal) headerView.accountButton.setTitle(NSLocalizedString("Link Patreon account", comment: ""), for: .normal)
headerView.textView.text = """ headerView.textView.text = defaultText
Hey y'all,
If you'd like to support my work, you can donate here. In return, you'll gain access to beta versions of all of my apps and be among the first to try the latest features.
Thanks for all your support 💜
Riley
"""
} }
} }
} }