This commit is contained in:
Ilya Laktyushin 2018-11-23 23:00:27 +04:00
parent 9b7901b330
commit 394b204f29
6 changed files with 43 additions and 19 deletions

View File

@ -592,8 +592,7 @@ final class ContactListNode: ASDisplayNode {
self.selectionStateValue = selectionState
self.selectionStatePromise.set(.single(selectionState))
//self.addSubnode(self.listNode)
self.addSubnode(self.authorizationNode)
self.addSubnode(self.listNode)
let processingQueue = Queue()
let previousEntries = Atomic<[ContactListNodeEntry]?>(value: nil)
@ -837,11 +836,6 @@ final class ContactListNode: ASDisplayNode {
}
}
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let result = super.hitTest(point, with: event)
return result
}
func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
var insets = layout.insets(options: [.input])
insets.left += layout.safeInsets.left

View File

@ -217,6 +217,7 @@ class ItemListController<Entry: ItemListNodeEntry>: ViewController {
strongSelf.tabBarItem.title = tabBarItemInfo.title
strongSelf.tabBarItem.image = tabBarItemInfo.image
strongSelf.tabBarItem.selectedImage = tabBarItemInfo.selectedImage
strongSelf.tabBarItem.badgeValue = tabBarItemInfo.badgeValue
}
}
})

View File

@ -13,12 +13,16 @@ final class PermissionController : ViewController {
private let strings: PresentationStrings
private let theme: AuthorizationTheme
private var animatedIn = false
private var allow: (() -> Void)?
init(account: Account) {
self.account = account
self.strings = account.telegramApplicationContext.currentPresentationData.with { $0 }.strings
self.theme = defaultLightAuthorizationTheme
super.init(navigationBarPresentationData: NavigationBarPresentationData(theme: AuthorizationSequenceController.navigationBarTheme(theme), strings: NavigationBarStrings(presentationStrings: strings)))
super.init(navigationBarPresentationData: nil)
self.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
@ -37,13 +41,24 @@ final class PermissionController : ViewController {
self?.presentingViewController?.dismiss(animated: false, completion: nil)
}
self.controllerNode.allow = { [weak self] in
self?.account.telegramApplicationContext.applicationBindings.openSettings()
self?.allow?()
}
self.controllerNode.next = { [weak self] in
self?.dismiss(completion: nil)
}
self.controllerNode.openPrivacyPolicy = {
self.controllerNode.openPrivacyPolicy = { [weak self] in
if let strongSelf = self {
openExternalUrl(account: strongSelf.account, context: .generic, url: "https://telegram.org/privacy", forceExternal: true, presentationData: strongSelf.account.telegramApplicationContext.currentPresentationData.with { $0 }, applicationContext: strongSelf.account.telegramApplicationContext, navigationController: nil, dismissInput: {})
}
}
}
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if !self.animatedIn {
self.animatedIn = true
self.controllerNode.animateIn()
}
}
@ -51,7 +66,8 @@ final class PermissionController : ViewController {
self.controllerNode.animateOut(completion: completion)
}
func updateData(subject: DeviceAccessSubject, currentStatus: AccessType) {
func updateData(subject: DeviceAccessSubject, currentStatus: AccessType, allow: @escaping () -> Void) {
self.allow = allow
self.controllerNode.updateData(subject: .notifications, currentStatus: currentStatus)
}

View File

@ -47,9 +47,6 @@ final class PermissionControllerNode: ASDisplayNode {
self.textNode.textAlignment = .center
self.textNode.maximumNumberOfLines = 0
self.textNode.displaysAsynchronously = false
let body = MarkdownAttributeSet(font: Font.regular(16.0), textColor: theme.primaryColor)
let link = MarkdownAttributeSet(font: Font.regular(16.0), textColor: theme.accentColor, additionalAttributes: [TelegramTextAttributes.URL: ""])
self.textNode.attributedText = parseMarkdownIntoAttributedString(strings.Login_TermsOfServiceLabel.replacingOccurrences(of: "]", with: "]()"), attributes: MarkdownAttributes(body: body, bold: body, link: link, linkAttribute: { _ in nil }), textAlignment: .center)
self.buttonNode = SolidRoundedButtonNode(theme: self.theme, height: 48.0, cornerRadius: 9.0)
@ -77,6 +74,7 @@ final class PermissionControllerNode: ASDisplayNode {
self.buttonNode.pressed = { [weak self] in
self?.allow?()
self?.dismiss?()
}
self.privacyPolicyNode.addTarget(self, action: #selector(self.privacyPolicyPressed), forControlEvents: .touchUpInside)
@ -158,7 +156,7 @@ final class PermissionControllerNode: ASDisplayNode {
}
let nextSize = self.nextNode.measure(layout.size)
transition.updateFrame(node: self.nextNode, frame: CGRect(x: layout.size.width - insets.right - nextSize.width - 16.0, y: insets.top + 10.0 + 60.0, width: nextSize.width, height: nextSize.height))
transition.updateFrame(node: self.nextNode, frame: CGRect(x: layout.size.width - insets.right - nextSize.width - 16.0, y: insets.top + 10.0, width: nextSize.width, height: nextSize.height))
self.titleNode.attributedText = NSAttributedString(string: self.title ?? "", font: Font.semibold(fontSize), textColor: self.theme.primaryColor)
@ -192,6 +190,10 @@ final class PermissionControllerNode: ASDisplayNode {
self.next?()
}
func animateIn(completion: (() -> Void)? = nil) {
self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring)
}
func animateOut(completion: (() -> Void)? = nil) {
self.layer.animatePosition(from: self.layer.position, to: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), duration: 0.2, timingFunction: kCAMediaTimingFunctionEaseInEaseOut, removeOnCompletion: false, completion: { [weak self] _ in
if let strongSelf = self {

View File

@ -674,7 +674,8 @@ public func settingsController(account: Account, accountManager: AccountManager)
updatePassport()
let notificationAuthorizationStatus = Promise<AccessType>(.allowed)
notificationAuthorizationStatus.set(DeviceAccess.authorizationStatus(account: account, subject: .notifications))
notificationAuthorizationStatus.set(.single(.allowed)
|> then(DeviceAccess.authorizationStatus(account: account, subject: .notifications)))
let notifyExceptions = Promise<NotificationExceptionsList?>(nil)
let updateNotifyExceptions: () -> Void = {

View File

@ -122,12 +122,22 @@ public final class TelegramRootController: NavigationController {
return
}
let _ = (DeviceAccess.authorizationStatus(account: self.account, subject: .notifications)
let account = self.account
let _ = (DeviceAccess.authorizationStatus(account: account, subject: .notifications)
|> take(1)
|> deliverOnMainQueue).start(next: { status in
if status != .allowed {
let controller = PermissionController(account: self.account)
controller.updateData(subject: .notifications, currentStatus: status)
controller.updateData(subject: .notifications, currentStatus: status, allow: {
switch status {
case .notDetermined:
account.telegramApplicationContext.applicationBindings.registerForNotifications()
case .denied:
account.telegramApplicationContext.applicationBindings.openSettings()
default:
break
}
})
parentController.present(controller, in: .window(.root))
}
})