Merge commit '11d312f925102cec9e558f8bf7a5dbe82eb2275e'

This commit is contained in:
Ali 2021-02-16 23:09:01 +04:00
commit 29c08a7019
23 changed files with 2306 additions and 1417 deletions

View File

@ -1087,6 +1087,8 @@
"Time.PreciseDate_m11" = "Nov %1$@, %2$@ at %3$@";
"Time.PreciseDate_m12" = "Dec %1$@, %2$@ at %3$@";
"Time.MediumDate" = "%1$@ at %2$@";
"MuteFor.Hours_1" = "Mute for 1 hour";
"MuteFor.Hours_2" = "Mute for 2 hours";
"MuteFor.Hours_3_10" = "Mute for %@ hours";
@ -6130,3 +6132,5 @@ Sorry for the inconvenience.";
"Intents.ErrorLockedTitle" = "Locked";
"Intents.ErrorLockedText" = "Open Telegram and enter passcode to edit widget.";
"Conversation.GigagroupDescription" = "Only admins can send messages in this group.";

View File

@ -1574,8 +1574,12 @@ contacts found.</string>
<objects>
<notificationController backgroundImage="BubbleNotification" spacing="0.0" id="JcB-1W-jcv" userLabel="Static M">
<items>
<group width="1" alignment="left" radius="0.0" id="11B-ry-7nl">
<group width="1" alignment="left" layout="vertical" radius="0.0" spacing="0.0" id="11B-ry-7nl">
<items>
<label alignment="left" text="Name" id="TZ0-FP-E5f">
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="font" type="system" weight="medium" pointSize="16"/>
</label>
<label alignment="left" text="Text" numberOfLines="0" id="RMV-rW-0qs">
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="font" style="UICTFontTextStyleBody"/>
@ -1593,6 +1597,7 @@ contacts found.</string>
<edgeInsets key="margins" left="0.0" right="0.0" top="0.0" bottom="4"/>
<connections>
<outlet property="notificationAlertLabel" destination="RMV-rW-0qs" id="buR-qh-N93"/>
<outlet property="notificationTitleLabel" destination="TZ0-FP-E5f" id="5d7-td-uBA"/>
<segue destination="RQh-4n-Jyy" kind="relationship" relationship="dynamicNotificationInterface" id="wDy-DD-bRl"/>
<segue destination="RQh-4n-Jyy" kind="relationship" relationship="dynamicInteractiveNotificationInterface" id="MKi-5u-rhv"/>
</connections>
@ -1787,8 +1792,12 @@ contacts found.</string>
<objects>
<notificationController backgroundImage="BubbleNotification" spacing="0.0" id="crw-Qo-dti" userLabel="Static R">
<items>
<group width="1" alignment="left" layout="vertical" radius="0.0" id="RTo-Ed-NsD">
<group width="1" alignment="left" layout="vertical" radius="0.0" spacing="0.0" id="RTo-Ed-NsD">
<items>
<label alignment="left" text="Name" id="pKp-eS-3LS">
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="font" type="system" weight="medium" pointSize="16"/>
</label>
<label alignment="left" text="Text" numberOfLines="0" id="6f0-WK-Add">
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="font" style="UICTFontTextStyleBody"/>
@ -1806,6 +1815,7 @@ contacts found.</string>
<edgeInsets key="margins" left="0.0" right="0.0" top="0.0" bottom="4"/>
<connections>
<outlet property="notificationAlertLabel" destination="6f0-WK-Add" id="ioT-Xv-KJp"/>
<outlet property="notificationTitleLabel" destination="pKp-eS-3LS" id="Jbj-qy-H83"/>
<segue destination="79a-X2-tmF" kind="relationship" relationship="dynamicNotificationInterface" id="dmG-n7-HwD"/>
<segue destination="79a-X2-tmF" kind="relationship" relationship="dynamicInteractiveNotificationInterface" id="UyA-Ra-UVy"/>
</connections>

View File

