Implement preliminary app mode switch

pull/247/head
nielsandriesse 5 years ago
parent 152b3ce5d6
commit a666776c88

@ -128,6 +128,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
stackView.pin(to: scrollView)
view.addSubview(scrollView)
scrollView.pin(to: view)
// Register for notifications
NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeSwitchedNotification(_:)), name: .appModeSwitched, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func getSettingButtons() -> [UIView] {
@ -203,6 +209,11 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
}
// MARK: Updating
@objc private func handleAppModeSwitchedNotification(_ notification: Notification) {
updateNavigationBarButtons()
// TODO: Redraw UI
}
private func handleIsEditingDisplayNameChanged() {
updateNavigationBarButtons()
UIView.animate(withDuration: 0.25) {
@ -228,9 +239,12 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
closeButton.tintColor = Colors.text
navigationItem.leftBarButtonItem = closeButton
let appModeIcon = UserDefaults.standard[.isUsingDarkMode] ? #imageLiteral(resourceName: "ic_dark_theme_on") : #imageLiteral(resourceName: "ic_dark_theme_off")
let appModeButton = UIBarButtonItem(image: appModeIcon, style: .plain, target: self, action: #selector(switchAppMode))
appModeButton.tintColor = Colors.text
let qrCodeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "QRCode"), style: .plain, target: self, action: #selector(showQRCode))
qrCodeButton.tintColor = Colors.text
navigationItem.rightBarButtonItem = qrCodeButton
navigationItem.rightBarButtonItems = [ qrCodeButton/*, appModeButton*/ ]
}
}
@ -281,7 +295,13 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
@objc private func close() {
dismiss(animated: true, completion: nil)
}
@objc private func switchAppMode() {
let isUsingDarkMode = UserDefaults.standard[.isUsingDarkMode]
UserDefaults.standard[.isUsingDarkMode] = !isUsingDarkMode
NotificationCenter.default.post(name: .appModeSwitched, object: nil)
}
@objc private func showQRCode() {
let qrCodeVC = QRCodeVC()
navigationController!.pushViewController(qrCodeVC, animated: true)

@ -3,6 +3,9 @@ public enum AppMode {
case light, dark
public static var current: AppMode = .dark
// public static var current: AppMode {
// return UserDefaults.standard[.isUsingDarkMode] ? .dark : .light
// }
}
public var isLightMode: Bool {

@ -10,6 +10,7 @@ public enum LKUserDefaults {
case hasViewedSeed
/// Whether the device was unlinked as a slave device (used to notify the user on the landing screen).
case wasUnlinked
case isUsingDarkMode
case isUsingFullAPNs
}

@ -2,6 +2,7 @@
public extension Notification.Name {
// State changes
public static let appModeSwitched = Notification.Name("appModeSwitched")
public static let blockedContactsUpdated = Notification.Name("blockedContactsUpdated")
public static let contactOnlineStatusChanged = Notification.Name("contactOnlineStatusChanged")
public static let groupThreadUpdated = Notification.Name("groupThreadUpdated")
@ -28,6 +29,7 @@ public extension Notification.Name {
@objc public extension NSNotification {
// State changes
@objc public static let appModeSwitched = Notification.Name.appModeSwitched.rawValue as NSString
@objc public static let blockedContactsUpdated = Notification.Name.blockedContactsUpdated.rawValue as NSString
@objc public static let contactOnlineStatusChanged = Notification.Name.contactOnlineStatusChanged.rawValue as NSString
@objc public static let groupThreadUpdated = Notification.Name.groupThreadUpdated.rawValue as NSString

Loading…
Cancel
Save