Add promoting alert for subreddit
This commit is contained in:
parent
b6d430f106
commit
62d1c2d882
|
@ -58,6 +58,13 @@ extension UIAlertController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addAction(_ title: String, handler: @escaping () -> Void) {
|
||||||
|
let action = UIAlertAction(title: title, style: .default) { (action) in
|
||||||
|
handler()
|
||||||
|
}
|
||||||
|
addAction(action)
|
||||||
|
}
|
||||||
|
|
||||||
func addDestructiveAction(_ title: String, handler: @escaping () -> Void) {
|
func addDestructiveAction(_ title: String, handler: @escaping () -> Void) {
|
||||||
let action = UIAlertAction(title: title, style: .destructive) { (action) in
|
let action = UIAlertAction(title: title, style: .destructive) { (action) in
|
||||||
handler()
|
handler()
|
||||||
|
|
|
@ -35,7 +35,9 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
||||||
private var hostProfiles: [HostConnectionProfile] = []
|
private var hostProfiles: [HostConnectionProfile] = []
|
||||||
|
|
||||||
private var availableProviderNames: [Infrastructure.Name]?
|
private var availableProviderNames: [Infrastructure.Name]?
|
||||||
|
|
||||||
|
private var didShowSubreddit = false
|
||||||
|
|
||||||
// MARK: TableModelHost
|
// MARK: TableModelHost
|
||||||
|
|
||||||
let model: TableModel<SectionType, RowType> = {
|
let model: TableModel<SectionType, RowType> = {
|
||||||
|
@ -103,6 +105,25 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
||||||
service.delegate = self
|
service.delegate = self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
super.viewDidAppear(animated)
|
||||||
|
|
||||||
|
if !didShowSubreddit && !TransientStore.shared.didHandleSubreddit {
|
||||||
|
didShowSubreddit = true
|
||||||
|
|
||||||
|
let alert = Macros.alert(L10n.About.Cells.DiscussReddit.caption, L10n.Reddit.message)
|
||||||
|
alert.addDefaultAction(L10n.Reddit.Buttons.subscribe) {
|
||||||
|
TransientStore.shared.didHandleSubreddit = true
|
||||||
|
self.subscribeSubreddit()
|
||||||
|
}
|
||||||
|
alert.addAction(L10n.Reddit.Buttons.never) {
|
||||||
|
TransientStore.shared.didHandleSubreddit = true
|
||||||
|
}
|
||||||
|
alert.addCancelAction(L10n.Reddit.Buttons.remind)
|
||||||
|
present(alert, animated: true, completion: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
|
||||||
if let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) {
|
if let cell = sender as? UITableViewCell, let indexPath = tableView.indexPath(for: cell) {
|
||||||
return model.row(at: indexPath) == .profile
|
return model.row(at: indexPath) == .profile
|
||||||
|
@ -227,6 +248,10 @@ class OrganizerViewController: UITableViewController, TableModelHost {
|
||||||
alert.addCancelAction(L10n.Global.cancel)
|
alert.addCancelAction(L10n.Global.cancel)
|
||||||
present(alert, animated: true, completion: nil)
|
present(alert, animated: true, completion: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func subscribeSubreddit() {
|
||||||
|
UIApplication.shared.open(AppConstants.URLs.subreddit, options: [:], completionHandler: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: -
|
// MARK: -
|
||||||
|
|
|
@ -27,6 +27,11 @@
|
||||||
"global.cancel" = "Cancel";
|
"global.cancel" = "Cancel";
|
||||||
"global.next" = "Next";
|
"global.next" = "Next";
|
||||||
|
|
||||||
|
"reddit.message" = "Did you know that Passepartout has a subreddit? Subscribe for updates or to discuss issues, features, new platforms or whatever you like.\n\nIt's also a great way to show you care about this project.";
|
||||||
|
"reddit.buttons.subscribe" = "Subscribe now!";
|
||||||
|
"reddit.buttons.remind" = "Remind me later";
|
||||||
|
"reddit.buttons.never" = "Don't ask again";
|
||||||
|
|
||||||
"organizer.sections.providers.header" = "Networks";
|
"organizer.sections.providers.header" = "Networks";
|
||||||
"organizer.sections.providers.footer" = "Here you find a few public infrastructures offering preset configuration profiles.";
|
"organizer.sections.providers.footer" = "Here you find a few public infrastructures offering preset configuration profiles.";
|
||||||
"organizer.sections.hosts.header" = "Hosts";
|
"organizer.sections.hosts.header" = "Hosts";
|
||||||
|
|
|
@ -29,12 +29,25 @@ import SwiftyBeaver
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
||||||
class TransientStore {
|
class TransientStore {
|
||||||
|
private struct Keys {
|
||||||
|
static let didHandleSubreddit = "DidHandleSubreddit"
|
||||||
|
}
|
||||||
|
|
||||||
static let shared = TransientStore()
|
static let shared = TransientStore()
|
||||||
|
|
||||||
private let servicePath: URL
|
private let servicePath: URL
|
||||||
|
|
||||||
let service: ConnectionService
|
let service: ConnectionService
|
||||||
|
|
||||||
|
var didHandleSubreddit: Bool {
|
||||||
|
get {
|
||||||
|
return UserDefaults.standard.bool(forKey: Keys.didHandleSubreddit)
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
UserDefaults.standard.set(newValue, forKey: Keys.didHandleSubreddit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
servicePath = FileManager.default.userURL(
|
servicePath = FileManager.default.userURL(
|
||||||
for: .documentDirectory,
|
for: .documentDirectory,
|
||||||
|
|
|
@ -395,6 +395,20 @@ internal enum L10n {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal enum Reddit {
|
||||||
|
/// Did you know that Passepartout has a subreddit? Subscribe for updates or to discuss issues, features, new platforms or whatever you like.\n\nIt's also a great way to show you care about this project.
|
||||||
|
internal static let message = L10n.tr("Localizable", "reddit.message")
|
||||||
|
|
||||||
|
internal enum Buttons {
|
||||||
|
/// Don't ask again
|
||||||
|
internal static let never = L10n.tr("Localizable", "reddit.buttons.never")
|
||||||
|
/// Remind me later
|
||||||
|
internal static let remind = L10n.tr("Localizable", "reddit.buttons.remind")
|
||||||
|
/// Subscribe now!
|
||||||
|
internal static let subscribe = L10n.tr("Localizable", "reddit.buttons.subscribe")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal enum Service {
|
internal enum Service {
|
||||||
|
|
||||||
internal enum Alerts {
|
internal enum Alerts {
|
||||||
|
|
Loading…
Reference in New Issue