@ -917,29 +917,67 @@ private class TimeInputView: UIView, UIKeyInput {
return !self.text.isEmpty
}
var focusUpdated: ((Bool) -> Void)?
var textUpdated: ((String) -> Void)?
override func becomeFirstResponder() -> Bool {
if self.isFirstResponder {
self.didReset = false
}
let result = super.becomeFirstResponder()
self.focusUpdated?(true)
return result
}
override func resignFirstResponder() -> Bool {
let result = super.resignFirstResponder()
self.focusUpdated?(false)
return result
}
var didReset = false
private let nonDigits = CharacterSet.decimalDigits.inverted
func insertText(_ text: String) {
if text.rangeOfCharacter(from: nonDigits) != nil {
return
}
if !self.didReset {
self.text = ""
self.didReset = true
}
var updatedText = self.text
updatedText.append(updatedText)
updatedText = String(updatedText.suffix(4))
updatedText.append(text)
self.text = updatedText
self.textUpdated?(self.text)
}
func deleteBackward() {
self.didReset = true
var updatedText = self.text
updatedText.removeLast()
if !updatedText.isEmpty {
updatedText.removeLast()
}
self.text = updatedText
self.textUpdated?(self.text)
}
}
private class TimeInputNode: ASDisplayNode {
var text: String {
get {
if let view = self.view as? TimeInputView {
return view.text
} else {
return ""
}
}
set {
if let view = self.view as? TimeInputView {
view.text = newValue
}
}
}
var textUpdated: ((String) -> Void)? {
didSet {
if let view = self.view as? TimeInputView {
@ -948,6 +986,14 @@ private class TimeInputNode: ASDisplayNode {
}
}
var focusUpdated: ((Bool) -> Void)? {
didSet {
if let view = self.view as? TimeInputView {
view.focusUpdated = self.focusUpdated
}
}
}
override init() {
super.init()
@ -958,57 +1004,44 @@ private class TimeInputNode: ASDisplayNode {
override func didLoad() {
super.didLoad()
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap)))
if let view = self.view as? TimeInputView {
view.textUpdated = self.textUpdated
}
}
@objc private func handleTap() {
self.view.becomeFirstResponder()
}
}
public func stringTimestamp(hours: Int32, minutes: Int32, dateTimeFormat: PresentationDateTimeFormat) -> String {
switch dateTimeFormat.timeFormat {
case .regular:
let hourString: String
if hours == 0 {
hourString = "12"
} else if hours > 12 {
hourString = "\(hours - 12)"
} else {
hourString = "\(hours)"
}
let periodString: String
if hours >= 12 {
periodString = "PM"
} else {
periodString = "AM"
}
if minutes >= 10 {
return "\(hourString) \(minutes) \(periodString)"
} else {
return "\(hourString):0\(minutes) \(periodString)"
}
case .military:
return String(format: "%02d %02d", arguments: [Int(hours), Int(minutes)])
}
}
private final class TimePickerNode: ASDisplayNode {
enum Selection {
case none
case hours
case minutes
case all
}
private var theme: DatePickerTheme
private let dateTimeFormat: PresentationDateTimeFormat
private let backgroundNode: ASDisplayNode
private let textNode: ImmediateTextNode
private let hoursNode: TapeNode
private let minutesNode: TapeNode
private let hoursTopMaskNode: ASDisplayNode
private let hoursBottomMaskNode: ASDisplayNode
private let minutesTopMaskNode: ASDisplayNode
private let minutesBottomMaskNode: ASDisplayNode
private let colonNode: ImmediateTextNode
private let borderNode: ASDisplayNode
private let inputNode: TimeInputNode
private let amPMSelectorNode: SegmentedControlNode
private var typing = false
private var typingString = ""
private var typingHours: Int?
private var typingMinutes: Int?
private let hoursTypingNode: ImmediateTextNode
private let minutesTypingNode: ImmediateTextNode
var date: Date? {
didSet {
if let size = self.validLayout {
@ -1027,15 +1060,42 @@ private final class TimePickerNode: ASDisplayNode {
self.theme = theme
self.dateTimeFormat = dateTimeFormat
self.date = date
self.selection = .none
self.backgroundNode = ASDisplayNode()
self.backgroundNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
self.backgroundNode.cornerRadius = 9.0
self.textNode = ImmediateTextNode()
self.borderNode = ASDisplayNode()
self.borderNode.cornerRadius = 9.0
self.borderNode.isUserInteractionEnabled = false
self.borderNode.isHidden = true
self.borderNode.borderWidth = 2.0
self.borderNode.borderColor = theme.accentColor.cgColor
self.colonNode = ImmediateTextNode()
self.hoursNode = TapeNode()
self.minutesNode = TapeNode()
self.hoursTypingNode = ImmediateTextNode()
self.hoursTypingNode.isHidden = true
self.hoursTypingNode.textAlignment = .right
self.minutesTypingNode = ImmediateTextNode()
self.minutesTypingNode.isHidden = true
self.minutesTypingNode.textAlignment = .right
self.inputNode = TimeInputNode()
self.hoursTopMaskNode = ASDisplayNode()
self.hoursTopMaskNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
self.hoursBottomMaskNode = ASDisplayNode()
self.hoursBottomMaskNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
self.minutesTopMaskNode = ASDisplayNode()
self.minutesTopMaskNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
self.minutesBottomMaskNode = ASDisplayNode()
self.minutesBottomMaskNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
let isPM: Bool
if let date = date {
let hours = calendar.component(.hour, from: date)
@ -1049,13 +1109,21 @@ private final class TimePickerNode: ASDisplayNode {
super.init()
self.addSubnode(self.backgroundNode)
self.addSubnode(self.textNode)
// self.addSubnode(self.colonNode)
// self.addSubnode(self.inputNode)
self.addSubnode(self.colonNode)
self.addSubnode(self.hoursNode)
self.addSubnode(self.minutesNode)
self.addSubnode(self.hoursTopMaskNode)
self.addSubnode(self.hoursBottomMaskNode)
self.addSubnode(self.minutesTopMaskNode)
self.addSubnode(self.minutesBottomMaskNode)
self.addSubnode(self.hoursTypingNode)
self.addSubnode(self.minutesTypingNode)
self.addSubnode(self.borderNode)
self.addSubnode(self.inputNode)
self.addSubnode(self.amPMSelectorNode)
self.amPMSelectorNode.selectedIndexChanged = { index in
guard let date = self.date else {
self.amPMSelectorNode.selectedIndexChanged = { [weak self] index in
guard let strongSelf = self, let date = strongSelf.date else {
return
}
let hours = calendar.component(.hour, from: date)
@ -1066,12 +1134,376 @@ private final class TimePickerNode: ASDisplayNode {
components.hour = hours + 12
}
if let newDate = calendar.date(from: components) {
self.valueChanged?(newDate)
strongSelf.date = newDate
strongSelf.valueChanged?(newDate)
}
}
self.inputNode.textUpdated = { text in
self.inputNode.textUpdated = { [weak self] text in
self?.handleTextInput(text)
}
self.inputNode.focusUpdated = { [weak self] focus in
if focus {
self?.selection = .all
} else {
self?.selection = .none
}
}
self.hoursNode.count = {
switch dateTimeFormat.timeFormat {
case .military:
return 24
case .regular:
return 12
}
}
self.hoursNode.titleAt = { i in
switch dateTimeFormat.timeFormat {
case .military:
if i < 10 {
return "0\(i)"
} else {
return "\(i)"
}
case .regular:
if i < 10 {
return "0\(i)"
} else {
return "\(1 + i)"
}
}
}
self.hoursNode.isScrollingUpdated = { [weak self] scrolling in
if let strongSelf = self {
if scrolling {
strongSelf.typing = false
strongSelf.selection = .hours
} else {
if strongSelf.inputNode.view.isFirstResponder {
strongSelf.selection = .all
} else {
strongSelf.selection = .none
}
}
}
}
self.hoursNode.selected = { [weak self] index in
guard let strongSelf = self else {
return
}
switch dateTimeFormat.timeFormat {
case .military:
let hour = index
if let date = strongSelf.date {
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
components.hour = hour
if let newDate = calendar.date(from: components) {
strongSelf.date = newDate
strongSelf.valueChanged?(newDate)
}
}
case .regular:
break
}
}
self.minutesNode.count = {
return 60
}
self.minutesNode.titleAt = { i in
if i < 10 {
return "0\(i)"
} else {
return "\(i)"
}
}
self.minutesNode.isScrollingUpdated = { [weak self] scrolling in
if let strongSelf = self {
if scrolling {
strongSelf.typing = false
strongSelf.selection = .minutes
} else {
if strongSelf.inputNode.view.isFirstResponder {
strongSelf.selection = .all
} else {
strongSelf.selection = .none
}
}
}
}
self.minutesNode.selected = { [weak self] index in
guard let strongSelf = self else {
return
}
switch dateTimeFormat.timeFormat {
case .military:
let minute = index
if let date = strongSelf.date {
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
components.minute = minute
if let newDate = calendar.date(from: components) {
strongSelf.date = newDate
strongSelf.valueChanged?(newDate)
}
}
case .regular:
break
}
}
}
override func didLoad() {
super.didLoad()
self.view.disablesInteractiveTransitionGestureRecognizer = true
self.view.disablesInteractiveModalDismiss = true
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:))))
}
private func handleTextInput(_ input: String) {
self.typing = true
var text = input
var typingHours: Int?
var typingMinutes: Int?
if self.selection == .all {
text = String(text.suffix(4))
if text.count < 2 {
typingHours = nil
} else {
if var value = Int(String(text.prefix(2))) {
if value > 24 {
value = value % 10
}
typingHours = value
}
}
if var value = Int(String(text.suffix(2))) {
if value >= 60 {
value = value % 10
}
typingMinutes = value
}
} else if self.selection == .hours {
text = String(text.suffix(2))
if var value = Int(text) {
if value > 24 {
value = value % 10
}
typingHours = value
} else {
typingHours = nil
}
} else if self.selection == .minutes {
text = String(text.suffix(2))
if var value = Int(text) {
if value >= 60 {
value = value % 10
}
typingMinutes = value
} else {
typingMinutes = nil
}
}
self.typingHours = typingHours
self.typingMinutes = typingMinutes
if let date = self.date {
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
if let typingHours = typingHours {
components.hour = typingHours
}
if let typingMinutes = typingMinutes {
components.minute = typingMinutes
}
if let newDate = calendar.date(from: components) {
self.date = newDate
self.valueChanged?(newDate)
self.updateTapes()
}
}
self.update()
}
private var selection: Selection {
didSet {
self.update()
}
}
private func update() {
if case .none = self.selection {
self.borderNode.isHidden = true
} else {
self.borderNode.isHidden = false
}
let colonColor: UIColor
switch self.selection {
case .none:
colonColor = self.theme.textColor
self.colonNode.alpha = 1.0
self.hoursNode.textColor = self.theme.textColor
self.minutesNode.textColor = self.theme.textColor
self.hoursNode.alpha = 1.0
self.minutesNode.alpha = 1.0
self.hoursTopMaskNode.alpha = 1.0
self.hoursBottomMaskNode.alpha = 1.0
self.minutesTopMaskNode.alpha = 1.0
self.minutesBottomMaskNode.alpha = 1.0
self.typing = false
self.typingHours = nil
self.typingMinutes = nil
self.hoursTypingNode.isHidden = true
self.minutesTypingNode.isHidden = true
self.hoursNode.isHidden = false
self.minutesNode.isHidden = false
case .hours:
colonColor = self.theme.textColor
self.colonNode.alpha = 0.35
self.hoursNode.textColor = self.theme.accentColor
self.minutesNode.textColor = self.theme.textColor
self.hoursNode.alpha = 1.0
self.minutesNode.alpha = 0.35
self.hoursTopMaskNode.alpha = 0.5
self.hoursBottomMaskNode.alpha = 0.5
self.minutesTopMaskNode.alpha = 1.0
self.minutesBottomMaskNode.alpha = 1.0
if self.typing {
self.hoursTypingNode.isHidden = false
self.minutesTypingNode.isHidden = true
self.hoursNode.isHidden = true
self.minutesNode.isHidden = false
} else {
self.hoursTypingNode.isHidden = true
self.minutesTypingNode.isHidden = true
self.hoursNode.isHidden = false
self.minutesNode.isHidden = false
}
case .minutes:
colonColor = self.theme.textColor
self.colonNode.alpha = 0.35
self.hoursNode.textColor = self.theme.textColor
self.minutesNode.textColor = self.theme.accentColor
self.hoursNode.alpha = 0.35
self.minutesNode.alpha = 1.0
self.hoursTopMaskNode.alpha = 1.0
self.hoursBottomMaskNode.alpha = 1.0
self.minutesTopMaskNode.alpha = 0.5
self.minutesBottomMaskNode.alpha = 0.5
if self.typing {
self.hoursTypingNode.isHidden = true
self.minutesTypingNode.isHidden = false
self.hoursNode.isHidden = false
self.minutesNode.isHidden = true
} else {
self.hoursTypingNode.isHidden = true
self.minutesTypingNode.isHidden = true
self.hoursNode.isHidden = false
self.minutesNode.isHidden = false
}
case .all:
colonColor = self.theme.accentColor
self.colonNode.alpha = 1.0
self.hoursNode.textColor = self.theme.accentColor
self.minutesNode.textColor = self.theme.accentColor
self.hoursNode.alpha = 1.0
self.minutesNode.alpha = 1.0
self.hoursTopMaskNode.alpha = 0.5
self.hoursBottomMaskNode.alpha = 0.5
self.minutesTopMaskNode.alpha = 0.5
self.minutesBottomMaskNode.alpha = 0.5
if self.typing {
self.hoursTypingNode.isHidden = false
self.minutesTypingNode.isHidden = false
self.hoursNode.isHidden = true
self.minutesNode.isHidden = true
} else {
self.hoursTypingNode.isHidden = true
self.minutesTypingNode.isHidden = true
self.hoursNode.isHidden = false
self.minutesNode.isHidden = false
}
}
if let size = self.validLayout {
let hoursString: String
if let typingHours = self.typingHours {
if typingHours < 10 {
hoursString = "0\(typingHours)"
} else {
hoursString = "\(typingHours)"
}
} else {
hoursString = ""
}
let minutesString: String
if let typingMinutes = self.typingMinutes {
if typingMinutes < 10 {
minutesString = "0\(typingMinutes)"
} else {
minutesString = "\(typingMinutes)"
}
} else {
minutesString = ""
}
self.hoursTypingNode.attributedText = NSAttributedString(string: hoursString, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: theme.textColor)
let hoursSize = self.hoursTypingNode.updateLayout(size)
self.hoursTypingNode.frame = CGRect(origin: CGPoint(x: 37.0 - hoursSize.width - 3.0 + UIScreenPixel, y: 6.0), size: hoursSize)
self.minutesTypingNode.attributedText = NSAttributedString(string: minutesString, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: theme.textColor)
let minutesSize = self.minutesTypingNode.updateLayout(size)
self.minutesTypingNode.frame = CGRect(origin: CGPoint(x: 75.0 - minutesSize.width - 9.0 + UIScreenPixel, y: 6.0), size: minutesSize)
self.colonNode.attributedText = NSAttributedString(string: ":", font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: colonColor)
let _ = self.colonNode.updateLayout(size)
}
}
@objc func handleTap(_ gestureRecognizer: UITapGestureRecognizer) {
if !self.inputNode.view.isFirstResponder {
self.inputNode.view.becomeFirstResponder()
self.selection = .all
} else {
let location = gestureRecognizer.location(in: self.view)
if location.x < 37.0 {
if self.selection == .hours {
self.selection = .all
} else {
self.selection = .hours
}
} else if location.x > 37.0 && location.x < 75.0 {
if self.selection == .minutes {
self.selection = .all
} else {
self.selection = .minutes
}
}
}
}
@ -1079,35 +1511,60 @@ private final class TimePickerNode: ASDisplayNode {
self.theme = theme
self.backgroundNode.backgroundColor = theme.segmentedControlTheme.backgroundColor
self.borderNode.borderColor = theme.accentColor.cgColor
}
func updateLayout(size: CGSize) -> CGSize {
self.backgroundNode.frame = CGRect(x: 0.0, y: 0.0, width: 75.0, height: 36.0)
var contentSize = CGSize()
func updateTapes() {
let hours: Int32
let minutes: Int32
if let date = self.date {
hours = Int32(calendar.component(.hour, from: date))
minutes = Int32(calendar.component(.hour, from: date))
minutes = Int32(calendar.component(.minute, from: date))
} else {
hours = 11
minutes = 0
}
let string = stringForShortTimestamp(hours: hours, minutes: minutes, dateTimeFormat: self.dateTimeFormat).replacingOccurrences(of: " AM", with: "").replacingOccurrences(of: " PM", with: "")
self.textNode.attributedText = NSAttributedString(string: string, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor)
switch self.dateTimeFormat.timeFormat {
case .military:
self.hoursNode.selectRow(Int(hours), animated: false)
self.minutesNode.selectRow(Int(minutes), animated: false)
case .regular:
var h12Hours = hours
if hours == 0 {
h12Hours = 12
} else if hours > 12 {
h12Hours = hours - 12
}
self.hoursNode.selectRow(Int(h12Hours - 1), animated: false)
self.minutesNode.selectRow(Int(minutes), animated: false)
}
}
func updateLayout(size: CGSize) -> CGSize {
self.validLayout = size
self.backgroundNode.frame = CGRect(x: 0.0, y: 0.0, width: 75.0, height: 36.0)
self.borderNode.frame = self.backgroundNode.frame
var contentSize = CGSize()
self.updateTapes()
self.hoursNode.frame = CGRect(x: 3.0, y: 0.0, width: 36.0, height: 36.0)
self.minutesNode.frame = CGRect(x: 35.0, y: 0.0, width: 36.0, height: 36.0)
self.hoursTopMaskNode.frame = CGRect(x: 9.0, y: 0.0, width: 28.0, height: 5.0)
self.hoursBottomMaskNode.frame = CGRect(x: 9.0, y: 36.0 - 5.0, width: 28.0, height: 5.0)
self.minutesTopMaskNode.frame = CGRect(x: 37.0, y: 0.0, width: 28.0, height: 5.0)
self.minutesBottomMaskNode.frame = CGRect(x: 37.0, y: 36.0 - 5.0, width: 28.0, height: 5.0)
self.colonNode.attributedText = NSAttributedString(string: ":", font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor)
let textSize = self.textNode.updateLayout(size)
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.backgroundNode.frame.width - textSize.width) / 2.0), y: floorToScreenPixels((self.backgroundNode.frame.height - textSize.height) / 2.0)), size: textSize)
let colonSize = self.colonNode.updateLayout(size)
self.colonNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.backgroundNode.frame.width - colonSize.width) / 2.0) - 7.0, y: floorToScreenPixels((self.backgroundNode.frame.height - colonSize.height) / 2.0) - 2.0), size: colonSize)
self.colonNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((self.backgroundNode.frame.width - colonSize.width) / 2.0), y: floorToScreenPixels((self.backgroundNode.frame.height - colonSize.height) / 2.0) - 2.0), size: colonSize)
self.inputNode.frame = self.backgroundNode.frame
self.inputNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: 1.0, height: 1.0))
if self.dateTimeFormat.timeFormat == .military {
contentSize = self.backgroundNode.frame.size

View File

@ -0,0 +1,271 @@
import Foundation
import UIKit
import Display
import AsyncDisplayKit
import AudioToolbox
@objc public protocol PickerViewDelegate: class {
func pickerViewHeightForRows(_ pickerView: TapeNode) -> CGFloat
@objc optional func pickerView(_ pickerView: TapeNode, didSelectRow row: Int)
@objc optional func pickerView(_ pickerView: TapeNode, didTapRow row: Int)
@objc optional func pickerView(_ pickerView: TapeNode, styleForLabel label: UILabel, highlighted: Bool)
@objc optional func pickerView(_ pickerView: TapeNode, viewForRow row: Int, highlighted: Bool, reusingView view: UIView?) -> UIView?
}
open class TapeNode: ASDisplayNode {
fileprivate class Cell: UITableViewCell {
lazy var titleLabel: UILabel = {
let titleLabel = UILabel(frame: CGRect(x: 0.0, y: 0.0, width: self.contentView.frame.width, height: self.contentView.frame.height))
titleLabel.textAlignment = .center
return titleLabel
}()
var customView: UIView?
}
var textColor: UIColor = .black {
didSet {
for cell in self.tableView.visibleCells {
if let cell = cell as? Cell {
cell.titleLabel.textColor = self.textColor
}
}
}
}
private let hapticFeedback = HapticFeedback()
private var previousRoundedRow: Int?
var count: (() -> Int)?
var titleAt: ((Int) -> String)?
var selected: ((Int) -> Void)?
var isScrollingUpdated: ((Bool) -> Void)?
var numberOfRows: Int {
get {
return self.count?() ?? 0
}
}
private var indexesCount: Int {
return self.numberOfRows > 0 ? self.numberOfRows - 1 : self.numberOfRows
}
private var rowHeight: CGFloat {
return 21.0
}
private let cellIdentifier = "tapeCell"
public lazy var tableView: UITableView = {
return UITableView()
}()
private var infinityRowsMultiplier: Int = 1
var currentSelectedRow: Int?
var currentSelectedIndex: Int {
get {
if let currentSelectedRow = self.currentSelectedRow {
return self.indexForRow(currentSelectedRow)
} else {
return 0
}
}
}
private var isScrolling = false
private var initialized = false
private var shouldSelectNearbyToMiddleRow = false
open override func didLoad() {
super.didLoad()
self.setup()
}
fileprivate func setup() {
self.infinityRowsMultiplier = self.generateInfinityRowsMultiplier()
if #available(iOS 11.0, *) {
self.tableView.contentInsetAdjustmentBehavior = .never
}
self.tableView.estimatedRowHeight = 0
self.tableView.estimatedSectionFooterHeight = 0
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.backgroundColor = .clear
self.tableView.separatorStyle = .none
self.tableView.separatorColor = .none
self.tableView.allowsSelection = true
self.tableView.allowsMultipleSelection = false
self.tableView.showsVerticalScrollIndicator = false
self.tableView.showsHorizontalScrollIndicator = false
self.tableView.scrollsToTop = false
self.tableView.register(Cell.classForCoder(), forCellReuseIdentifier: self.cellIdentifier)
self.view.addSubview(tableView)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.reloadData()
}
fileprivate func generateInfinityRowsMultiplier() -> Int {
if self.numberOfRows > 100 {
return 100
} else if self.numberOfRows < 100 && self.numberOfRows > 50 {
return 200
} else if self.numberOfRows < 50 && self.numberOfRows > 25 {
return 400
} else {
return 800
}
}
open override func layout() {
super.layout()
self.tableView.frame = self.bounds
if !self.initialized {
self.setup()
self.initialized = true
}
}
fileprivate func indexForRow(_ row: Int) -> Int {
return row % (self.numberOfRows > 0 ? self.numberOfRows : 1)
}
fileprivate func selectTappedRow(_ row: Int) {
self.selectRow(row, animated: true)
if let currentSelectedRow = self.currentSelectedRow {
self.selected?(currentSelectedRow)
}
}
fileprivate func visibleIndexOfSelectedRow() -> Int {
let middleMultiplier = (self.infinityRowsMultiplier / 2)
let middleIndex = self.numberOfRows * middleMultiplier
let indexForSelectedRow: Int
if let currentSelectedRow = self.currentSelectedRow {
indexForSelectedRow = middleIndex - (self.numberOfRows - currentSelectedRow)
} else {
let middleRow = Int(floor(Float(self.indexesCount) / 2.0))
indexForSelectedRow = middleIndex - (self.numberOfRows - middleRow)
}
return indexForSelectedRow
}
open func selectRow(_ row : Int, animated: Bool) {
if self.currentSelectedIndex == self.indexForRow(row) {
return
}
var finalRow = row
if row <= self.numberOfRows {
let middleMultiplier = (self.infinityRowsMultiplier / 2)
let middleIndex = self.numberOfRows * middleMultiplier
finalRow = middleIndex - (self.numberOfRows - finalRow)
}
self.currentSelectedRow = finalRow
if let currentSelectedRow = self.currentSelectedRow {
self.tableView.setContentOffset(CGPoint(x: 0.0, y: CGFloat(currentSelectedRow) * self.rowHeight), animated: animated)
}
}
open func reloadPickerView() {
self.tableView.reloadData()
}
}
extension TapeNode: UITableViewDataSource {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.numberOfRows * self.infinityRowsMultiplier
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let pickerViewCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! Cell
pickerViewCell.selectionStyle = .none
let centerY = (indexPath as NSIndexPath).row == 0 ? (self.frame.height / 2) - (self.rowHeight / 2) : 0.0
pickerViewCell.backgroundColor = .clear
pickerViewCell.contentView.backgroundColor = .clear
pickerViewCell.contentView.addSubview(pickerViewCell.titleLabel)
pickerViewCell.titleLabel.backgroundColor = .clear
pickerViewCell.titleLabel.font = Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers])
pickerViewCell.titleLabel.text = self.titleAt?(indexForRow((indexPath as NSIndexPath).row))
pickerViewCell.titleLabel.textColor = self.textColor
pickerViewCell.titleLabel.frame = CGRect(x: 0.0, y: centerY, width: frame.width, height: self.rowHeight)
return pickerViewCell
}
}
extension TapeNode: UITableViewDelegate {
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectTappedRow((indexPath as NSIndexPath).row)
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let numberOfRows = (self.count?() ?? 0) * self.infinityRowsMultiplier
if (indexPath as NSIndexPath).row == 0 {
return (self.frame.height / 2) + (self.rowHeight / 2)
} else if numberOfRows > 0 && (indexPath as NSIndexPath).row == numberOfRows - 1 {
return (self.frame.height / 2) + (self.rowHeight / 2)
}
return self.rowHeight
}
}
extension TapeNode: UIScrollViewDelegate {
public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.isScrolling = true
self.isScrollingUpdated?(true)
}
public func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let partialRow = Float(targetContentOffset.pointee.y / self.rowHeight)
var roundedRow = Int(lroundf(partialRow))
if roundedRow < 0 {
roundedRow = 0
} else {
targetContentOffset.pointee.y = CGFloat(roundedRow) * self.rowHeight
}
self.currentSelectedRow = self.indexForRow(roundedRow)
if let currentSelectedRow = self.currentSelectedRow {
self.selected?(currentSelectedRow)
}
}
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate {
self.isScrolling = false
self.isScrollingUpdated?(false)
}
}
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
self.isScrolling = false
self.isScrollingUpdated?(false)
}
public func scrollViewDidScroll(_ scrollView: UIScrollView) {
let partialRow = Float(scrollView.contentOffset.y / self.rowHeight)
let roundedRow = Int(lroundf(partialRow))
if self.previousRoundedRow != roundedRow && self.isScrolling {
self.previousRoundedRow = roundedRow
self.hapticFeedback.impact()
AudioServicesPlaySystemSound(1157)
}
}
}

