Skip to content

Commit

Permalink
Add notice title and “show the latest notice” button
Browse files Browse the repository at this point in the history
  • Loading branch information
superk589 committed Dec 22, 2018
1 parent c9371fd commit 24382cf
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,10 @@
<source>Show All Field</source>
<note>No comment provided by engineer.</note>
</trans-unit>
<trans-unit id="Show the Latest Notice">
<source>Show the Latest Notice</source>
<note>No comment provided by engineer.</note>
</trans-unit>
<trans-unit id="Silence">
<source>Silence</source>
<target>沈黙</target>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,11 @@
<target>显示所有字段</target>
<note>No comment provided by engineer.</note>
</trans-unit>
<trans-unit id="Show the Latest Notice">
<source>Show the Latest Notice</source>
<target>显示最新通知</target>
<note>No comment provided by engineer.</note>
</trans-unit>
<trans-unit id="Silence">
<source>Silence</source>
<target>沉默</target>
Expand Down
Binary file not shown.
16 changes: 10 additions & 6 deletions PrincessGuide/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
Updater.shared.getNotice { [weak self] (payload) in
if let payload = payload, VersionManager.shared.noticeVersion < payload.version {
VersionManager.shared.noticeVersion = payload.version
let alert = UIAlertController(title: NSLocalizedString("Notice", comment: ""), message: payload.localizedContent, preferredStyle: .alert)
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: { _ in
alert.dismiss(animated: true, completion: nil)
})
alert.addAction(action)
self?.window?.rootViewController?.present(alert, animated: true, completion: nil)
self?.showNotice(payload: payload)
}
}
}

func showNotice(payload: NoticePayload) {
let alert = UIAlertController(title: payload.localizedTitle, message: payload.localizedContent, preferredStyle: .alert)
let action = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: { _ in
alert.dismiss(animated: true, completion: nil)
})
alert.addAction(action)
window?.rootViewController?.present(alert, animated: true, completion: nil)
}

}
9 changes: 9 additions & 0 deletions PrincessGuide/Model/Notice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct NoticePayload: Codable {
/// { "ja" : "notice content in Japanese" , "zh-Hans" : "notice content in simplified Chinese" }
var contents: [String: String]

var titles: [String: String]

}

extension NoticePayload {
Expand All @@ -28,4 +30,11 @@ extension NoticePayload {
}
return contents[`default`]
}

var localizedTitle: String? {
if let identifier = Locale.preferredLanguages.first {
return titles.filter { identifier.hasPrefix($0.key) }.max { $0.key.count < $1.key.count }?.value ?? titles[`default`] ?? NSLocalizedString("Notice", comment: "")
}
return titles[`default`] ?? NSLocalizedString("Notice", comment: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SettingsTableViewController: UITableViewController {
// if !Defaults.proEdition {
// aboutRows.append(Row(title: NSLocalizedString("Upgrade to Pro Edition", comment: ""), detail: "", hasDisclosure: true, accessoryView: nil, selector: #selector(upgradeToProEdition)))
// }
aboutRows.append(Row(title: NSLocalizedString("Show the Latest Notice", comment: ""), detail: nil, hasDisclosure: true, accessoryView: nil, selector: #selector(showRecentNotice)))
aboutRows.append(Row(title: NSLocalizedString("Third-Party Licenses", comment: ""), detail: nil, hasDisclosure: true, accessoryView: nil, selector: #selector(showAckListViewController)))
let versionInfo = Defaults.proEdition ? VersionManager.shared.appVersion + " (Pro)" : VersionManager.shared.appVersion
aboutRows.append(Row(title: NSLocalizedString("App Version", comment: ""), detail: versionInfo, hasDisclosure: false, accessoryView: nil, selector: nil))
Expand Down Expand Up @@ -118,6 +119,11 @@ class SettingsTableViewController: UITableViewController {
navigationController?.pushViewController(vc, animated: true)
}

@objc private func showRecentNotice() {
VersionManager.shared.noticeVersion = ""
(UIApplication.shared.delegate as? AppDelegate)?.checkNotice()
}

@objc private func upgradeToProEdition() {
let vc = BuyProEditionViewController()
vc.hidesBottomBarWhenPushed = true
Expand Down
3 changes: 3 additions & 0 deletions PrincessGuide/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,9 @@
/* No comment provided by engineer. */
"Show All Field" = "显示所有字段";

/* No comment provided by engineer. */
"Show the Latest Notice" = "显示最新通知";

/* No comment provided by engineer. */
"Silence" = "沉默";

Expand Down

0 comments on commit 24382cf

Please sign in to comment.