RateKiwixAlert

This commit is contained in:
Chris Li 2017-01-19 11:10:20 -05:00
parent 995f8dd978
commit dacfc2c583
3 changed files with 48 additions and 15 deletions

View File

@ -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")
}
}
}

View File

@ -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
}
}

View File

@ -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")
}
}