View File

@ -497,7 +497,12 @@ final class NavigationModalContainer: ASDisplayNode, UIScrollViewDelegate, UIGes
if currentParent == nil {
break
}
if let scrollView = currentParent as? UIScrollView {
if currentParent is UIKeyInput {
if currentParent?.disablesInteractiveModalDismiss == true {
enableScrolling = false
break
}
} else if let scrollView = currentParent as? UIScrollView {
if scrollView === self.scrollNode.view {
break
}

View File

@ -54,7 +54,7 @@ func isValidNumberOfUsers(_ number: String) -> Bool {
private enum InviteLinksEditEntry: ItemListNodeEntry {
case timeHeader(PresentationTheme, String)
case timePicker(PresentationTheme, InviteLinkTimeLimit)
case timeExpiryDate(PresentationTheme, Int32?, Bool)
case timeExpiryDate(PresentationTheme, PresentationDateTimeFormat, Int32?, Bool)
case timeCustomPicker(PresentationTheme, PresentationDateTimeFormat, Int32?)
case timeInfo(PresentationTheme, String)
@ -115,8 +115,8 @@ private enum InviteLinksEditEntry: ItemListNodeEntry {
} else {
return false
}
case let .timeExpiryDate(lhsTheme, lhsDate, lhsActive):
if case let .timeExpiryDate(rhsTheme, rhsDate, rhsActive) = rhs, lhsTheme === rhsTheme, lhsDate == rhsDate, lhsActive == rhsActive {
case let .timeExpiryDate(lhsTheme, lhsDateTimeFormat, lhsDate, lhsActive):
if case let .timeExpiryDate(rhsTheme, rhsDateTimeFormat, rhsDate, rhsActive) = rhs, lhsTheme === rhsTheme, lhsDateTimeFormat == rhsDateTimeFormat, lhsDate == rhsDate, lhsActive == rhsActive {
return true
} else {
return false
@ -186,10 +186,10 @@ private enum InviteLinksEditEntry: ItemListNodeEntry {
return updatedState
})
})
case let .timeExpiryDate(theme, value, active):
case let .timeExpiryDate(theme, dateTimeFormat, value, active):
let text: String
if let value = value {
text = stringForFullDate(timestamp: value, strings: presentationData.strings, dateTimeFormat: PresentationDateTimeFormat(timeFormat: .regular, dateFormat: .monthFirst, dateSeparator: ".", decimalSeparator: ".", groupingSeparator: "."))
text = stringForMediumDate(timestamp: value, strings: presentationData.strings, dateTimeFormat: dateTimeFormat)
} else {
text = presentationData.strings.InviteLink_Create_TimeLimitExpiryDateNever
}
@ -287,7 +287,7 @@ private func inviteLinkEditControllerEntries(invite: ExportedInvitation?, state:
} else if let value = state.time.value {
time = currentTime + value
}
entries.append(.timeExpiryDate(presentationData.theme, time, state.pickingTimeLimit))
entries.append(.timeExpiryDate(presentationData.theme, presentationData.dateTimeFormat, time, state.pickingTimeLimit))
if state.pickingTimeLimit {
entries.append(.timeCustomPicker(presentationData.theme, presentationData.dateTimeFormat, time))
}
@ -484,6 +484,9 @@ public func inviteLinkEditController(context: AccountContext, peerId: PeerId, in
}
let controller = ItemListController(context: context, state: signal)
controller.beganInteractiveDragging = {
dismissInputImpl?()
}
presentControllerImpl = { [weak controller] c, p in
if let controller = controller {
controller.present(c, in: .window(.root), with: p)

View File

@ -104,6 +104,8 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
self.bottomStripeNode.isLayerBacked = true
super.init(layerBacked: false, dynamicBounce: false)
self.allowsGroupOpacity = true
}
public func asyncLayout() -> (_ item: ItemListDatePickerItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) {

View File

@ -164,6 +164,14 @@ open class ItemListController: ViewController, KeyShortcutResponder, Presentable
}
}
public var beganInteractiveDragging: (() -> Void)? {
didSet {
if self.isNodeLoaded {
(self.displayNode as! ItemListControllerNode).beganInteractiveDragging = self.beganInteractiveDragging
}
}
}
public var visibleBottomContentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)? {
didSet {
if self.isNodeLoaded {
@ -447,6 +455,7 @@ open class ItemListController: ViewController, KeyShortcutResponder, Presentable
displayNode.enableInteractiveDismiss = self.enableInteractiveDismiss
displayNode.alwaysSynchronous = self.alwaysSynchronous
displayNode.visibleEntriesUpdated = self.visibleEntriesUpdated
displayNode.beganInteractiveDragging = self.beganInteractiveDragging
displayNode.visibleBottomContentOffsetChanged = self.visibleBottomContentOffsetChanged
displayNode.contentOffsetChanged = self.contentOffsetChanged
displayNode.contentScrollingEnded = self.contentScrollingEnded

View File

@ -210,6 +210,7 @@ open class ItemListControllerNode: ASDisplayNode, UIScrollViewDelegate {
public var visibleEntriesUpdated: ((ItemListNodeVisibleEntries) -> Void)?
public var visibleBottomContentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)?
public var beganInteractiveDragging: (() -> Void)?
public var contentOffsetChanged: ((ListViewVisibleContentOffset, Bool) -> Void)?
public var contentScrollingEnded: ((ListView) -> Bool)?
public var searchActivated: ((Bool) -> Void)?
@ -291,6 +292,12 @@ open class ItemListControllerNode: ASDisplayNode, UIScrollViewDelegate {
self?.contentOffsetChanged?(offset, inVoiceOver)
}
self.listNode.beganInteractiveDragging = { [weak self] in
if let strongSelf = self {
strongSelf.beganInteractiveDragging?()
}
}
self.listNode.didEndScrolling = { [weak self] in
if let strongSelf = self {
let _ = strongSelf.contentScrollingEnded?(strongSelf.listNode)

View File

@ -63,6 +63,7 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
case currentSession(PresentationTheme, PresentationStrings, PresentationDateTimeFormat, RecentAccountSession)
case terminateOtherSessions(PresentationTheme, String)
case terminateAllWebSessions(PresentationTheme, String)
case currentAddDevice(PresentationTheme, String)
case currentSessionInfo(PresentationTheme, String)
case pendingSessionsHeader(PresentationTheme, String)
case pendingSession(index: Int32, theme: PresentationTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, session: RecentAccountSession, enabled: Bool, editing: Bool, revealed: Bool)
@ -75,12 +76,12 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
var section: ItemListSectionId {
switch self {
case .currentSessionHeader, .currentSession, .terminateOtherSessions, .terminateAllWebSessions, .currentSessionInfo:
return RecentSessionsSection.currentSession.rawValue
case .pendingSessionsHeader, .pendingSession, .pendingSessionsInfo:
return RecentSessionsSection.pendingSessions.rawValue
case .otherSessionsHeader, .addDevice, .session, .website, .devicesInfo:
return RecentSessionsSection.otherSessions.rawValue
case .currentSessionHeader, .currentSession, .terminateOtherSessions, .terminateAllWebSessions, .currentAddDevice, .currentSessionInfo:
return RecentSessionsSection.currentSession.rawValue
case .pendingSessionsHeader, .pendingSession, .pendingSessionsInfo:
return RecentSessionsSection.pendingSessions.rawValue
case .otherSessionsHeader, .addDevice, .session, .website, .devicesInfo:
return RecentSessionsSection.otherSessions.rawValue
}
}
@ -94,18 +95,20 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
return .index(2)
case .terminateAllWebSessions:
return .index(3)
case .currentAddDevice:
return .index(3)
case .currentSessionInfo:
return .index(4)
case .pendingSessionsHeader:
return .index(5)
case .pendingSessionsHeader:
return .index(6)
case let .pendingSession(_, _, _, _, session, _, _, _):
return .session(session.hash)
case .pendingSessionsInfo:
return .index(6)
case .otherSessionsHeader:
return .index(7)
case .addDevice:
case .otherSessionsHeader:
return .index(8)
case .addDevice:
return .index(9)
case let .session(_, _, _, _, session, _, _, _):
return .session(session.hash)
case let .website(_, _, _, _, _, website, _, _, _, _):
@ -135,6 +138,12 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
} else {
return false
}
case let .currentAddDevice(lhsTheme, lhsText):
if case let .currentAddDevice(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
return true
} else {
return false
}
case let .currentSessionInfo(lhsTheme, lhsText):
if case let .currentSessionInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
return true
@ -257,39 +266,48 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
let arguments = arguments as! RecentSessionsControllerArguments
switch self {
case let .currentSessionHeader(theme, text):
case let .currentSessionHeader(_, text):
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
case let .currentSession(theme, strings, dateTimeFormat, session):
case let .currentSession(_, strings, dateTimeFormat, session):
return ItemListRecentSessionItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, session: session, enabled: true, editable: false, editing: false, revealed: false, sectionId: self.section, setSessionIdWithRevealedOptions: { _, _ in
}, removeSession: { _ in
})
case let .terminateOtherSessions(theme, text):
case let .terminateOtherSessions(_, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.terminateOtherSessions()
})
case let .terminateAllWebSessions(theme, text):
case let .terminateAllWebSessions(_, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.terminateAllWebSessions()
})
case let .currentSessionInfo(theme, text):
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
case let .pendingSessionsHeader(theme, text):
case let .currentAddDevice(_, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.addDevice()
})
case let .currentSessionInfo(_, text):
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in
switch action {
case .tap:
arguments.openOtherAppsUrl()
}
})
case let .pendingSessionsHeader(_, text):
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
case let .pendingSession(_, theme, strings, dateTimeFormat, session, enabled, editing, revealed):
case let .pendingSession(_, _, _, dateTimeFormat, session, enabled, editing, revealed):
return ItemListRecentSessionItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, session: session, enabled: enabled, editable: true, editing: editing, revealed: revealed, sectionId: self.section, setSessionIdWithRevealedOptions: { previousId, id in
arguments.setSessionIdWithRevealedOptions(previousId, id)
}, removeSession: { id in
arguments.removeSession(id)
})
case let .pendingSessionsInfo(theme, text):
case let .pendingSessionsInfo(_, text):
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
case let .otherSessionsHeader(theme, text):
case let .otherSessionsHeader(_, text):
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
case let .addDevice(theme, text):
case let .addDevice(_, text):
return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
arguments.addDevice()
})
case let .session(_, theme, strings, dateTimeFormat, session, enabled, editing, revealed):
case let .session(_, _, _, dateTimeFormat, session, enabled, editing, revealed):
return ItemListRecentSessionItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, session: session, enabled: enabled, editable: true, editing: editing, revealed: revealed, sectionId: self.section, setSessionIdWithRevealedOptions: { previousId, id in
arguments.setSessionIdWithRevealedOptions(previousId, id)
}, removeSession: { id in
@ -301,7 +319,7 @@ private enum RecentSessionsEntry: ItemListNodeEntry {
}, removeSession: { id in
arguments.removeWebSession(id)
})
case let .devicesInfo(theme, text):
case let .devicesInfo(_, text):
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in
switch action {
case .tap:
@ -377,10 +395,17 @@ private func recentSessionsControllerEntries(presentationData: PresentationData,
entries.append(.currentSession(presentationData.theme, presentationData.strings, presentationData.dateTimeFormat, sessionsState.sessions[index]))
}
var hasAddDevice = false
if sessionsState.sessions.count > 1 || enableQRLogin {
entries.append(.terminateOtherSessions(presentationData.theme, presentationData.strings.AuthSessions_TerminateOtherSessions))
entries.append(.currentSessionInfo(presentationData.theme, presentationData.strings.AuthSessions_TerminateOtherSessionsHelp))
if sessionsState.sessions.count > 1 {
entries.append(.terminateOtherSessions(presentationData.theme, presentationData.strings.AuthSessions_TerminateOtherSessions))
entries.append(.currentSessionInfo(presentationData.theme, presentationData.strings.AuthSessions_TerminateOtherSessionsHelp))
} else if enableQRLogin {
hasAddDevice = true
entries.append(.currentAddDevice(presentationData.theme, presentationData.strings.AuthSessions_AddDevice))
entries.append(.currentSessionInfo(presentationData.theme, presentationData.strings.AuthSessions_OtherDevices))
}
let filteredPendingSessions: [RecentAccountSession] = sessionsState.sessions.filter({ $0.flags.contains(.passwordPending) })
if !filteredPendingSessions.isEmpty {
entries.append(.pendingSessionsHeader(presentationData.theme, presentationData.strings.AuthSessions_IncompleteAttempts))
@ -393,9 +418,11 @@ private func recentSessionsControllerEntries(presentationData: PresentationData,
entries.append(.pendingSessionsInfo(presentationData.theme, presentationData.strings.AuthSessions_IncompleteAttemptsInfo))
}
entries.append(.otherSessionsHeader(presentationData.theme, presentationData.strings.AuthSessions_OtherSessions))
if sessionsState.sessions.count > 1 {
entries.append(.otherSessionsHeader(presentationData.theme, presentationData.strings.AuthSessions_OtherSessions))
}
if enableQRLogin {
if enableQRLogin && !hasAddDevice {
entries.append(.addDevice(presentationData.theme, presentationData.strings.AuthSessions_AddDevice))
}
@ -410,7 +437,7 @@ private func recentSessionsControllerEntries(presentationData: PresentationData,
}
}
if enableQRLogin {
if enableQRLogin && !hasAddDevice {
entries.append(.devicesInfo(presentationData.theme, presentationData.strings.AuthSessions_OtherDevices))
}
}
@ -654,7 +681,12 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont
}
}
let emptyStateItem: ItemListControllerEmptyStateItem? = nil
let emptyStateItem: ItemListControllerEmptyStateItem?
if sessionsState.sessions.count == 1 && mode == .sessions {
emptyStateItem = RecentSessionsEmptyStateItem(theme: presentationData.theme, strings: presentationData.strings)
} else {
emptyStateItem = nil
}
let title: ItemListControllerTitle
let entries: [RecentSessionsEntry]

View File

@ -42,6 +42,29 @@ public func stringForMessageTimestamp(timestamp: Int32, dateTimeFormat: Presenta
return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat)
}
public func stringForMediumDate(timestamp: Int32, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) -> String {
var t: time_t = Int(timestamp)
var timeinfo = tm()
localtime_r(&t, &timeinfo);
let day = timeinfo.tm_mday
let month = timeinfo.tm_mon + 1
let year = timeinfo.tm_year
let dateString: String
let separator = dateTimeFormat.dateSeparator
switch dateTimeFormat.dateFormat {
case .monthFirst:
dateString = String(format: "%d%@%d%@%02d", month, separator, day, separator, year - 100)
case .dayFirst:
dateString = String(format: "%d%@%02d%@%02d", day, separator, month, separator, year - 100)
}
let timeString = stringForShortTimestamp(hours: Int32(timeinfo.tm_hour), minutes: Int32(timeinfo.tm_min), dateTimeFormat: dateTimeFormat)
return strings.Time_MediumDate(dateString, timeString).0
}
public func stringForFullDate(timestamp: Int32, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) -> String {
var t: time_t = Int(timestamp)
var timeinfo = tm()

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "ic_question.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -10,6 +10,7 @@ import TelegramPresentationData
import AlertUI
import PresentationDataUtils
import PeerInfoUI
import UndoUI
private enum SubscriberAction: Equatable {
case join
@ -95,6 +96,8 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
private let badgeText: ImmediateTextNode
private let activityIndicator: UIActivityIndicatorView
private let helpButton: HighlightableButtonNode
private var action: SubscriberAction?
private let actionDisposable = MetaDisposable()
@ -122,6 +125,8 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
self.badgeText.displaysAsynchronously = false
self.badgeText.isHidden = true
self.helpButton = HighlightableButtonNode()
self.discussButton.addSubnode(self.discussButtonText)
self.discussButton.addSubnode(self.badgeBackground)
self.discussButton.addSubnode(self.badgeText)
@ -131,9 +136,11 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
self.addSubnode(self.button)
self.addSubnode(self.discussButton)
self.view.addSubview(self.activityIndicator)
self.addSubnode(self.helpButton)
self.button.addTarget(self, action: #selector(self.buttonPressed), forControlEvents: .touchUpInside)
self.discussButton.addTarget(self, action: #selector(self.discussPressed), forControlEvents: .touchUpInside)
self.helpButton.addTarget(self, action: #selector(self.helpPressed), forControlEvents: .touchUpInside)
}
deinit {
@ -148,6 +155,10 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
return super.hitTest(point, with: event)
}
@objc func helpPressed() {
self.interfaceInteraction?.presentGigagroupHelp()
}
@objc func buttonPressed() {
guard let context = self.context, let action = self.action, let presentationInterfaceState = self.presentationInterfaceState, let peer = presentationInterfaceState.renderedPeer?.peer else {
return
@ -213,6 +224,7 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
if previousState?.theme !== interfaceState.theme {
self.badgeBackground.image = PresentationResourcesChatList.badgeBackgroundActive(interfaceState.theme, diameter: 20.0)
self.helpButton.setImage(generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/Help"), color: interfaceState.theme.chat.inputPanel.panelControlAccentColor), for: .normal)
}
if let peer = interfaceState.renderedPeer?.peer, previousState?.renderedPeer?.peer == nil || !peer.isEqual(previousState!.renderedPeer!.peer!) || previousState?.theme !== interfaceState.theme || previousState?.strings !== interfaceState.strings || previousState?.peerIsMuted != interfaceState.peerIsMuted || previousState?.pinnedMessage != interfaceState.pinnedMessage {
@ -234,10 +246,20 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
if let action = self.action, action == .muteNotifications || action == .unmuteNotifications {
let buttonWidth = self.button.titleNode.calculateSizeThatFits(CGSize(width: width, height: panelHeight)).width + 24.0
self.button.frame = CGRect(origin: CGPoint(x: floor((width - buttonWidth) / 2.0), y: 0.0), size: CGSize(width: buttonWidth, height: panelHeight))
if let peer = interfaceState.renderedPeer?.peer as? TelegramChannel, peer.flags.contains(.isGigagroup) {
self.helpButton.isHidden = false
} else {
self.helpButton.isHidden = true
}
} else {
self.button.frame = CGRect(origin: CGPoint(x: leftInset, y: 0.0), size: CGSize(width: width - leftInset - rightInset, height: panelHeight))
self.helpButton.isHidden = true
}
self.helpButton.frame = CGRect(x: width - rightInset - panelHeight, y: 0.0, width: panelHeight, height: panelHeight)
} else {
self.helpButton.isHidden = true
let availableWidth = min(600.0, width - leftInset - rightInset)
let leftOffset = floor((width - availableWidth) / 2.0)
self.button.frame = CGRect(origin: CGPoint(x: leftOffset, y: 0.0), size: CGSize(width: floor(availableWidth / 2.0), height: panelHeight))

View File

@ -6456,6 +6456,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return
}
presentAddMembers(context: strongSelf.context, parentController: strongSelf, groupPeer: peer, selectAddMemberDisposable: strongSelf.selectAddMemberDisposable, addMemberDisposable: strongSelf.addMemberDisposable)
}, presentGigagroupHelp: { [weak self] in
if let strongSelf = self {
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .info(text: strongSelf.presentationData.strings.Conversation_GigagroupDescription), elevatedLayout: false, action: { _ in return true }), in: .current)
}
}, editMessageMedia: { [weak self] messageId, draw in
if let strongSelf = self {
strongSelf.controllerInteraction?.editMessageMedia(messageId, draw)

View File

@ -129,6 +129,7 @@ final class ChatPanelInterfaceInteraction {
let editMessageMedia: (MessageId, Bool) -> Void
let joinGroupCall: (CachedChannelData.ActiveCall) -> Void
let presentInviteMembers: () -> Void
let presentGigagroupHelp: () -> Void
let statuses: ChatPanelInterfaceInteractionStatuses?
init(
@ -210,6 +211,7 @@ final class ChatPanelInterfaceInteraction {
activatePinnedListPreview: @escaping (ASDisplayNode, ContextGesture) -> Void,
joinGroupCall: @escaping (CachedChannelData.ActiveCall) -> Void,
presentInviteMembers: @escaping () -> Void,
presentGigagroupHelp: @escaping () -> Void,
editMessageMedia: @escaping (MessageId, Bool) -> Void,
statuses: ChatPanelInterfaceInteractionStatuses?
) {
@ -292,6 +294,7 @@ final class ChatPanelInterfaceInteraction {
self.editMessageMedia = editMessageMedia
self.joinGroupCall = joinGroupCall
self.presentInviteMembers = presentInviteMembers
self.presentGigagroupHelp = presentGigagroupHelp
self.statuses = statuses
}
}

View File

@ -134,6 +134,7 @@ final class ChatRecentActionsController: TelegramBaseController {
}, activatePinnedListPreview: { _, _ in
}, joinGroupCall: { _ in
}, presentInviteMembers: {
}, presentGigagroupHelp: {
}, editMessageMedia: { _, _ in
}, statuses: nil)

View File

@ -154,11 +154,34 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
}
case let .editExportedInvitation(_, invite), let .revokeExportedInvitation(invite), let .deleteExportedInvitation(invite), let .participantJoinedViaInvite(invite):
if !invite.link.hasSuffix("...") {
let controller = inviteLinkEditController(context: strongSelf.context, peerId: peer.id, invite: invite, completion: { [weak self] _ in
self?.eventLogContext.reload()
})
controller.navigationPresentation = .modal
strongSelf.pushController(controller)
if invite.isPermanent {
let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData)
var items: [ActionSheetItem] = []
items.append(ActionSheetTextItem(title: invite.link))
items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.InviteLink_ContextRevoke, color: .destructive, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
if let strongSelf = self {
let _ = (revokePeerExportedInvitation(account: strongSelf.context.account, peerId: peer.id, link: invite.link)
|> deliverOnMainQueue).start(completed: { [weak self] in
self?.eventLogContext.reload()
})
}
}))
actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
})
])])
strongSelf.presentController(actionSheet, nil)
} else {
let controller = inviteLinkEditController(context: strongSelf.context, peerId: peer.id, invite: invite, completion: { [weak self] _ in
self?.eventLogContext.reload()
})
controller.navigationPresentation = .modal
strongSelf.pushController(controller)
}
return true
}
case .changeHistoryTTL:

