mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
6fe8e5e447
commit
9d327ccd4b
File diff suppressed because it is too large
Load Diff
@ -294,7 +294,8 @@ private enum InviteLinksEditEntry: ItemListNodeEntry {
|
||||
}
|
||||
})
|
||||
case let .timeCustomPicker(_, dateTimeFormat, date):
|
||||
return ItemListDatePickerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, date: date, sectionId: self.section, style: .blocks, updated: { date in
|
||||
let title = presentationData.strings.InviteLink_Create_TimeLimitExpiryTime
|
||||
return ItemListDatePickerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, date: date, title: title, displayingDateSelection: false, displayingTimeSelection: false, sectionId: self.section, style: .blocks, toggleDateSelection: {}, toggleTimeSelection: {}, updated: { date in
|
||||
arguments.updateState({ state in
|
||||
var updatedState = state
|
||||
updatedState.time = .custom(date)
|
||||
|
@ -94,7 +94,7 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
|
||||
case timeHeader(PresentationTheme, String)
|
||||
case timeExpiryDate(PresentationTheme, PresentationDateTimeFormat, Int32?, Bool)
|
||||
case timeCustomPicker(PresentationTheme, PresentationDateTimeFormat, Int32?, Int32?, Int32?)
|
||||
case timeCustomPicker(PresentationTheme, PresentationDateTimeFormat, Int32?, Int32?, Int32?, Bool, Bool)
|
||||
case timeInfo(PresentationTheme, String)
|
||||
|
||||
case durationHeader(PresentationTheme, String)
|
||||
@ -282,8 +282,8 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .timeCustomPicker(lhsTheme, lhsDateTimeFormat, lhsDate, lhsMinDate, lhsMaxDate):
|
||||
if case let .timeCustomPicker(rhsTheme, rhsDateTimeFormat, rhsDate, rhsMinDate, rhsMaxDate) = rhs, lhsTheme === rhsTheme, lhsDateTimeFormat == rhsDateTimeFormat, lhsDate == rhsDate, lhsMinDate == rhsMinDate, lhsMaxDate == rhsMaxDate {
|
||||
case let .timeCustomPicker(lhsTheme, lhsDateTimeFormat, lhsDate, lhsMinDate, lhsMaxDate, lhsDisplayingDateSelection, lhsDisplayingTimeSelection):
|
||||
if case let .timeCustomPicker(rhsTheme, rhsDateTimeFormat, rhsDate, rhsMinDate, rhsMaxDate, rhsDisplayingDateSelection, rhsDisplayingTimeSelection) = rhs, lhsTheme === rhsTheme, lhsDateTimeFormat == rhsDateTimeFormat, lhsDate == rhsDate, lhsMinDate == rhsMinDate, lhsMaxDate == rhsMaxDate, lhsDisplayingDateSelection == rhsDisplayingDateSelection, lhsDisplayingTimeSelection == rhsDisplayingTimeSelection {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@ -437,8 +437,8 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
var focus = false
|
||||
arguments.updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.pickingTimeLimit = !state.pickingTimeLimit
|
||||
if updatedState.pickingTimeLimit {
|
||||
updatedState.pickingExpiryTime = !state.pickingExpiryTime
|
||||
if updatedState.pickingExpiryTime {
|
||||
focus = true
|
||||
}
|
||||
return updatedState
|
||||
@ -449,8 +449,41 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
}
|
||||
}
|
||||
})
|
||||
case let .timeCustomPicker(_, dateTimeFormat, date, minDate, maxDate):
|
||||
return ItemListDatePickerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, date: date, minDate: minDate, maxDate: maxDate, sectionId: self.section, style: .blocks, updated: { date in
|
||||
case let .timeCustomPicker(_, dateTimeFormat, date, minDate, maxDate, displayingDateSelection, displayingTimeSelection):
|
||||
let title = presentationData.strings.BoostGift_DateEnds
|
||||
return ItemListDatePickerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, date: date, minDate: minDate, maxDate: maxDate, title: title, displayingDateSelection: displayingDateSelection, displayingTimeSelection: displayingTimeSelection, sectionId: self.section, style: .blocks, toggleDateSelection: {
|
||||
var focus = false
|
||||
arguments.updateState({ state in
|
||||
var updatedState = state
|
||||
updatedState.pickingExpiryDate = !updatedState.pickingExpiryDate
|
||||
if updatedState.pickingExpiryDate {
|
||||
updatedState.pickingExpiryTime = false
|
||||
focus = true
|
||||
}
|
||||
return updatedState
|
||||
})
|
||||
if focus {
|
||||
Queue.mainQueue().after(0.1) {
|
||||
arguments.scrollToDate()
|
||||
}
|
||||
}
|
||||
}, toggleTimeSelection: {
|
||||
var focus = false
|
||||
arguments.updateState({ state in
|
||||
var updatedState = state
|
||||
updatedState.pickingExpiryTime = !updatedState.pickingExpiryTime
|
||||
if updatedState.pickingExpiryTime {
|
||||
updatedState.pickingExpiryDate = false
|
||||
focus = true
|
||||
}
|
||||
return updatedState
|
||||
})
|
||||
if focus {
|
||||
Queue.mainQueue().after(0.1) {
|
||||
arguments.scrollToDate()
|
||||
}
|
||||
}
|
||||
}, updated: { date in
|
||||
arguments.updateState({ state in
|
||||
var updatedState = state
|
||||
updatedState.time = date
|
||||
@ -585,10 +618,7 @@ private func createGiveawayControllerEntries(
|
||||
entries.append(.usersInfo(presentationData.theme, presentationData.strings.BoostGift_LimitSubscribersInfo))
|
||||
|
||||
entries.append(.timeHeader(presentationData.theme, presentationData.strings.BoostGift_DateTitle.uppercased()))
|
||||
entries.append(.timeExpiryDate(presentationData.theme, presentationData.dateTimeFormat, state.time, state.pickingTimeLimit))
|
||||
if state.pickingTimeLimit {
|
||||
entries.append(.timeCustomPicker(presentationData.theme, presentationData.dateTimeFormat, state.time, minDate, maxDate))
|
||||
}
|
||||
entries.append(.timeCustomPicker(presentationData.theme, presentationData.dateTimeFormat, state.time, minDate, maxDate, state.pickingExpiryDate, state.pickingExpiryTime))
|
||||
entries.append(.timeInfo(presentationData.theme, presentationData.strings.BoostGift_DateInfo(presentationData.strings.BoostGift_DateInfoSubscribers(Int32(state.subscriptions))).string))
|
||||
}
|
||||
|
||||
@ -656,7 +686,8 @@ private struct CreateGiveawayControllerState: Equatable {
|
||||
var countries: [String]
|
||||
var onlyNewEligible: Bool
|
||||
var time: Int32
|
||||
var pickingTimeLimit = false
|
||||
var pickingExpiryTime = false
|
||||
var pickingExpiryDate = false
|
||||
var revealedItemId: EnginePeer.Id? = nil
|
||||
var updating = false
|
||||
}
|
||||
@ -675,9 +706,19 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
} else {
|
||||
initialSubscriptions = 5
|
||||
}
|
||||
|
||||
let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
|
||||
let expiryTime = currentTime + 86400 * 3
|
||||
|
||||
let timeZone = TimeZone(secondsFromGMT: 0)!
|
||||
var calendar = Calendar(identifier: .gregorian)
|
||||
calendar.timeZone = timeZone
|
||||
let currentDate = Date()
|
||||
var components = calendar.dateComponents(Set([.era, .year, .month, .day, .hour, .minute, .second]), from: currentDate)
|
||||
components.hour = (components.hour ?? 0) + 1
|
||||
components.minute = 0
|
||||
components.second = 0
|
||||
let expiryDate = calendar.date(byAdding: .day, value: 3, to: calendar.date(from: components)!)!
|
||||
let expiryTime = Int32(expiryDate.timeIntervalSince1970)
|
||||
|
||||
let minDate = currentTime + 60 * 10
|
||||
let maxDate = currentTime + context.userLimits.maxGiveawayPeriodSeconds
|
||||
|
||||
@ -805,7 +846,10 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
let previousState = previousState.swap(state)
|
||||
var animateChanges = false
|
||||
if let previousState = previousState {
|
||||
if previousState.pickingTimeLimit != state.pickingTimeLimit {
|
||||
if previousState.pickingExpiryTime != state.pickingExpiryTime {
|
||||
animateChanges = true
|
||||
}
|
||||
if previousState.pickingExpiryDate != state.pickingExpiryDate {
|
||||
animateChanges = true
|
||||
}
|
||||
if previousState.mode != state.mode {
|
||||
|
@ -582,7 +582,7 @@ private enum StatsEntry: ItemListNodeEntry {
|
||||
title = peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder)
|
||||
icon = .peer(peer)
|
||||
if let _ = label {
|
||||
expiresString = expiresValue
|
||||
expiresString = "\(durationString) • \(expiresValue)"
|
||||
} else {
|
||||
expiresString = presentationData.strings.Stats_Boosts_ExpiresOn(expiresValue).string
|
||||
}
|
||||
|
@ -13,8 +13,16 @@ public class ItemListDatePickerItem: ListViewItem, ItemListItem {
|
||||
let date: Int32?
|
||||
let minDate: Int32?
|
||||
let maxDate: Int32?
|
||||
let title: String
|
||||
let displayingDateSelection: Bool
|
||||
let displayingTimeSelection: Bool
|
||||
|
||||
public let sectionId: ItemListSectionId
|
||||
let style: ItemListStyle
|
||||
|
||||
let toggleDateSelection: (() -> Void)?
|
||||
let toggleTimeSelection: (() -> Void)?
|
||||
|
||||
let updated: ((Int32) -> Void)?
|
||||
public let tag: ItemListItemTag?
|
||||
|
||||
@ -24,8 +32,13 @@ public class ItemListDatePickerItem: ListViewItem, ItemListItem {
|
||||
date: Int32?,
|
||||
minDate: Int32? = nil,
|
||||
maxDate: Int32? = nil,
|
||||
title: String,
|
||||
displayingDateSelection: Bool,
|
||||
displayingTimeSelection: Bool,
|
||||
sectionId: ItemListSectionId,
|
||||
style: ItemListStyle,
|
||||
toggleDateSelection: (() -> Void)?,
|
||||
toggleTimeSelection: (() -> Void)?,
|
||||
updated: ((Int32) -> Void)?,
|
||||
tag: ItemListItemTag? = nil
|
||||
) {
|
||||
@ -34,8 +47,13 @@ public class ItemListDatePickerItem: ListViewItem, ItemListItem {
|
||||
self.date = date
|
||||
self.minDate = minDate
|
||||
self.maxDate = maxDate
|
||||
self.title = title
|
||||
self.displayingDateSelection = displayingDateSelection
|
||||
self.displayingTimeSelection = displayingTimeSelection
|
||||
self.sectionId = sectionId
|
||||
self.style = style
|
||||
self.toggleDateSelection = toggleDateSelection
|
||||
self.toggleTimeSelection = toggleTimeSelection
|
||||
self.updated = updated
|
||||
self.tag = tag
|
||||
}
|
||||
@ -50,7 +68,7 @@ public class ItemListDatePickerItem: ListViewItem, ItemListItem {
|
||||
|
||||
Queue.mainQueue().async {
|
||||
completion(node, {
|
||||
return (nil, { _ in apply() })
|
||||
return (nil, { _ in apply(.None) })
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -65,7 +83,7 @@ public class ItemListDatePickerItem: ListViewItem, ItemListItem {
|
||||
let (layout, apply) = makeLayout(self, params, itemListNeighbors(item: self, topItem: previousItem as? ItemListItem, bottomItem: nextItem as? ItemListItem))
|
||||
Queue.mainQueue().async {
|
||||
completion(layout, { _ in
|
||||
apply()
|
||||
apply(animation)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -82,6 +100,8 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
private let bottomStripeNode: ASDisplayNode
|
||||
private let maskNode: ASImageNode
|
||||
|
||||
private let containerNode: ASDisplayNode
|
||||
|
||||
private var datePickerNode: DatePickerNode?
|
||||
|
||||
private var item: ItemListDatePickerItem?
|
||||
@ -108,12 +128,17 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
self.bottomStripeNode = ASDisplayNode()
|
||||
self.bottomStripeNode.isLayerBacked = true
|
||||
|
||||
self.containerNode = ASDisplayNode()
|
||||
self.containerNode.clipsToBounds = true
|
||||
|
||||
super.init(layerBacked: false, dynamicBounce: false)
|
||||
|
||||
self.addSubnode(self.containerNode)
|
||||
|
||||
self.allowsGroupOpacity = true
|
||||
}
|
||||
|
||||
public func asyncLayout() -> (_ item: ItemListDatePickerItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) {
|
||||
public func asyncLayout() -> (_ item: ItemListDatePickerItem, _ params: ListViewItemLayoutParams, _ insets: ItemListNeighbors) -> (ListViewItemNodeLayout, (ListViewItemUpdateAnimation) -> Void) {
|
||||
let currentItem = self.item
|
||||
|
||||
return { item, params, neighbors in
|
||||
@ -132,8 +157,15 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
|
||||
let width = min(390.0, params.width - params.leftInset - params.rightInset)
|
||||
let cellSize = floor((width - 12.0 * 2.0) / 7.0)
|
||||
let height: CGFloat = 122.0 + cellSize * 6.0
|
||||
|
||||
let pickerHeight = 122.0 + cellSize * 6.0
|
||||
let height: CGFloat
|
||||
if item.displayingDateSelection {
|
||||
height = pickerHeight
|
||||
} else if item.displayingTimeSelection {
|
||||
height = 260.0
|
||||
} else {
|
||||
height = 44.0
|
||||
}
|
||||
switch item.style {
|
||||
case .plain:
|
||||
itemBackgroundColor = item.presentationData.theme.list.plainBackgroundColor
|
||||
@ -147,9 +179,11 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
insets = itemListNeighborsGroupedInsets(neighbors, params)
|
||||
}
|
||||
|
||||
return (ListViewItemNodeLayout(contentSize: contentSize, insets: insets), { [weak self] in
|
||||
return (ListViewItemNodeLayout(contentSize: contentSize, insets: insets), { [weak self] animation in
|
||||
if let strongSelf = self {
|
||||
strongSelf.item = item
|
||||
|
||||
let transition = animation.transition
|
||||
|
||||
if let _ = updatedTheme {
|
||||
strongSelf.topStripeNode.backgroundColor = itemSeparatorColor
|
||||
@ -185,7 +219,7 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
strongSelf.insertSubnode(strongSelf.bottomStripeNode, at: 2)
|
||||
}
|
||||
if strongSelf.maskNode.supernode == nil {
|
||||
strongSelf.insertSubnode(strongSelf.maskNode, at: 3)
|
||||
strongSelf.addSubnode(strongSelf.maskNode)
|
||||
}
|
||||
|
||||
let hasCorners = itemListHasRoundedBlockLayout(params)
|
||||
@ -211,23 +245,38 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
|
||||
strongSelf.maskNode.image = hasCorners ? PresentationResourcesItemList.cornersImage(item.presentationData.theme, top: hasTopCorners, bottom: hasBottomCorners) : nil
|
||||
|
||||
strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
|
||||
strongSelf.maskNode.frame = strongSelf.backgroundNode.frame.insetBy(dx: params.leftInset, dy: 0.0)
|
||||
strongSelf.topStripeNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: separatorHeight))
|
||||
strongSelf.bottomStripeNode.frame = CGRect(origin: CGPoint(x: bottomStripeInset, y: contentSize.height - separatorHeight), size: CGSize(width: params.width - bottomStripeInset, height: separatorHeight))
|
||||
transition.updateFrame(node: strongSelf.backgroundNode, frame: CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight))))
|
||||
transition.updateFrame(node: strongSelf.maskNode, frame: strongSelf.backgroundNode.frame.insetBy(dx: params.leftInset, dy: 0.0))
|
||||
transition.updateFrame(node: strongSelf.topStripeNode, frame: CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: separatorHeight)))
|
||||
transition.updateFrame(node: strongSelf.bottomStripeNode, frame: CGRect(origin: CGPoint(x: bottomStripeInset, y: contentSize.height - separatorHeight), size: CGSize(width: params.width - bottomStripeInset, height: separatorHeight)))
|
||||
}
|
||||
|
||||
let datePickerNode: DatePickerNode
|
||||
if let current = strongSelf.datePickerNode {
|
||||
datePickerNode = current
|
||||
} else {
|
||||
datePickerNode = DatePickerNode(theme: DatePickerTheme(theme: item.presentationData.theme), strings: item.presentationData.strings, dateTimeFormat: item.dateTimeFormat)
|
||||
strongSelf.insertSubnode(datePickerNode, belowSubnode: strongSelf.topStripeNode)
|
||||
datePickerNode = DatePickerNode(theme: DatePickerTheme(theme: item.presentationData.theme), strings: item.presentationData.strings, dateTimeFormat: item.dateTimeFormat, title: item.title)
|
||||
strongSelf.containerNode.addSubnode(datePickerNode)
|
||||
strongSelf.datePickerNode = datePickerNode
|
||||
}
|
||||
datePickerNode.valueUpdated = { date in
|
||||
strongSelf.item?.updated?(Int32(date.timeIntervalSince1970))
|
||||
datePickerNode.valueUpdated = { [weak self] date in
|
||||
if let self {
|
||||
self.item?.updated?(Int32(date.timeIntervalSince1970))
|
||||
}
|
||||
}
|
||||
datePickerNode.toggleDateSelection = { [weak self] in
|
||||
if let self {
|
||||
self.item?.toggleDateSelection?()
|
||||
}
|
||||
}
|
||||
datePickerNode.toggleTimeSelection = { [weak self] in
|
||||
if let self {
|
||||
self.item?.toggleTimeSelection?()
|
||||
}
|
||||
}
|
||||
|
||||
datePickerNode.displayDateSelection = item.displayingDateSelection
|
||||
datePickerNode.displayTimeSelection = item.displayingTimeSelection
|
||||
|
||||
if let minDate = item.minDate {
|
||||
datePickerNode.minimumDate = Date(timeIntervalSince1970: TimeInterval(minDate))
|
||||
@ -240,9 +289,12 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
|
||||
|
||||
datePickerNode.date = item.date.flatMap { Date(timeIntervalSince1970: TimeInterval($0)) }
|
||||
|
||||
let datePickerSize = CGSize(width: width, height: contentSize.height)
|
||||
let datePickerSize = CGSize(width: width, height: pickerHeight)
|
||||
datePickerNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((params.width - datePickerSize.width) / 2.0), y: 0.0), size: datePickerSize)
|
||||
datePickerNode.updateLayout(size: datePickerSize, transition: .immediate)
|
||||
|
||||
transition.updateFrame(node: strongSelf.containerNode, frame: CGRect(origin: .zero, size: CGSize(width: params.width, height: contentSize.height)))
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user