-
Notifications
You must be signed in to change notification settings - Fork 3k
/
VersionSetting.swift
63 lines (53 loc) · 2.62 KB
/
VersionSetting.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import Common
import Foundation
import Shared
/// Show the current version of Firefox
class VersionSetting: Setting {
private weak var settingsDelegate: DebugSettingsDelegate?
override var accessibilityIdentifier: String? {
return AccessibilityIdentifiers.Settings.Version.title
}
init(settingsDelegate: DebugSettingsDelegate) {
self.settingsDelegate = settingsDelegate
super.init(title: nil)
}
override var title: NSAttributedString? {
return NSAttributedString(string: "\(AppName.shortName) \(AppInfo.appVersion) (\(AppInfo.buildNumber))",
attributes: [NSAttributedString.Key.foregroundColor: theme.colors.textPrimary])
}
override func onConfigureCell(_ cell: UITableViewCell, theme: Theme) {
super.onConfigureCell(cell, theme: theme)
}
override func onClick(_ navigationController: UINavigationController?) {
settingsDelegate?.pressedVersion()
}
override func onLongPress(_ navigationController: UINavigationController?) {
if CoordinatorFlagManager.isSettingsCoordinatorEnabled {
let alertTitle: String = .SettingsCopyAppVersionAlertTitle
let alert = AlertController(title: alertTitle, message: nil, preferredStyle: .alert)
settingsDelegate?.askedToShow(alert: alert)
} else {
copyAppVersionAndPresentAlert(by: navigationController)
}
}
private func copyAppVersionAndPresentAlert(by navigationController: UINavigationController?) {
let alertTitle: String = .SettingsCopyAppVersionAlertTitle
let alert = AlertController(title: alertTitle, message: nil, preferredStyle: .alert)
getSelectedCell(by: navigationController)?.setSelected(false, animated: true)
UIPasteboard.general.string = self.title?.string
navigationController?.topViewController?.present(alert, animated: true) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
alert.dismiss(animated: true)
}
}
}
private func getSelectedCell(by navigationController: UINavigationController?) -> UITableViewCell? {
let controller = navigationController?.topViewController
let tableView = (controller as? AppSettingsTableViewController)?.tableView
guard let indexPath = tableView?.indexPathForSelectedRow else { return nil }
return tableView?.cellForRow(at: indexPath)
}
}