From 56aff0306ec2ae60522d9ac941438a725825b780 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 9 Oct 2023 18:13:18 +0400 Subject: [PATCH] Various improvements --- .../Sources/PhoneInputNode.swift | 9 +++++ .../Sources/DeleteAccountDataController.swift | 31 ++++++++++++---- .../Sources/DeleteAccountPhoneItem.swift | 10 ++++-- .../Sources/ChannelStatsController.swift | 2 +- .../TelegramNotices/Sources/Notices.swift | 26 ++++++++++++++ .../Sources/StoryContainerScreen.swift | 35 +++++++++++++------ .../StoryInteractionGuideComponent.swift | 10 +++++- 7 files changed, 100 insertions(+), 23 deletions(-) diff --git a/submodules/PhoneInputNode/Sources/PhoneInputNode.swift b/submodules/PhoneInputNode/Sources/PhoneInputNode.swift index 76b745cd23..b55d0fee02 100644 --- a/submodules/PhoneInputNode/Sources/PhoneInputNode.swift +++ b/submodules/PhoneInputNode/Sources/PhoneInputNode.swift @@ -93,6 +93,15 @@ public final class PhoneInputNode: ASDisplayNode, UITextFieldDelegate { } } + public var codeNumberAndFullNumber: (String, String, String) { + let full = self.number + return ( + cleanPhoneNumber(self.countryCodeField.textField.text ?? ""), + cleanPhoneNumber(self.numberField.textField.text ?? ""), + full + ) + } + public var countryCodeText: String { get { return self.countryCodeField.textField.text ?? "" diff --git a/submodules/SettingsUI/Sources/DeleteAccountDataController.swift b/submodules/SettingsUI/Sources/DeleteAccountDataController.swift index efa45cab1c..6631833d34 100644 --- a/submodules/SettingsUI/Sources/DeleteAccountDataController.swift +++ b/submodules/SettingsUI/Sources/DeleteAccountDataController.swift @@ -486,18 +486,22 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat action(peers, nil) }) case .phone: - var phoneNumber: String? + var code: String? + var number: String? controller?.forEachItemNode { itemNode in if let itemNode = itemNode as? DeleteAccountPhoneItemNode { - var phoneValue = itemNode.phoneNumber - if phoneValue.hasPrefix("+939998") { - phoneValue = phoneValue.replacingOccurrences(of: "+939998", with: "+9998") + let value = itemNode.codeNumberAndFullNumber + if value.0 == "+93" && value.1.hasPrefix("9998") { + code = "+" + number = value.1 + } else { + code = value.0 + number = value.1 } - phoneNumber = phoneValue } } - if let phoneNumber = phoneNumber, phoneNumber.count > 4 { + if let code, var number, (code + number).count > 4 { let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId)) |> deliverOnMainQueue) .start(next: { accountPeer in @@ -505,7 +509,20 @@ func deleteAccountDataController(context: AccountContext, mode: DeleteAccountDat if !phone.hasPrefix("+") { phone = "+\(phone)" } - if phone != phoneNumber { + + var matches = false + if phone == (code + number) { + matches = true + } else { + while number.hasPrefix("0") { + number.removeFirst() + if phone == (code + number) { + matches = true + } + } + } + + if !matches { secondaryActionDisabled = false presentControllerImpl?(textAlertController(context: context, title: nil, text: presentationData.strings.DeleteAccount_InvalidPhoneNumberError, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})])) return diff --git a/submodules/SettingsUI/Sources/DeleteAccountPhoneItem.swift b/submodules/SettingsUI/Sources/DeleteAccountPhoneItem.swift index caf368cf73..a64fdfdd58 100644 --- a/submodules/SettingsUI/Sources/DeleteAccountPhoneItem.swift +++ b/submodules/SettingsUI/Sources/DeleteAccountPhoneItem.swift @@ -188,13 +188,13 @@ class DeleteAccountPhoneItemNode: ListViewItemNode, ItemListItemNode { let localizedName: String = AuthorizationSequenceCountrySelectionController.lookupCountryNameById(country.id, strings: item.strings) ?? country.name strongSelf.countryButton.setTitle("\(flagString) \(localizedName)", with: Font.regular(17.0), with: item.theme.list.itemPrimaryTextColor, for: []) - let maskFont = Font.with(size: 20.0, design: .regular, traits: [.monospacedNumbers]) + let maskFont = Font.with(size: 17.0, design: .regular, traits: [.monospacedNumbers]) if let mask = AuthorizationSequenceCountrySelectionController.lookupPatternByNumber(number, preferredCountries: strongSelf.preferredCountryIdForCode).flatMap({ NSAttributedString(string: $0, font: maskFont, textColor: item.theme.list.itemPlaceholderTextColor) }) { strongSelf.phoneInputNode.numberField.textField.attributedPlaceholder = nil strongSelf.phoneInputNode.mask = mask } else { strongSelf.phoneInputNode.mask = nil - strongSelf.phoneInputNode.numberField.textField.attributedPlaceholder = NSAttributedString(string: item.strings.Login_PhonePlaceholder, font: Font.regular(20.0), textColor: item.theme.list.itemPlaceholderTextColor) + strongSelf.phoneInputNode.numberField.textField.attributedPlaceholder = NSAttributedString(string: item.strings.Login_PhonePlaceholder, font: Font.regular(17.0), textColor: item.theme.list.itemPlaceholderTextColor) } return true } else { @@ -269,6 +269,10 @@ class DeleteAccountPhoneItemNode: ListViewItemNode, ItemListItemNode { return self.phoneInputNode.number } + var codeNumberAndFullNumber: (String, String, String) { + return self.phoneInputNode.codeNumberAndFullNumber + } + func updateCountryCode() { self.phoneInputNode.codeAndNumber = self.phoneInputNode.codeAndNumber } @@ -397,7 +401,7 @@ class DeleteAccountPhoneItemNode: ListViewItemNode, ItemListItemNode { strongSelf.phoneInputNode.frame = phoneInputFrame strongSelf.phoneInputNode.countryCodeField.frame = countryCodeFrame.offsetBy(dx: -phoneInputFrame.minX, dy: -phoneInputFrame.minY) strongSelf.phoneInputNode.numberField.frame = numberFrame.offsetBy(dx: -phoneInputFrame.minX, dy: -phoneInputFrame.minY) - strongSelf.phoneInputNode.placeholderNode.frame = placeholderFrame.offsetBy(dx: -phoneInputFrame.minX, dy: -phoneInputFrame.minY) + strongSelf.phoneInputNode.placeholderNode.frame = placeholderFrame.offsetBy(dx: -phoneInputFrame.minX, dy: -phoneInputFrame.minY + 4.0 + UIScreenPixel) } }) } diff --git a/submodules/StatisticsUI/Sources/ChannelStatsController.swift b/submodules/StatisticsUI/Sources/ChannelStatsController.swift index c7f6348301..2f559296f3 100644 --- a/submodules/StatisticsUI/Sources/ChannelStatsController.swift +++ b/submodules/StatisticsUI/Sources/ChannelStatsController.swift @@ -800,7 +800,7 @@ public func channelStatsController(context: AccountContext, updatedPresentationD if let boostStatus { boostData = .single(boostStatus) } else { - boostData = context.engine.peers.getChannelBoostStatus(peerId: peerId) + boostData = .single(nil) |> then(context.engine.peers.getChannelBoostStatus(peerId: peerId)) } let boostersContext = ChannelBoostersContext(account: context.account, peerId: peerId) diff --git a/submodules/TelegramNotices/Sources/Notices.swift b/submodules/TelegramNotices/Sources/Notices.swift index 866a403ee9..a2abcb0a5e 100644 --- a/submodules/TelegramNotices/Sources/Notices.swift +++ b/submodules/TelegramNotices/Sources/Notices.swift @@ -181,6 +181,7 @@ private enum ApplicationSpecificGlobalNotice: Int32 { case storyStealthModeReplyCount = 47 case viewOnceTooltip = 48 case displayStoryUnmuteTooltip = 49 + case displayStoryInteractionGuide = 50 var key: ValueBoxKey { let v = ValueBoxKey(length: 4) @@ -434,6 +435,10 @@ private struct ApplicationSpecificNoticeKeys { static func displayStoryUnmuteTooltip() -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.displayStoryUnmuteTooltip.key) } + + static func displayStoryInteractionGuide() -> NoticeEntryKey { + return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.displayStoryInteractionGuide.key) + } } public struct ApplicationSpecificNotice { @@ -1659,4 +1664,25 @@ public struct ApplicationSpecificNotice { } |> take(1) } + + public static func setDisplayStoryInteractionGuide(accountManager: AccountManager) -> Signal { + return accountManager.transaction { transaction -> Void in + if let entry = CodableEntry(ApplicationSpecificBoolNotice()) { + transaction.setNotice(ApplicationSpecificNoticeKeys.displayStoryInteractionGuide(), entry) + } + } + |> ignoreValues + } + + public static func displayStoryInteractionGuide(accountManager: AccountManager) -> Signal { + return accountManager.noticeEntry(key: ApplicationSpecificNoticeKeys.displayStoryInteractionGuide()) + |> map { view -> Bool in + if let _ = view.value?.get(ApplicationSpecificBoolNotice.self) { + return true + } else { + return false + } + } + |> take(1) + } } diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift index ee18304a7a..59c97c7182 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift @@ -392,11 +392,10 @@ private final class StoryContainerScreenComponent: Component { var longPressRecognizer: StoryLongPressRecognizer? private var pendingNavigationToItemId: (peerId: EnginePeer.Id, id: Int32)? - - private var didDisplayReactionTooltip: Bool = false - + private let interactionGuide = ComponentView() private var isDisplayingInteractionGuide: Bool = false + private var displayInteractionGuideDisposable: Disposable? override init(frame: CGRect) { self.backgroundLayer = SimpleLayer() @@ -637,6 +636,7 @@ private final class StoryContainerScreenComponent: Component { self.headphonesDisposable?.dispose() self.stealthModeDisposable?.dispose() self.stealthModeTimer?.invalidate() + self.displayInteractionGuideDisposable?.dispose() } override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { @@ -893,10 +893,6 @@ private final class StoryContainerScreenComponent: Component { self.didAnimateIn = true self.state?.updated(transition: .immediate) } - - if let view = self.interactionGuide.view as? StoryInteractionGuideComponent.View { - view.animateIn(transitionIn: transitionIn) - } } else { self.didAnimateIn = true self.state?.updated(transition: .immediate) @@ -926,13 +922,11 @@ private final class StoryContainerScreenComponent: Component { guard let self else { return } - if !value { + if !value && !self.isDisplayingInteractionGuide { if let stateValue = self.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id], let currentItemView = itemSetView.view.view as? StoryItemSetContainerComponent.View { currentItemView.maybeDisplayReactionTooltip() } } - - self.didDisplayReactionTooltip = true }) }) } @@ -1119,6 +1113,22 @@ private final class StoryContainerScreenComponent: Component { } }) + let accountManager = component.context.sharedContext.accountManager + self.displayInteractionGuideDisposable = (ApplicationSpecificNotice.displayStoryInteractionGuide(accountManager: accountManager) + |> deliverOnMainQueue).startStrict(next: { [weak self] value in + guard let self else { + return + } + if !value { + self.isDisplayingInteractionGuide = true + if update { + self.state?.updated(transition: .immediate) + } + + let _ = ApplicationSpecificNotice.setDisplayStoryInteractionGuide(accountManager: accountManager).startStandalone() + } + }) + update = true } @@ -1718,15 +1728,18 @@ private final class StoryContainerScreenComponent: Component { strings: environment.strings, action: { [weak self] in self?.isDisplayingInteractionGuide = false + self?.state?.updated() } ) ), environment: {}, containerSize: availableSize ) - if let view = self.interactionGuide.view { + if let view = self.interactionGuide.view as? StoryInteractionGuideComponent.View { if view.superview == nil { self.addSubview(view) + + view.animateIn() } view.layer.zPosition = 1000.0 view.frame = CGRect(origin: .zero, size: availableSize) diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryInteractionGuideComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryInteractionGuideComponent.swift index 978f90c205..aa8da8d0dd 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryInteractionGuideComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryInteractionGuideComponent.swift @@ -66,7 +66,10 @@ final class StoryInteractionGuideComponent: Component { } } - func animateIn(transitionIn: StoryContainerScreen.TransitionIn) { + var didAnimateOut = false + + func animateIn() { + self.didAnimateOut = false UIView.animate(withDuration: 0.2) { self.effectView.effect = UIBlurEffect(style: .dark) } @@ -75,6 +78,10 @@ final class StoryInteractionGuideComponent: Component { } func animateOut(completion: @escaping () -> Void) { + guard !self.didAnimateOut else { + return + } + self.didAnimateOut = true self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in completion() }) @@ -87,6 +94,7 @@ final class StoryInteractionGuideComponent: Component { let sideInset: CGFloat = 48.0 +//TODO:localize let titleSize = self.titleLabel.update( transition: .immediate, component: AnyComponent(MultilineTextComponent(text: .plain(NSAttributedString(string: "Watching Stories", font: Font.semibold(20.0), textColor: .white, paragraphAlignment: .center)))),