From dacfc2c583c5dfc1529fcc0535e8a1cd43106af9 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Thu, 19 Jan 2017 11:10:20 -0500 Subject: [PATCH] RateKiwixAlert --- .../Setting/SettingController.swift | 38 ++++++++++++++----- Kiwix/Operations/UIProcedure.swift | 24 +++++++++--- Kiwix/Tools/StringTools.swift | 1 + 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Kiwix-iOS/Controller/Setting/SettingController.swift b/Kiwix-iOS/Controller/Setting/SettingController.swift index dff93623..326afabe 100644 --- a/Kiwix-iOS/Controller/Setting/SettingController.swift +++ b/Kiwix-iOS/Controller/Setting/SettingController.swift @@ -8,6 +8,7 @@ import UIKit import MessageUI +import ProcedureKit class SettingController: UITableViewController { @@ -52,28 +53,41 @@ class SettingController: UITableViewController { } else { UIQueue.shared.add(operation: EmailNotConfiguredAlert(context: self)) } + case Localized.Setting.rateApp: + UIQueue.shared.add(operation: AlertProcedure.rateKiwix(context: self, userInitiated: true)) default: return } } + + override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { + guard section == tableView.numberOfSections - 1 else {return nil} + return String(format: Localized.Setting.version, Bundle.appShortVersion) + } + + override func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) { + guard section == tableView.numberOfSections - 1 else {return} + if let view = view as? UITableViewHeaderFooterView { + view.textLabel?.textAlignment = .center + } + } } extension Localized { class Setting { - static let title = NSLocalizedString("Setting", comment: "Setting view title") + static let title = NSLocalizedString("Setting", comment: "Setting table title") - static let fontSize = NSLocalizedString("Font Size", comment: "Setting view rows") - static let notifications = NSLocalizedString("Notifications", comment: "Setting view rows") - - static let feedback = NSLocalizedString("Email us your suggestions", comment: "Setting view rows") - static let rateApp = NSLocalizedString("Give Kiwix a Rate", comment: "Setting view rows") - - static let about = NSLocalizedString("About", comment: "Setting view rows") + static let fontSize = NSLocalizedString("Font Size", comment: "Setting table rows") + static let notifications = NSLocalizedString("Notifications", comment: "Setting table rows") + static let feedback = NSLocalizedString("Email us your suggestions", comment: "Setting table rows") + static let rateApp = NSLocalizedString("Give Kiwix a Rate", comment: "Setting table rows") + static let about = NSLocalizedString("About", comment: "Setting table rows") + static let version = NSLocalizedString("Kiwix for iOS v%@", comment: "Setting table footer") class Feedback { static let subject = NSLocalizedString(String(format: "Feedback: Kiwix for iOS %@", Bundle.appShortVersion), - comment: "Feedback view subject, %@ will be replaced by kiwix version string") + comment: "Feedback email composer subject, %@ will be replaced by kiwix version string") class Success { static let title = NSLocalizedString("Email Sent", comment: "Feedback success title") static let message = NSLocalizedString("Your Email was sent. We will get back to you shortly.", comment: "Feedback success message") @@ -86,6 +100,12 @@ extension Localized { static let title = NSLocalizedString("Email not sent", comment: "Feedback error title") } } + + class RateApp { + static let message = NSLocalizedString("Would you like to rate Kiwix in App Store?", comment: "Rate app alert message") + static let goToAppStore = NSLocalizedString("Go to App Store", comment: "Rate app alert action") + static let remindMeLater = NSLocalizedString("Remind Me Later", comment: "Rate app alert action") + } } } diff --git a/Kiwix/Operations/UIProcedure.swift b/Kiwix/Operations/UIProcedure.swift index 20b4d258..79809e0d 100644 --- a/Kiwix/Operations/UIProcedure.swift +++ b/Kiwix/Operations/UIProcedure.swift @@ -74,10 +74,22 @@ class EmailNotSentAlert: UIProcedure { } } -class RateKiwixAlert: UIProcedure { - let controller = UIAlertController(title: nil, message: nil, - preferredStyle: .alert) -// init (context: UIViewController) { -// -// } +extension AlertProcedure { + static func rateKiwix(context: UIViewController, userInitiated: Bool) -> AlertProcedure { + let alert = AlertProcedure(presentAlertFrom: context) + alert.title = Localized.Setting.rateApp + alert.message = Localized.Setting.RateApp.message + alert.add(actionWithTitle: Localized.Setting.RateApp.goToAppStore, style: .default) { _ in + let url = URL(string: "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=997079563&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8")! + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + if !userInitiated { + alert.add(actionWithTitle: Localized.Setting.RateApp.remindMeLater, style: .default, handler: { (alert, action) in + // clear launch history + }) + } + alert.add(actionWithTitle: Localized.Alert.cancel, style: .cancel) + return alert + } } + diff --git a/Kiwix/Tools/StringTools.swift b/Kiwix/Tools/StringTools.swift index c433d94c..559a917c 100644 --- a/Kiwix/Tools/StringTools.swift +++ b/Kiwix/Tools/StringTools.swift @@ -72,6 +72,7 @@ class LocalizedStrings { class Localized { class Alert { static let ok = NSLocalizedString("OK", comment: "Alert action") + static let cancel = NSLocalizedString("Cancel", comment: "Alert action") } }