Skip to content

Commit

Permalink
Add menu items for release notes and reporting an issue.
Browse files Browse the repository at this point in the history
Implement the help menu action.
  • Loading branch information
mhdhejazi committed Apr 29, 2020
1 parent b0f2839 commit bbb436b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions Corona/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal enum Asset {
internal static let info = ImageAsset(name: "Info")
internal static let layers = ImageAsset(name: "Layers")
internal static let more = ImageAsset(name: "More")
internal static let persons = ImageAsset(name: "Persons")
internal static let reload = ImageAsset(name: "Reload")
internal static let search = ImageAsset(name: "Search")
internal static let shareCircle = ImageAsset(name: "Share-Circle")
Expand Down
4 changes: 4 additions & 0 deletions Corona/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ internal enum L10n {
internal enum Menu {
/// Copy
internal static let copy = L10n.tr("Localizable", "menu.copy")
/// Release Notes
internal static let releaseNotes = L10n.tr("Localizable", "menu.releaseNotes")
/// Report an Issue
internal static let reportIssue = L10n.tr("Localizable", "menu.reportIssue")
/// Search
internal static let search = L10n.tr("Localizable", "menu.search")
/// Share
Expand Down
2 changes: 2 additions & 0 deletions Corona/Localization/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@
"menu.update" = "Update";
"menu.share" = "Share";
"menu.search" = "Search";
"menu.releaseNotes" = "Release Notes";
"menu.reportIssue" = "Report an Issue";
"share.current" = "Coronavirus live update";
"share.chartHistory" = "Coronavirus growth chart";
25 changes: 22 additions & 3 deletions Corona/Main/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ class App {
return topController
}

static let repoURL = URL(string: "https://github.com/mhdhejazi/CoronaTracker")!
static let releaseNotesURL = URL(string: "https://github.com/mhdhejazi/CoronaTracker/releases")!
static let newIssueURL = URL(string: "https://github.com/mhdhejazi/CoronaTracker/issues/new")!
#if targetEnvironment(macCatalyst)
static let updateURL = URL(string: "https://coronatracker.samabox.com/")!
#else
static let updateURL = URL(string: "https://github.com/mhdhejazi/CoronaTracker")!
static let updateURL = repoURL
#endif

static let version = Bundle.main.version
Expand All @@ -48,12 +51,16 @@ class App {
}.resume()
}

public static func openUpdatePage(viewController: UIViewController) {
let safariController = SFSafariViewController(url: updateURL)
public static func openWebPage(url: URL, viewController: UIViewController) {
let safariController = SFSafariViewController(url: url)
safariController.modalPresentationStyle = .pageSheet
viewController.present(safariController, animated: true)
}

public static func openUpdatePage(viewController: UIViewController) {
openWebPage(url: updateURL, viewController: viewController)
}

public static func upgrade() {
let appVersionKey = "appVersion"
let oldAppVersion = UserDefaults.standard.string(forKey: appVersionKey)
Expand All @@ -65,4 +72,16 @@ class App {

UserDefaults.standard.set(newAppVersion, forKey: appVersionKey)
}

public static func openHelpPage() {
openWebPage(url: repoURL, viewController: topViewController)
}

public static func openReleaseNotesPage() {
openWebPage(url: releaseNotesURL, viewController: topViewController)
}

public static func openNewIssuePage() {
openWebPage(url: newIssueURL, viewController: topViewController)
}
}
36 changes: 35 additions & 1 deletion Corona/Main/AppMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ extension AppMenu {
switch action {
case #selector(searchAction(_:)),
#selector(reloadAction(_:)),
#selector(shareAction(_:)):
#selector(shareAction(_:)),
#selector(releaseNotesAction(_:)),
#selector(reportIssueAction(_:)),
#selector(showHelp(_:)):
return true

default:
Expand All @@ -35,6 +38,7 @@ extension AppMenu {
builder.insertSibling(searchMenu(), afterMenu: .standardEdit)
builder.insertChild(reloadMenu(), atStartOfMenu: .view)
builder.insertChild(shareMenu(), atStartOfMenu: .file)
builder.insertChild(helpMenu(), atStartOfMenu: .help)
}

private func searchMenu() -> UIMenu {
Expand All @@ -61,6 +65,21 @@ extension AppMenu {
return UIMenu(title: "", options: .displayInline, children: [command])
}

private func helpMenu() -> UIMenu {
UIMenu(title: "", options: .displayInline, children: [
UICommand(title: L10n.Menu.releaseNotes,
action: #selector(releaseNotesAction(_:))),
UICommand(title: L10n.Menu.reportIssue,
action: #selector(reportIssueAction(_:)))
])
}

private func reportIssueMenu() -> UIMenu {
let command = UICommand(title: L10n.Menu.reportIssue,
action: #selector(reportIssueAction(_:)))
return UIMenu(title: "", options: .displayInline, children: [command])
}

// MARK: - Actions

@objc
Expand All @@ -77,4 +96,19 @@ extension AppMenu {
private func shareAction(_ sender: UICommand) {
MapController.shared.showShareButtons()
}

@objc
private func releaseNotesAction(_ sender: UICommand) {
App.openReleaseNotesPage()
}

@objc
private func reportIssueAction(_ sender: UICommand) {
App.openNewIssuePage()
}

@objc
private func showHelp(_ sender: UICommand) {
App.openHelpPage()
}
}

0 comments on commit bbb436b

Please sign in to comment.