mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various improvements
This commit is contained in:
@@ -30,10 +30,11 @@ private final class CreateGiveawayControllerArguments {
|
||||
let openCountriesSelection: () -> Void
|
||||
let openPremiumIntro: () -> Void
|
||||
let scrollToDate: () -> Void
|
||||
let scrollToDescription: () -> Void
|
||||
let setItemIdWithRevealedOptions: (EnginePeer.Id?, EnginePeer.Id?) -> Void
|
||||
let removeChannel: (EnginePeer.Id) -> Void
|
||||
|
||||
init(context: AccountContext, updateState: @escaping ((CreateGiveawayControllerState) -> CreateGiveawayControllerState) -> Void, dismissInput: @escaping () -> Void, openPeersSelection: @escaping () -> Void, openChannelsSelection: @escaping () -> Void, openCountriesSelection: @escaping () -> Void, openPremiumIntro: @escaping () -> Void, scrollToDate: @escaping () -> Void, setItemIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, removeChannel: @escaping (EnginePeer.Id) -> Void) {
|
||||
init(context: AccountContext, updateState: @escaping ((CreateGiveawayControllerState) -> CreateGiveawayControllerState) -> Void, dismissInput: @escaping () -> Void, openPeersSelection: @escaping () -> Void, openChannelsSelection: @escaping () -> Void, openCountriesSelection: @escaping () -> Void, openPremiumIntro: @escaping () -> Void, scrollToDate: @escaping () -> Void, scrollToDescription: @escaping () -> Void, setItemIdWithRevealedOptions: @escaping (EnginePeer.Id?, EnginePeer.Id?) -> Void, removeChannel: @escaping (EnginePeer.Id) -> Void) {
|
||||
self.context = context
|
||||
self.updateState = updateState
|
||||
self.dismissInput = dismissInput
|
||||
@@ -42,6 +43,7 @@ private final class CreateGiveawayControllerArguments {
|
||||
self.openCountriesSelection = openCountriesSelection
|
||||
self.openPremiumIntro = openPremiumIntro
|
||||
self.scrollToDate = scrollToDate
|
||||
self.scrollToDescription = scrollToDescription
|
||||
self.setItemIdWithRevealedOptions = setItemIdWithRevealedOptions
|
||||
self.removeChannel = removeChannel
|
||||
}
|
||||
@@ -60,6 +62,7 @@ private enum CreateGiveawaySection: Int32 {
|
||||
}
|
||||
|
||||
private enum CreateGiveawayEntryTag: ItemListItemTag {
|
||||
case description
|
||||
case date
|
||||
|
||||
func isEqual(to other: ItemListItemTag) -> Bool {
|
||||
@@ -94,12 +97,12 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
case usersNew(PresentationTheme, String, String, Bool)
|
||||
case usersInfo(PresentationTheme, String)
|
||||
|
||||
case winnersHeader(PresentationTheme, String)
|
||||
case winners(PresentationTheme, String, Bool)
|
||||
case winnersInfo(PresentationTheme, String)
|
||||
case durationHeader(PresentationTheme, String)
|
||||
case duration(Int32, PresentationTheme, Int32, String, String, String, String?, Bool)
|
||||
case durationInfo(PresentationTheme, String)
|
||||
|
||||
case prizeDescriptionHeader(PresentationTheme, String)
|
||||
case prizeDescription(PresentationTheme, String, String)
|
||||
case prizeDescription(PresentationTheme, String, Bool)
|
||||
case prizeDescriptionText(PresentationTheme, String, String, Int32)
|
||||
case prizeDescriptionInfo(PresentationTheme, String)
|
||||
|
||||
case timeHeader(PresentationTheme, String)
|
||||
@@ -107,9 +110,8 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
case timeCustomPicker(PresentationTheme, PresentationDateTimeFormat, Int32?, Int32?, Int32?, Bool, Bool)
|
||||
case timeInfo(PresentationTheme, String)
|
||||
|
||||
case durationHeader(PresentationTheme, String)
|
||||
case duration(Int32, PresentationTheme, Int32, String, String, String, String?, Bool)
|
||||
case durationInfo(PresentationTheme, String)
|
||||
case winners(PresentationTheme, String, Bool)
|
||||
case winnersInfo(PresentationTheme, String)
|
||||
|
||||
var section: ItemListSectionId {
|
||||
switch self {
|
||||
@@ -123,77 +125,75 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
return CreateGiveawaySection.channels.rawValue
|
||||
case .usersHeader, .usersAll, .usersNew, .usersInfo:
|
||||
return CreateGiveawaySection.users.rawValue
|
||||
case .winnersHeader, .winners, .winnersInfo:
|
||||
return CreateGiveawaySection.winners.rawValue
|
||||
case .prizeDescriptionHeader, .prizeDescription, .prizeDescriptionInfo:
|
||||
case .durationHeader, .duration, .durationInfo:
|
||||
return CreateGiveawaySection.duration.rawValue
|
||||
case .prizeDescription, .prizeDescriptionText, .prizeDescriptionInfo:
|
||||
return CreateGiveawaySection.prizeDescription.rawValue
|
||||
case .timeHeader, .timeExpiryDate, .timeCustomPicker, .timeInfo:
|
||||
return CreateGiveawaySection.time.rawValue
|
||||
case .durationHeader, .duration, .durationInfo:
|
||||
return CreateGiveawaySection.duration.rawValue
|
||||
case .winners, .winnersInfo:
|
||||
return CreateGiveawaySection.winners.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
var stableId: Int32 {
|
||||
switch self {
|
||||
case .header:
|
||||
return -1
|
||||
case .createGiveaway:
|
||||
return 0
|
||||
case .awardUsers:
|
||||
return 1
|
||||
case .prepaidHeader:
|
||||
return 2
|
||||
case .prepaid:
|
||||
return 3
|
||||
case .subscriptionsHeader:
|
||||
return 4
|
||||
case .subscriptions:
|
||||
return 5
|
||||
case .subscriptionsInfo:
|
||||
return 6
|
||||
case .channelsHeader:
|
||||
return 7
|
||||
case let .channel(index, _, _, _, _):
|
||||
return 8 + index
|
||||
case .channelAdd:
|
||||
return 100
|
||||
case .channelsInfo:
|
||||
return 101
|
||||
case .usersHeader:
|
||||
return 102
|
||||
case .usersAll:
|
||||
return 103
|
||||
case .usersNew:
|
||||
return 104
|
||||
case .usersInfo:
|
||||
return 105
|
||||
case .winnersHeader:
|
||||
return 106
|
||||
case .winners:
|
||||
return 107
|
||||
case .winnersInfo:
|
||||
return 108
|
||||
case .prizeDescriptionHeader:
|
||||
return 109
|
||||
case .prizeDescription:
|
||||
return 110
|
||||
case .prizeDescriptionInfo:
|
||||
return 111
|
||||
case .timeHeader:
|
||||
return 112
|
||||
case .timeExpiryDate:
|
||||
return 113
|
||||
case .timeCustomPicker:
|
||||
return 114
|
||||
case .timeInfo:
|
||||
return 115
|
||||
case .durationHeader:
|
||||
return 116
|
||||
case let .duration(index, _, _, _, _, _, _, _):
|
||||
return 117 + index
|
||||
case .durationInfo:
|
||||
return 130
|
||||
case .header:
|
||||
return -1
|
||||
case .createGiveaway:
|
||||
return 0
|
||||
case .awardUsers:
|
||||
return 1
|
||||
case .prepaidHeader:
|
||||
return 2
|
||||
case .prepaid:
|
||||
return 3
|
||||
case .subscriptionsHeader:
|
||||
return 4
|
||||
case .subscriptions:
|
||||
return 5
|
||||
case .subscriptionsInfo:
|
||||
return 6
|
||||
case .channelsHeader:
|
||||
return 7
|
||||
case let .channel(index, _, _, _, _):
|
||||
return 8 + index
|
||||
case .channelAdd:
|
||||
return 100
|
||||
case .channelsInfo:
|
||||
return 101
|
||||
case .usersHeader:
|
||||
return 102
|
||||
case .usersAll:
|
||||
return 103
|
||||
case .usersNew:
|
||||
return 104
|
||||
case .usersInfo:
|
||||
return 105
|
||||
case .durationHeader:
|
||||
return 106
|
||||
case let .duration(index, _, _, _, _, _, _, _):
|
||||
return 107 + index
|
||||
case .durationInfo:
|
||||
return 200
|
||||
case .prizeDescription:
|
||||
return 201
|
||||
case .prizeDescriptionText:
|
||||
return 202
|
||||
case .prizeDescriptionInfo:
|
||||
return 203
|
||||
case .timeHeader:
|
||||
return 204
|
||||
case .timeExpiryDate:
|
||||
return 205
|
||||
case .timeCustomPicker:
|
||||
return 206
|
||||
case .timeInfo:
|
||||
return 207
|
||||
case .winners:
|
||||
return 208
|
||||
case .winnersInfo:
|
||||
return 209
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,32 +295,32 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .winnersHeader(lhsTheme, lhsText):
|
||||
if case let .winnersHeader(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
case let .durationHeader(lhsTheme, lhsText):
|
||||
if case let .durationHeader(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .winners(lhsTheme, lhsText, lhsValue):
|
||||
if case let .winners(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue {
|
||||
case let .duration(lhsIndex, lhsTheme, lhsMonths, lhsTitle, lhsSubtitle, lhsLabel, lhsBadge, lhsIsSelected):
|
||||
if case let .duration(rhsIndex, rhsTheme, rhsMonths, rhsTitle, rhsSubtitle, rhsLabel, rhsBadge, rhsIsSelected) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsMonths == rhsMonths, lhsTitle == rhsTitle, lhsSubtitle == rhsSubtitle, lhsLabel == rhsLabel, lhsBadge == rhsBadge, lhsIsSelected == rhsIsSelected {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .winnersInfo(lhsTheme, lhsText):
|
||||
if case let .winnersInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
case let .durationInfo(lhsTheme, lhsText):
|
||||
if case let .durationInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .prizeDescriptionHeader(lhsTheme, lhsText):
|
||||
if case let .prizeDescriptionHeader(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
case let .prizeDescription(lhsTheme, lhsText, lhsValue):
|
||||
if case let .prizeDescription(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .prizeDescription(lhsTheme, lhsPlaceholder, lhsValue):
|
||||
if case let .prizeDescription(rhsTheme, rhsPlaceholder, rhsValue) = rhs, lhsTheme === rhsTheme, lhsPlaceholder == rhsPlaceholder, lhsValue == rhsValue {
|
||||
case let .prizeDescriptionText(lhsTheme, lhsPlaceholder, lhsValue, lhsCount):
|
||||
if case let .prizeDescriptionText(rhsTheme, rhsPlaceholder, rhsValue, rhsCount) = rhs, lhsTheme === rhsTheme, lhsPlaceholder == rhsPlaceholder, lhsValue == rhsValue, lhsCount == rhsCount {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@@ -355,20 +355,14 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .durationHeader(lhsTheme, lhsText):
|
||||
if case let .durationHeader(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
case let .winners(lhsTheme, lhsText, lhsValue):
|
||||
if case let .winners(rhsTheme, rhsText, rhsValue) = rhs, lhsTheme === rhsTheme, lhsText == rhsText, lhsValue == rhsValue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .duration(lhsIndex, lhsTheme, lhsMonths, lhsTitle, lhsSubtitle, lhsLabel, lhsBadge, lhsIsSelected):
|
||||
if case let .duration(rhsIndex, rhsTheme, rhsMonths, rhsTitle, rhsSubtitle, rhsLabel, rhsBadge, rhsIsSelected) = rhs, lhsIndex == rhsIndex, lhsTheme === rhsTheme, lhsMonths == rhsMonths, lhsTitle == rhsTitle, lhsSubtitle == rhsSubtitle, lhsLabel == rhsLabel, lhsBadge == rhsBadge, lhsIsSelected == rhsIsSelected {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .durationInfo(lhsTheme, lhsText):
|
||||
if case let .durationInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
case let .winnersInfo(lhsTheme, lhsText):
|
||||
if case let .winnersInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
@@ -484,30 +478,44 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
})
|
||||
case let .usersInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
case let .winnersHeader(_, text):
|
||||
case let .durationHeader(_, text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .winners(_, text, value):
|
||||
return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
case let .duration(_, _, months, title, subtitle, label, badge, isSelected):
|
||||
return GiftOptionItem(presentationData: presentationData, context: arguments.context, title: title, subtitle: subtitle, subtitleFont: .small, label: .generic(label), badge: badge, isSelected: isSelected, sectionId: self.section, action: {
|
||||
arguments.updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.showWinners = value
|
||||
updatedState.selectedMonths = months
|
||||
return updatedState
|
||||
}
|
||||
})
|
||||
case let .winnersInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
case let .prizeDescriptionHeader(_, text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .prizeDescription(_, placeholder, value):
|
||||
return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: placeholder, sectionId: self.section, textUpdated: { value in
|
||||
case let .durationInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { _ in
|
||||
arguments.openPremiumIntro()
|
||||
})
|
||||
case let .prizeDescription(_, text, value):
|
||||
return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
arguments.updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.showPrizeDescription = value
|
||||
return updatedState
|
||||
}
|
||||
})
|
||||
case let .prizeDescriptionText(_, placeholder, value, count):
|
||||
return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: "\(count)"), text: value, placeholder: placeholder, returnKeyType: .done, spacing: 24.0, tag: CreateGiveawayEntryTag.description, sectionId: self.section, textUpdated: { value in
|
||||
arguments.updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.prizeDescription = value
|
||||
return updatedState
|
||||
}
|
||||
}, action: {})
|
||||
}, updatedFocus: { focused in
|
||||
if focused {
|
||||
arguments.scrollToDescription()
|
||||
}
|
||||
}, action: {
|
||||
arguments.dismissInput()
|
||||
})
|
||||
case let .prizeDescriptionInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section)
|
||||
case let .timeHeader(_, text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .timeExpiryDate(theme, dateTimeFormat, value, active):
|
||||
@@ -577,20 +585,16 @@ private enum CreateGiveawayEntry: ItemListNodeEntry {
|
||||
}, tag: CreateGiveawayEntryTag.date)
|
||||
case let .timeInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
case let .durationHeader(_, text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .duration(_, _, months, title, subtitle, label, badge, isSelected):
|
||||
return GiftOptionItem(presentationData: presentationData, context: arguments.context, title: title, subtitle: subtitle, subtitleFont: .small, label: .generic(label), badge: badge, isSelected: isSelected, sectionId: self.section, action: {
|
||||
case let .winners(_, text, value):
|
||||
return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in
|
||||
arguments.updateState { state in
|
||||
var updatedState = state
|
||||
updatedState.selectedMonths = months
|
||||
updatedState.showWinners = value
|
||||
return updatedState
|
||||
}
|
||||
})
|
||||
case let .durationInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { _ in
|
||||
arguments.openPremiumIntro()
|
||||
})
|
||||
case let .winnersInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -658,64 +662,7 @@ private func createGiveawayControllerEntries(
|
||||
entries.append(.prepaid(presentationData.theme, presentationData.strings.BoostGift_PrepaidGiveawayCount(prepaidGiveaway.quantity), presentationData.strings.BoostGift_PrepaidGiveawayMonths("\(prepaidGiveaway.months)").string, prepaidGiveaway))
|
||||
}
|
||||
|
||||
if case .giveaway = state.mode {
|
||||
if case .generic = subject {
|
||||
entries.append(.subscriptionsHeader(presentationData.theme, presentationData.strings.BoostGift_QuantityTitle.uppercased(), presentationData.strings.BoostGift_QuantityBoosts(state.subscriptions * 4)))
|
||||
entries.append(.subscriptions(presentationData.theme, state.subscriptions))
|
||||
entries.append(.subscriptionsInfo(presentationData.theme, presentationData.strings.BoostGift_QuantityInfo))
|
||||
}
|
||||
|
||||
entries.append(.channelsHeader(presentationData.theme, presentationData.strings.BoostGift_ChannelsTitle.uppercased()))
|
||||
var index: Int32 = 0
|
||||
let channels = [peerId] + state.channels
|
||||
for channelId in channels {
|
||||
if let channel = peers[channelId] {
|
||||
entries.append(.channel(index, presentationData.theme, channel, channel.id == peerId ? state.subscriptions * 4 : nil, false))
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
entries.append(.channelAdd(presentationData.theme, presentationData.strings.BoostGift_AddChannel))
|
||||
entries.append(.channelsInfo(presentationData.theme, presentationData.strings.BoostGift_ChannelsInfo))
|
||||
|
||||
entries.append(.usersHeader(presentationData.theme, presentationData.strings.BoostGift_UsersTitle.uppercased()))
|
||||
|
||||
let countriesText: String
|
||||
if state.countries.count > 2 {
|
||||
countriesText = presentationData.strings.BoostGift_FromCountries(Int32(state.countries.count))
|
||||
} else if !state.countries.isEmpty {
|
||||
if state.countries.count == 2 {
|
||||
let firstCountryCode = state.countries.first ?? ""
|
||||
let secondCountryCode = state.countries.last ?? ""
|
||||
let firstCountryName = locale.localizedString(forRegionCode: firstCountryCode) ?? firstCountryCode
|
||||
let secondCountryName = locale.localizedString(forRegionCode: secondCountryCode) ?? secondCountryCode
|
||||
countriesText = presentationData.strings.BoostGift_FromTwoCountries(firstCountryName, secondCountryName).string
|
||||
} else {
|
||||
let countryCode = state.countries.first ?? ""
|
||||
let countryName = locale.localizedString(forRegionCode: countryCode) ?? countryCode
|
||||
countriesText = presentationData.strings.BoostGift_FromOneCountry(countryName).string
|
||||
}
|
||||
} else {
|
||||
countriesText = presentationData.strings.BoostGift_FromAllCountries
|
||||
}
|
||||
|
||||
entries.append(.usersAll(presentationData.theme, presentationData.strings.BoostGift_AllSubscribers, countriesText, !state.onlyNewEligible))
|
||||
entries.append(.usersNew(presentationData.theme, presentationData.strings.BoostGift_OnlyNewSubscribers, countriesText, state.onlyNewEligible))
|
||||
entries.append(.usersInfo(presentationData.theme, presentationData.strings.BoostGift_LimitSubscribersInfo))
|
||||
|
||||
entries.append(.winnersHeader(presentationData.theme, presentationData.strings.BoostGift_WinnersTitle.uppercased()))
|
||||
entries.append(.winners(presentationData.theme, presentationData.strings.BoostGift_Winners, state.showWinners))
|
||||
entries.append(.winnersInfo(presentationData.theme, presentationData.strings.BoostGift_WinnersInfo))
|
||||
|
||||
entries.append(.prizeDescriptionHeader(presentationData.theme, "Additional Prizes".uppercased()))
|
||||
entries.append(.prizeDescription(presentationData.theme, "Prize Description (Optional)", state.prizeDescription))
|
||||
entries.append(.prizeDescriptionInfo(presentationData.theme, "Provide description of any additional prizes you plan to award to the winners, in addition to Telegram Premium."))
|
||||
|
||||
entries.append(.timeHeader(presentationData.theme, presentationData.strings.BoostGift_DateTitle.uppercased()))
|
||||
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))
|
||||
}
|
||||
|
||||
if case .generic = subject {
|
||||
let appendDurationEntries = {
|
||||
entries.append(.durationHeader(presentationData.theme, presentationData.strings.BoostGift_DurationTitle.uppercased()))
|
||||
|
||||
let recipientCount: Int
|
||||
@@ -762,6 +709,82 @@ private func createGiveawayControllerEntries(
|
||||
entries.append(.durationInfo(presentationData.theme, presentationData.strings.BoostGift_PremiumInfo))
|
||||
}
|
||||
|
||||
switch state.mode {
|
||||
case .giveaway:
|
||||
if case .generic = subject {
|
||||
entries.append(.subscriptionsHeader(presentationData.theme, presentationData.strings.BoostGift_QuantityTitle.uppercased(), presentationData.strings.BoostGift_QuantityBoosts(state.subscriptions * 4)))
|
||||
entries.append(.subscriptions(presentationData.theme, state.subscriptions))
|
||||
entries.append(.subscriptionsInfo(presentationData.theme, presentationData.strings.BoostGift_QuantityInfo))
|
||||
}
|
||||
|
||||
entries.append(.channelsHeader(presentationData.theme, presentationData.strings.BoostGift_ChannelsTitle.uppercased()))
|
||||
var index: Int32 = 0
|
||||
let channels = [peerId] + state.channels
|
||||
for channelId in channels {
|
||||
if let channel = peers[channelId] {
|
||||
entries.append(.channel(index, presentationData.theme, channel, channel.id == peerId ? state.subscriptions * 4 : nil, false))
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
entries.append(.channelAdd(presentationData.theme, presentationData.strings.BoostGift_AddChannel))
|
||||
entries.append(.channelsInfo(presentationData.theme, presentationData.strings.BoostGift_ChannelsInfo))
|
||||
|
||||
entries.append(.usersHeader(presentationData.theme, presentationData.strings.BoostGift_UsersTitle.uppercased()))
|
||||
|
||||
let countriesText: String
|
||||
if state.countries.count > 2 {
|
||||
countriesText = presentationData.strings.BoostGift_FromCountries(Int32(state.countries.count))
|
||||
} else if !state.countries.isEmpty {
|
||||
if state.countries.count == 2 {
|
||||
let firstCountryCode = state.countries.first ?? ""
|
||||
let secondCountryCode = state.countries.last ?? ""
|
||||
let firstCountryName = locale.localizedString(forRegionCode: firstCountryCode) ?? firstCountryCode
|
||||
let secondCountryName = locale.localizedString(forRegionCode: secondCountryCode) ?? secondCountryCode
|
||||
countriesText = presentationData.strings.BoostGift_FromTwoCountries(firstCountryName, secondCountryName).string
|
||||
} else {
|
||||
let countryCode = state.countries.first ?? ""
|
||||
let countryName = locale.localizedString(forRegionCode: countryCode) ?? countryCode
|
||||
countriesText = presentationData.strings.BoostGift_FromOneCountry(countryName).string
|
||||
}
|
||||
} else {
|
||||
countriesText = presentationData.strings.BoostGift_FromAllCountries
|
||||
}
|
||||
|
||||
entries.append(.usersAll(presentationData.theme, presentationData.strings.BoostGift_AllSubscribers, countriesText, !state.onlyNewEligible))
|
||||
entries.append(.usersNew(presentationData.theme, presentationData.strings.BoostGift_OnlyNewSubscribers, countriesText, state.onlyNewEligible))
|
||||
entries.append(.usersInfo(presentationData.theme, presentationData.strings.BoostGift_LimitSubscribersInfo))
|
||||
|
||||
if case .generic = subject {
|
||||
appendDurationEntries()
|
||||
}
|
||||
|
||||
entries.append(.prizeDescription(presentationData.theme, presentationData.strings.BoostGift_AdditionalPrizes, state.showPrizeDescription))
|
||||
var prizeDescriptionInfoText = presentationData.strings.BoostGift_AdditionalPrizesInfoOff
|
||||
if state.showPrizeDescription {
|
||||
entries.append(.prizeDescriptionText(presentationData.theme, presentationData.strings.BoostGift_AdditionalPrizesPlaceholder, state.prizeDescription, state.subscriptions))
|
||||
|
||||
let monthsString = presentationData.strings.BoostGift_AdditionalPrizesInfoForMonths(state.selectedMonths ?? 3)
|
||||
if state.prizeDescription.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
let subscriptionsString = presentationData.strings.BoostGift_AdditionalPrizesInfoSubscriptions(state.subscriptions).replacingOccurrences(of: "\(state.subscriptions) ", with: "")
|
||||
prizeDescriptionInfoText = presentationData.strings.BoostGift_AdditionalPrizesInfoOn("\(state.subscriptions)", subscriptionsString, monthsString).string
|
||||
} else {
|
||||
let subscriptionsString = presentationData.strings.BoostGift_AdditionalPrizesInfoWithSubscriptions(state.subscriptions).replacingOccurrences(of: "\(state.subscriptions) ", with: "")
|
||||
let description = "\(state.prizeDescription) \(subscriptionsString)"
|
||||
prizeDescriptionInfoText = presentationData.strings.BoostGift_AdditionalPrizesInfoOn("\(state.subscriptions)", description, monthsString).string
|
||||
}
|
||||
}
|
||||
entries.append(.prizeDescriptionInfo(presentationData.theme, prizeDescriptionInfoText))
|
||||
|
||||
entries.append(.timeHeader(presentationData.theme, presentationData.strings.BoostGift_DateTitle.uppercased()))
|
||||
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))
|
||||
|
||||
entries.append(.winners(presentationData.theme, presentationData.strings.BoostGift_Winners, state.showWinners))
|
||||
entries.append(.winnersInfo(presentationData.theme, presentationData.strings.BoostGift_WinnersInfo))
|
||||
case .gift:
|
||||
appendDurationEntries()
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
@@ -779,6 +802,7 @@ private struct CreateGiveawayControllerState: Equatable {
|
||||
var countries: [String] = []
|
||||
var onlyNewEligible: Bool = false
|
||||
var showWinners: Bool = false
|
||||
var showPrizeDescription: Bool = false
|
||||
var prizeDescription: String = ""
|
||||
var time: Int32
|
||||
var pickingExpiryTime = false
|
||||
@@ -834,6 +858,7 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
var openPremiumIntroImpl: (() -> Void)?
|
||||
var presentControllerImpl: ((ViewController) -> Void)?
|
||||
var pushControllerImpl: ((ViewController) -> Void)?
|
||||
var scrollToDescriptionImpl: (() -> Void)?
|
||||
var scrollToDateImpl: (() -> Void)?
|
||||
var dismissImpl: (() -> Void)?
|
||||
var dismissInputImpl: (() -> Void)?
|
||||
@@ -852,6 +877,8 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
openPremiumIntroImpl?()
|
||||
}, scrollToDate: {
|
||||
scrollToDateImpl?()
|
||||
}, scrollToDescription: {
|
||||
scrollToDescriptionImpl?()
|
||||
}, setItemIdWithRevealedOptions: { itemId, fromItemId in
|
||||
updateState { state in
|
||||
var updatedState = state
|
||||
@@ -960,6 +987,9 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
if previousState.channels.count > state.channels.count {
|
||||
animateChanges = true
|
||||
}
|
||||
if previousState.showPrizeDescription != state.showPrizeDescription {
|
||||
animateChanges = true
|
||||
}
|
||||
}
|
||||
|
||||
var peers: [EnginePeer.Id: EnginePeer] = [:]
|
||||
@@ -981,7 +1011,7 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
let controller = ItemListController(context: context, state: signal)
|
||||
controller.navigationPresentation = .modal
|
||||
controller.beganInteractiveDragging = {
|
||||
dismissInputImpl?()
|
||||
// dismissInputImpl?()
|
||||
}
|
||||
presentControllerImpl = { [weak controller] c in
|
||||
controller?.present(c, in: .window(.root))
|
||||
@@ -1260,6 +1290,28 @@ public func createGiveawayController(context: AccountContext, updatedPresentatio
|
||||
pushControllerImpl?(controller)
|
||||
}
|
||||
|
||||
scrollToDescriptionImpl = { [weak controller] in
|
||||
controller?.afterLayout({
|
||||
guard let controller = controller else {
|
||||
return
|
||||
}
|
||||
|
||||
var resultItemNode: ListViewItemNode?
|
||||
let _ = controller.frameForItemNode({ listItemNode in
|
||||
if let itemNode = listItemNode as? ItemListItemNode {
|
||||
if let tag = itemNode.tag as? CreateGiveawayEntryTag, tag == .description {
|
||||
resultItemNode = listItemNode
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
if let resultItemNode = resultItemNode {
|
||||
controller.ensureItemNodeVisible(resultItemNode)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
scrollToDateImpl = { [weak controller] in
|
||||
controller?.afterLayout({
|
||||
guard let controller = controller else {
|
||||
|
||||
Reference in New Issue
Block a user