View File

@ -1187,7 +1187,7 @@ struct ChatRecentActionsEntry: Comparable, Identifiable {
var text: String = ""
var entities: [MessageTextEntity] = []
let rawText: (String, [(Int, NSRange)]) = self.presentationData.strings.Channel_AdminLog_UpdatedParticipantVolume(author?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "", participant?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "", "\(volume)")
let rawText: (String, [(Int, NSRange)]) = self.presentationData.strings.Channel_AdminLog_UpdatedParticipantVolume(author?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "", participant?.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder) ?? "", "\(volume / 100)%")
appendAttributedText(text: rawText, generateEntities: { index in
if index == 0, let author = author {

View File

@ -765,14 +765,10 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
let membersData: Signal<PeerInfoMembersData?, NoError> = combineLatest(membersContext.state, context.account.viewTracker.peerView(groupId, updateData: false))
|> map { state, view -> PeerInfoMembersData? in
if let peer = peerViewMainPeer(view) as? TelegramChannel, peer.flags.contains(.isGigagroup) {
return nil
if state.members.count > 5 {
return .longList(membersContext)
} else {
if state.members.count > 5 {
return .longList(membersContext)
} else {
return .shortList(membersContext: membersContext, members: state.members)
}
return .shortList(membersContext: membersContext, members: state.members)
}
}
|> distinctUntilChanged

View File

@ -446,6 +446,7 @@ final class PeerInfoSelectionPanelNode: ASDisplayNode {
}, activatePinnedListPreview: { _, _ in
}, joinGroupCall: { _ in
}, presentInviteMembers: {
}, presentGigagroupHelp: {
}, editMessageMedia: { _, _ in
}, statuses: nil)