mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Temp
This commit is contained in:
114
submodules/TelegramUI/Sources/ChatDateSelectionSheet.swift
Normal file
114
submodules/TelegramUI/Sources/ChatDateSelectionSheet.swift
Normal file
@@ -0,0 +1,114 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
import AsyncDisplayKit
|
||||
import UIKit
|
||||
import SwiftSignalKit
|
||||
import Photos
|
||||
import TelegramPresentationData
|
||||
|
||||
final class ChatDateSelectionSheet: ActionSheetController {
|
||||
private let strings: PresentationStrings
|
||||
|
||||
private let _ready = Promise<Bool>()
|
||||
override var ready: Promise<Bool> {
|
||||
return self._ready
|
||||
}
|
||||
|
||||
init(presentationData: PresentationData, completion: @escaping (Int32) -> Void) {
|
||||
self.strings = presentationData.strings
|
||||
|
||||
super.init(theme: ActionSheetControllerTheme(presentationData: presentationData))
|
||||
|
||||
self._ready.set(.single(true))
|
||||
|
||||
var updatedValue: Int32?
|
||||
self.setItemGroups([
|
||||
ActionSheetItemGroup(items: [
|
||||
ChatDateSelectorItem(strings: self.strings, valueChanged: { value in
|
||||
updatedValue = value
|
||||
}),
|
||||
ActionSheetButtonItem(title: self.strings.Common_Search, action: { [weak self] in
|
||||
self?.dismissAnimated()
|
||||
if let updatedValue = updatedValue {
|
||||
completion(updatedValue)
|
||||
}
|
||||
})
|
||||
]),
|
||||
ActionSheetItemGroup(items: [
|
||||
ActionSheetButtonItem(title: self.strings.Common_Cancel, action: { [weak self] in
|
||||
self?.dismissAnimated()
|
||||
}),
|
||||
])
|
||||
])
|
||||
}
|
||||
|
||||
required init(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
private final class ChatDateSelectorItem: ActionSheetItem {
|
||||
let strings: PresentationStrings
|
||||
|
||||
let valueChanged: (Int32) -> Void
|
||||
|
||||
init(strings: PresentationStrings, valueChanged: @escaping (Int32) -> Void) {
|
||||
self.strings = strings
|
||||
self.valueChanged = valueChanged
|
||||
}
|
||||
|
||||
func node(theme: ActionSheetControllerTheme) -> ActionSheetItemNode {
|
||||
return ChatDateSelectorItemNode(theme: theme, strings: self.strings, valueChanged: self.valueChanged)
|
||||
}
|
||||
|
||||
func updateNode(_ node: ActionSheetItemNode) {
|
||||
}
|
||||
}
|
||||
|
||||
private final class ChatDateSelectorItemNode: ActionSheetItemNode {
|
||||
private let theme: ActionSheetControllerTheme
|
||||
private let strings: PresentationStrings
|
||||
|
||||
private let pickerView: UIDatePicker
|
||||
|
||||
private let valueChanged: (Int32) -> Void
|
||||
|
||||
private var currentValue: Int32 {
|
||||
return Int32(self.pickerView.date.timeIntervalSince1970)
|
||||
}
|
||||
|
||||
init(theme: ActionSheetControllerTheme, strings: PresentationStrings, valueChanged: @escaping (Int32) -> Void) {
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.valueChanged = valueChanged
|
||||
|
||||
self.pickerView = UIDatePicker()
|
||||
self.pickerView.setValue(theme.primaryTextColor, forKey: "textColor")
|
||||
self.pickerView.datePickerMode = .countDownTimer
|
||||
self.pickerView.datePickerMode = .date
|
||||
self.pickerView.locale = Locale(identifier: strings.baseLanguageCode)
|
||||
|
||||
self.pickerView.minimumDate = Date(timeIntervalSince1970: 1376438400.0)
|
||||
self.pickerView.maximumDate = Date(timeIntervalSinceNow: 2.0)
|
||||
|
||||
super.init(theme: theme)
|
||||
|
||||
self.view.addSubview(self.pickerView)
|
||||
self.pickerView.addTarget(self, action: #selector(self.pickerChanged), for: .valueChanged)
|
||||
}
|
||||
|
||||
override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize {
|
||||
return CGSize(width: constrainedSize.width, height: 157.0)
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
super.layout()
|
||||
|
||||
self.pickerView.frame = CGRect(origin: CGPoint(), size: CGSize(width: self.bounds.size.width, height: 180.0))
|
||||
}
|
||||
|
||||
@objc func pickerChanged() {
|
||||
self.valueChanged(self.currentValue)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user