Theme fixes

This commit is contained in:
Ilya Laktyushin 2019-12-26 12:32:03 +03:00
parent e7ae760fda
commit c6e520e5c1
13 changed files with 161 additions and 69 deletions

View File

@ -282,6 +282,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
initialState = EditThemeControllerState(mode: mode, title: generateThemeName(accentColor: theme.rootController.navigationBar.buttonColor), slug: "", updatedTheme: nil, updating: false)
previewThemePromise.set(.single(theme.withUpdated(name: "", defaultWallpaper: wallpaper)))
case let .edit(info):
settingsPromise.set(.single(info.theme.settings))
if let file = info.theme.file, let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(file.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let theme = makePresentationTheme(data: data, resolvedWallpaper: info.resolvedWallpaper) {
if case let .file(file) = theme.chat.defaultWallpaper, file.id == 0 {
previewThemePromise.set(cachedWallpaper(account: context.account, slug: file.slug, settings: file.settings)
@ -295,7 +296,6 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
} else {
previewThemePromise.set(.single(theme.withUpdated(name: nil, defaultWallpaper: info.resolvedWallpaper)))
}
settingsPromise.set(.single(info.theme.settings))
} else {
previewThemePromise.set(.single(presentationData.theme.withUpdated(name: "", defaultWallpaper: presentationData.chatWallpaper)))
@ -320,7 +320,7 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
let _ = (combineLatest(queue: Queue.mainQueue(), previewThemePromise.get(), settingsPromise.get())
|> take(1)).start(next: { theme, previousSettings in
var controllerDismissImpl: (() -> Void)?
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: nil, defaultThemeReference: nil, create: false, completion: { updatedTheme, settings in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: nil, generalThemeReference: nil, defaultThemeReference: nil, create: false, completion: { updatedTheme, settings in
updateState { current in
var state = current
previewThemePromise.set(.single(updatedTheme))

View File

@ -17,13 +17,13 @@ private let randomBackgroundColors: [Int32] = [0x007aff, 0x00c2ed, 0x29b327, 0xe
enum ThemeAccentColorControllerMode {
case colors(themeReference: PresentationThemeReference, create: Bool)
case background(themeReference: PresentationThemeReference)
case edit(theme: PresentationTheme, wallpaper: TelegramWallpaper?, defaultThemeReference: PresentationThemeReference?, create: Bool, completion: (PresentationTheme, TelegramThemeSettings?) -> Void)
case edit(theme: PresentationTheme, wallpaper: TelegramWallpaper?, generalThemeReference: PresentationThemeReference?, defaultThemeReference: PresentationThemeReference?, create: Bool, completion: (PresentationTheme, TelegramThemeSettings?) -> Void)
var themeReference: PresentationThemeReference? {
switch self {
case let .colors(themeReference, _), let .background(themeReference):
return themeReference
case let .edit(_, _, defaultThemeReference, _, _):
case let .edit(_, _, _, defaultThemeReference, _, _):
return defaultThemeReference
default:
return nil
@ -119,7 +119,7 @@ final class ThemeAccentColorController: ViewController {
let theme: PresentationTheme
let wallpaper: TelegramWallpaper
if case let .edit(editedTheme, walpaper, _, _, _) = self.mode {
if case let .edit(editedTheme, walpaper, _, _, _, _) = self.mode {
theme = editedTheme
wallpaper = walpaper ?? editedTheme.chat.defaultWallpaper
} else {
@ -178,28 +178,38 @@ final class ThemeAccentColorController: ViewController {
prepare = .complete()
}
if case let .edit(theme, _, themeReference, _, completion) = strongSelf.mode {
if case let .edit(theme, _, generalThemeReference, themeReference, _, completion) = strongSelf.mode {
let _ = (prepare
|> deliverOnMainQueue).start(completed: { [weak self] in
let updatedTheme: PresentationTheme
var settings: TelegramThemeSettings?
var hasSettings = false
var baseTheme: TelegramBaseTheme?
if case let .cloud(theme) = generalThemeReference, let settings = theme.theme.settings {
hasSettings = true
baseTheme = settings.baseTheme
} else if case let .builtin(theme) = generalThemeReference {
hasSettings = true
baseTheme = theme.baseTheme
}
if let themeReference = themeReference {
updatedTheme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: state.accentColor, backgroundColors: state.backgroundColors, bubbleColors: state.messagesColors, wallpaper: state.initialWallpaper ?? coloredWallpaper, serviceBackgroundColor: serviceBackgroundColor) ?? defaultPresentationTheme
if case let .builtin(theme) = themeReference {
var messageColors: (Int32, Int32)?
if let colors = state.messagesColors {
messageColors = (Int32(bitPattern: colors.0.rgb), Int32(bitPattern: colors.1?.rgb ?? colors.0.rgb))
}
settings = TelegramThemeSettings(baseTheme: theme.baseTheme, accentColor: Int32(bitPattern: state.accentColor.rgb), messageColors: messageColors, wallpaper: coloredWallpaper)
}
} else {
updatedTheme = customizePresentationTheme(theme, editing: false, accentColor: state.accentColor, backgroundColors: state.backgroundColors, bubbleColors: state.messagesColors, wallpaper: state.initialWallpaper ?? coloredWallpaper)
}
if hasSettings, let baseTheme = baseTheme {
var messageColors: (Int32, Int32)?
if let colors = state.messagesColors {
messageColors = (Int32(bitPattern: colors.0.rgb), Int32(bitPattern: colors.1?.rgb ?? colors.0.rgb))
}
settings = TelegramThemeSettings(baseTheme: baseTheme, accentColor: Int32(bitPattern: state.accentColor.rgb), messageColors: messageColors, wallpaper: coloredWallpaper)
}
completion(updatedTheme, settings)
})
} else if case let .colors(theme, create) = strongSelf.mode {
@ -208,6 +218,8 @@ final class ThemeAccentColorController: ViewController {
if case let .cloud(theme) = theme, let settings = theme.theme.settings {
telegramTheme = theme.theme
baseTheme = settings.baseTheme
} else if case let .builtin(theme) = theme {
baseTheme = theme.baseTheme
} else {
baseTheme = .classic
}
@ -365,9 +377,9 @@ final class ThemeAccentColorController: ViewController {
} else if let customWallpaper = settings.themeSpecificChatWallpapers[themeReference.index] {
wallpaper = customWallpaper
} else {
let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: nil) ?? defaultPresentationTheme
let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: nil, wallpaper: themeSpecificAccentColor?.wallpaper) ?? defaultPresentationTheme
if case let .builtin(themeName) = themeReference {
if case .dayClassic = themeName, settings.themeSpecificAccentColors[themeReference.index] != nil {
if case .dayClassic = themeName, settings.themeSpecificAccentColors[coloredThemeIndex(reference: themeReference, accentColor: themeSpecificAccentColor)] != nil {
ignoreDefaultWallpaper = true
} else if case .nightAccent = themeName {
ignoreDefaultWallpaper = true
@ -466,7 +478,7 @@ final class ThemeAccentColorController: ViewController {
}
}
}
} else if case let .edit(theme, wallpaper, _, _, _) = strongSelf.mode {
} else if case let .edit(theme, wallpaper, _, _, _, _) = strongSelf.mode {
accentColor = theme.rootController.navigationBar.accentTextColor
let wallpaper = wallpaper ?? theme.chat.defaultWallpaper

View File

@ -258,7 +258,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
self.patternPanelNode = WallpaperPatternPanelNode(context: self.context, theme: self.theme, strings: self.presentationData.strings)
let doneButtonType: WallpaperGalleryToolbarDoneButtonType
if case .edit(_, _, _, true, _) = self.mode {
if case .edit(_, _, _, _, true, _) = self.mode {
doneButtonType = .proceed
} else {
doneButtonType = .set
@ -469,7 +469,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
if !updateOnlyWallpaper {
if let themeReference = mode.themeReference {
updatedTheme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeReference, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: messagesColors, serviceBackgroundColor: serviceBackgroundColor, preview: true) ?? defaultPresentationTheme
} else if case let .edit(theme, _, _, _, _) = mode {
} else if case let .edit(theme, _, _, _, _, _) = mode {
updatedTheme = customizePresentationTheme(theme, editing: false, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: messagesColors)
} else {
updatedTheme = theme
@ -700,7 +700,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
doneButtonType = .apply
cancelButtonType = .discard
} else {
if case .edit(_, _, _, true, _) = self.mode {
if case .edit(_, _, _, _, true, _) = self.mode {
doneButtonType = .proceed
} else {
doneButtonType = .set

View File

@ -143,6 +143,15 @@ enum ThemeSettingsColorOption: Equatable {
}
}
var wallpaper: TelegramWallpaper? {
switch self {
case let .accentColor(color):
return color.wallpaper
case .theme:
return nil
}
}
var index: Int64 {
switch self {
case let .accentColor(color):
@ -918,7 +927,7 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode {
}
let contextAction: ((ThemeSettingsColorOption?, Bool, ASDisplayNode, ContextGesture?) -> Void)? = { [weak item] color, selected, node, gesture in
if let strongSelf = self, let item = strongSelf.item {
item.contextAction?(selected, item.themeReference, color, node, gesture)
item.contextAction?(selected, item.generalThemeReference, color, node, gesture)
}
}
let openColorPicker: (Bool) -> Void = { [weak self] create in

View File

@ -598,7 +598,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
if let wallpaper = wallpaper {
effectiveWallpaper = wallpaper
} else {
let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: reference, accentColor: accentColor?.color, bubbleColors: accentColor?.customBubbleColors)
let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: reference, accentColor: accentColor?.color, bubbleColors: accentColor?.customBubbleColors, wallpaper: accentColor?.wallpaper)
effectiveWallpaper = theme?.chat.defaultWallpaper ?? .builtin(WallpaperSettings())
}
return (accentColor, effectiveWallpaper)
@ -663,7 +663,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
let _ = (resolvedWallpaper
|> deliverOnMainQueue).start(next: { wallpaper in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: wallpaper, defaultThemeReference: nil, create: true, completion: { result, settings in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: wallpaper, generalThemeReference: reference.generalThemeReference, defaultThemeReference: nil, create: true, completion: { result, settings in
let controller = editThemeController(context: context, mode: .create(result, nil), navigateToChat: { peerId in
if let navigationController = getNavigationControllerImpl?() {
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId)))
@ -704,14 +704,19 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
|> take(1)
|> deliverOnMainQueue).start(next: { themes in
if isCurrent, let currentThemeIndex = themes.firstIndex(where: { $0.id == theme.theme.id }) {
let previousThemeIndex = themes.prefix(upTo: currentThemeIndex).reversed().firstIndex(where: { $0.file != nil })
let newTheme: PresentationThemeReference
if let previousThemeIndex = previousThemeIndex {
newTheme = .cloud(PresentationCloudTheme(theme: themes[themes.index(before: previousThemeIndex.base)], resolvedWallpaper: nil))
if let settings = theme.theme.settings {
selectAccentColorImpl?(nil)
} else {
newTheme = .builtin(.nightAccent)
let previousThemeIndex = themes.prefix(upTo: currentThemeIndex).reversed().firstIndex(where: { $0.file != nil })
let newTheme: PresentationThemeReference
if let previousThemeIndex = previousThemeIndex {
newTheme = .cloud(PresentationCloudTheme(theme: themes[themes.index(before: previousThemeIndex.base)], resolvedWallpaper: nil))
} else {
newTheme = .builtin(.nightAccent)
}
selectThemeImpl?(newTheme)
}
selectThemeImpl?(newTheme)
}
let _ = deleteThemeInteractively(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme.theme).start()
@ -758,7 +763,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
}
}
return (accentColor, wallpaper)
} |> mapToSignal { accentColor, wallpaper -> Signal<(PresentationTheme?, TelegramWallpaper?), NoError> in
} |> mapToSignal { accentColor, wallpaper -> Signal<(PresentationTheme?, PresentationThemeReference, TelegramWallpaper?), NoError> in
let generalThemeReference: PresentationThemeReference
if let accentColor = accentColor, case let .cloud(theme) = reference, let settings = theme.theme.settings {
generalThemeReference = .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme))
@ -767,6 +772,13 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
}
let effectiveWallpaper: TelegramWallpaper
let effectiveThemeReference: PresentationThemeReference
if let accentColor = accentColor, case let .theme(themeReference) = accentColor {
effectiveThemeReference = themeReference
} else {
effectiveThemeReference = reference
}
if let wallpaper = wallpaper {
effectiveWallpaper = wallpaper
} else {
@ -774,7 +786,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
if let accentColor = accentColor, case let .theme(themeReference) = accentColor {
theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeReference)
} else {
theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.accentColor, bubbleColors: accentColor?.customBubbleColors)
theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.accentColor, bubbleColors: accentColor?.customBubbleColors, wallpaper: accentColor?.wallpaper)
}
effectiveWallpaper = theme?.chat.defaultWallpaper ?? .builtin(WallpaperSettings())
}
@ -792,23 +804,26 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
return wallpaperSignal
|> mapToSignal { wallpaper in
return chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: context.sharedContext.accountManager.mediaBox)
|> map { serviceBackgroundColor in
return (wallpaper, serviceBackgroundColor)
}
}
|> map { serviceBackgroundColor in
|> map { wallpaper, serviceBackgroundColor in
if let accentColor = accentColor, case let .theme(themeReference) = accentColor {
return (makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeReference, serviceBackgroundColor: serviceBackgroundColor), wallpaper)
return (makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeReference, serviceBackgroundColor: serviceBackgroundColor), effectiveThemeReference, wallpaper)
} else {
return (makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.accentColor, bubbleColors: accentColor?.customBubbleColors, serviceBackgroundColor: serviceBackgroundColor), wallpaper)
return (makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.accentColor, bubbleColors: accentColor?.customBubbleColors, serviceBackgroundColor: serviceBackgroundColor), effectiveThemeReference, wallpaper)
}
}
}
|> deliverOnMainQueue).start(next: { theme, wallpaper in
|> deliverOnMainQueue).start(next: { theme, effectiveThemeReference, wallpaper in
guard let theme = theme else {
return
}
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let strings = presentationData.strings
let themeController = ThemePreviewController(context: context, previewTheme: theme, source: .settings(reference, wallpaper))
let themeController = ThemePreviewController(context: context, previewTheme: theme, source: .settings(effectiveThemeReference, wallpaper))
var items: [ContextMenuItem] = []
if let accentColor = accentColor {
@ -844,7 +859,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
let _ = (resolvedWallpaper
|> deliverOnMainQueue).start(next: { wallpaper in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: wallpaper, defaultThemeReference: nil, create: true, completion: { result, settings in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: theme, wallpaper: wallpaper, generalThemeReference: reference.generalThemeReference, defaultThemeReference: nil, create: true, completion: { result, settings in
let controller = editThemeController(context: context, mode: .create(result, nil), navigateToChat: { peerId in
if let navigationController = getNavigationControllerImpl?() {
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId)))
@ -1215,10 +1230,10 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
items.append(ActionSheetButtonItem(title: presentationData.strings.Appearance_CreateTheme, color: .accent, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
let _ = (context.sharedContext.accountManager.transaction { transaction -> PresentationThemeReference? in
let _ = (context.sharedContext.accountManager.transaction { transaction -> PresentationThemeReference in
let settings = transaction.getSharedData(ApplicationSpecificSharedDataKeys.presentationThemeSettings) as? PresentationThemeSettings ?? PresentationThemeSettings.defaultSettings
var themeReference: PresentationThemeReference?
let themeReference: PresentationThemeReference
let autoNightModeTriggered = context.sharedContext.currentPresentationData.with { $0 }.autoNightModeTriggered
if autoNightModeTriggered {
themeReference = settings.automaticThemeSwitchSetting.theme
@ -1226,14 +1241,15 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The
themeReference = settings.theme
}
if let themeReference = themeReference, case .builtin = themeReference {
} else {
themeReference = nil
}
return themeReference
}
|> deliverOnMainQueue).start(next: { themeReference in
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: presentationData.theme, wallpaper: presentationData.chatWallpaper, defaultThemeReference: themeReference, create: true, completion: { result, settings in
let defaultThemeReference: PresentationThemeReference?
if case .builtin = themeReference {
defaultThemeReference = themeReference
}
let controller = ThemeAccentColorController(context: context, mode: .edit(theme: presentationData.theme, wallpaper: presentationData.chatWallpaper, generalThemeReference: themeReference.generalThemeReference, defaultThemeReference: themeReference, create: true, completion: { result, settings in
let controller = editThemeController(context: context, mode: .create(result, settings), navigateToChat: { peerId in
if let navigationController = getNavigationControllerImpl?() {
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peerId)))

View File

@ -305,7 +305,9 @@ private final class ThemeSettingsThemeItemIconNode : ListViewItemNode {
}
func prepareCrossfadeTransition() {
self.snapshotView?.removeFromSuperview()
guard self.snapshotView == nil else {
return
}
if let snapshotView = self.containerNode.view.snapshotView(afterScreenUpdates: false) {
self.view.insertSubview(snapshotView, aboveSubview: self.containerNode.view)
@ -314,8 +316,13 @@ private final class ThemeSettingsThemeItemIconNode : ListViewItemNode {
}
func animateCrossfadeTransition() {
guard self.snapshotView?.layer.animationKeys()?.isEmpty ?? true else {
return
}
self.snapshotView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { [weak self] _ in
self?.snapshotView?.removeFromSuperview()
self?.snapshotView = nil
})
}
@ -603,7 +610,7 @@ class ThemeSettingsThemeItemNode: ListViewItemNode, ItemListItemNode {
var entries: [ThemeSettingsThemeEntry] = []
var index: Int = 0
for var theme in item.themes {
for var theme in item.themes.prefix(1) {
if !item.displayUnsupported, case let .cloud(theme) = theme, theme.theme.file == nil {
continue
}
@ -647,7 +654,9 @@ class ThemeSettingsThemeItemNode: ListViewItemNode, ItemListItemNode {
}
func prepareCrossfadeTransition() {
self.snapshotView?.removeFromSuperview()
guard self.snapshotView == nil else {
return
}
if let snapshotView = self.containerNode.view.snapshotView(afterScreenUpdates: false) {
self.view.insertSubview(snapshotView, aboveSubview: self.containerNode.view)
@ -662,8 +671,13 @@ class ThemeSettingsThemeItemNode: ListViewItemNode, ItemListItemNode {
}
func animateCrossfadeTransition() {
guard self.snapshotView?.layer.animationKeys()?.isEmpty ?? true else {
return
}
self.snapshotView?.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false, completion: { [weak self] _ in
self?.snapshotView?.removeFromSuperview()
self?.snapshotView = nil
})
self.listNode.forEachVisibleItemNode { node in

View File

@ -143,7 +143,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode {
selectedFileId = file.id
}
for wallpaper in wallpapers {
for wallpaper in self.wallpapers {
let node = SettingsThemeWallpaperNode(overlayBackgroundColor: self.serviceBackgroundColor.withAlphaComponent(0.4))
node.clipsToBounds = true
node.cornerRadius = 5.0
@ -251,7 +251,16 @@ final class WallpaperPatternPanelNode: ASDisplayNode {
let frame = node.frame.insetBy(dx: -48.0, dy: 0.0)
if frame.minX < bounds.minX || frame.maxX > bounds.maxX {
self.scrollNode.view.scrollRectToVisible(frame, animated: animated)
let transition: ContainedViewLayoutTransition = animated ? .animated(duration: 0.3, curve: .easeInOut) : .immediate
var origin = CGPoint()
if frame.minX < bounds.minX {
origin.x = max(0.0, frame.minX)
} else if frame.maxX > bounds.maxX {
origin.x = min(self.scrollNode.view.contentSize.width - bounds.width, frame.maxX - bounds.width)
}
transition.updateBounds(node: self.scrollNode, bounds: CGRect(origin: origin, size: self.scrollNode.frame.size))
}
}

View File

@ -221,7 +221,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit
)
}
public func makeDefaultDarkPresentationTheme(customIndex: Int64? = nil, preview: Bool) -> PresentationTheme {
public func makeDefaultDarkPresentationTheme(extendingThemeReference: PresentationThemeReference? = nil, preview: Bool) -> PresentationTheme {
let rootTabBar = PresentationThemeRootTabBar(
backgroundColor: UIColor(rgb: 0x1c1c1d),
separatorColor: UIColor(rgb: 0x3d3d40),
@ -531,8 +531,8 @@ public func makeDefaultDarkPresentationTheme(customIndex: Int64? = nil, preview:
)
return PresentationTheme(
name: .builtin(.night),
index: customIndex ?? PresentationThemeReference.builtin(.night).index,
name: extendingThemeReference?.name ?? .builtin(.night),
index: extendingThemeReference?.index ?? PresentationThemeReference.builtin(.night).index,
referenceTheme: .night,
overallDarkAppearance: true,
intro: intro,

View File

@ -441,7 +441,7 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme
)
}
public func makeDefaultDarkTintedPresentationTheme(customIndex: Int64? = nil, preview: Bool) -> PresentationTheme {
public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: PresentationThemeReference? = nil, preview: Bool) -> PresentationTheme {
let accentColor = defaultDarkTintedAccentColor
let secondaryBadgeTextColor: UIColor
@ -787,8 +787,8 @@ public func makeDefaultDarkTintedPresentationTheme(customIndex: Int64? = nil, pr
)
return PresentationTheme(
name: .builtin(.nightAccent),
index: customIndex ?? PresentationThemeReference.builtin(.nightAccent).index,
name: extendingThemeReference?.name ?? .builtin(.nightAccent),
index: extendingThemeReference?.index ?? PresentationThemeReference.builtin(.nightAccent).index,
referenceTheme: .nightAccent,
overallDarkAppearance: true,
intro: intro,

View File

@ -311,7 +311,7 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ac
)
}
public func makeDefaultDayPresentationTheme(customIndex: Int64? = nil, serviceBackgroundColor: UIColor?, day: Bool, preview: Bool) -> PresentationTheme {
public func makeDefaultDayPresentationTheme(extendingThemeReference: PresentationThemeReference? = nil, serviceBackgroundColor: UIColor?, day: Bool, preview: Bool) -> PresentationTheme {
var serviceBackgroundColor = serviceBackgroundColor ?? defaultServiceBackgroundColor
let intro = PresentationThemeIntro(
@ -740,8 +740,8 @@ public func makeDefaultDayPresentationTheme(customIndex: Int64? = nil, serviceBa
)
return PresentationTheme(
name: .builtin(day ? .day : .dayClassic),
index: customIndex ?? PresentationThemeReference.builtin(day ? .day : .dayClassic).index,
name: extendingThemeReference?.name ?? .builtin(day ? .day : .dayClassic),
index: extendingThemeReference?.index ?? PresentationThemeReference.builtin(day ? .day : .dayClassic).index,
referenceTheme: day ? .day : .dayClassic,
overallDarkAppearance: false,
intro: intro,

View File

@ -4,23 +4,23 @@ import Postbox
import SyncCore
import TelegramUIPreferences
public func makeDefaultPresentationTheme(reference: PresentationBuiltinThemeReference, customIndex: Int64? = nil, serviceBackgroundColor: UIColor?, preview: Bool = false) -> PresentationTheme {
public func makeDefaultPresentationTheme(reference: PresentationBuiltinThemeReference, extendingThemeReference: PresentationThemeReference? = nil, serviceBackgroundColor: UIColor?, preview: Bool = false) -> PresentationTheme {
let theme: PresentationTheme
switch reference {
case .dayClassic:
theme = makeDefaultDayPresentationTheme(customIndex: customIndex, serviceBackgroundColor: serviceBackgroundColor, day: false, preview: preview)
theme = makeDefaultDayPresentationTheme(extendingThemeReference: extendingThemeReference, serviceBackgroundColor: serviceBackgroundColor, day: false, preview: preview)
case .day:
theme = makeDefaultDayPresentationTheme(customIndex: customIndex, serviceBackgroundColor: serviceBackgroundColor, day: true, preview: preview)
theme = makeDefaultDayPresentationTheme(extendingThemeReference: extendingThemeReference, serviceBackgroundColor: serviceBackgroundColor, day: true, preview: preview)
case .night:
theme = makeDefaultDarkPresentationTheme(customIndex: customIndex, preview: preview)
theme = makeDefaultDarkPresentationTheme(extendingThemeReference: extendingThemeReference, preview: preview)
case .nightAccent:
theme = makeDefaultDarkTintedPresentationTheme(customIndex: customIndex, preview: preview)
theme = makeDefaultDarkTintedPresentationTheme(extendingThemeReference: extendingThemeReference, preview: preview)
}
return theme
}
public func customizePresentationTheme(_ theme: PresentationTheme, editing: Bool, accentColor: UIColor?, backgroundColors: (UIColor, UIColor?)?, bubbleColors: (UIColor, UIColor?)?, wallpaper: TelegramWallpaper? = nil) -> PresentationTheme {
if accentColor == nil && bubbleColors == nil && backgroundColors == nil {
if accentColor == nil && bubbleColors == nil && backgroundColors == nil && wallpaper == nil {
return theme
}
switch theme.referenceTheme {
@ -35,11 +35,11 @@ public func customizePresentationTheme(_ theme: PresentationTheme, editing: Bool
return theme
}
public func makePresentationTheme(mediaBox: MediaBox, themeReference: PresentationThemeReference, customIndex: Int64? = nil, accentColor: UIColor? = nil, backgroundColors: (UIColor, UIColor?)? = nil, bubbleColors: (UIColor, UIColor?)? = nil, wallpaper: TelegramWallpaper? = nil, serviceBackgroundColor: UIColor? = nil, preview: Bool = false) -> PresentationTheme? {
public func makePresentationTheme(mediaBox: MediaBox, themeReference: PresentationThemeReference, extendingThemeReference: PresentationThemeReference? = nil, accentColor: UIColor? = nil, backgroundColors: (UIColor, UIColor?)? = nil, bubbleColors: (UIColor, UIColor?)? = nil, wallpaper: TelegramWallpaper? = nil, serviceBackgroundColor: UIColor? = nil, preview: Bool = false) -> PresentationTheme? {
let theme: PresentationTheme
switch themeReference {
case let .builtin(reference):
let defaultTheme = makeDefaultPresentationTheme(reference: reference, customIndex: customIndex, serviceBackgroundColor: serviceBackgroundColor, preview: preview)
let defaultTheme = makeDefaultPresentationTheme(reference: reference, extendingThemeReference: extendingThemeReference, serviceBackgroundColor: serviceBackgroundColor, preview: preview)
theme = customizePresentationTheme(defaultTheme, editing: true, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: bubbleColors, wallpaper: wallpaper)
case let .local(info):
if let path = mediaBox.completedResourcePath(info.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead), let loadedTheme = makePresentationTheme(data: data, themeReference: themeReference, resolvedWallpaper: info.resolvedWallpaper) {
@ -49,7 +49,7 @@ public func makePresentationTheme(mediaBox: MediaBox, themeReference: Presentati
}
case let .cloud(info):
if let settings = info.theme.settings {
if let loadedTheme = makePresentationTheme(mediaBox: mediaBox, themeReference: .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme)), customIndex: themeReference.index, accentColor: accentColor ?? UIColor(rgb: UInt32(bitPattern: settings.accentColor)), backgroundColors: nil, bubbleColors: bubbleColors ?? settings.messageColors.flatMap { (UIColor(rgb: UInt32(bitPattern: $0.top)), UIColor(rgb: UInt32(bitPattern: $0.bottom))) }, wallpaper: wallpaper ?? settings.wallpaper, serviceBackgroundColor: serviceBackgroundColor, preview: preview) {
if let loadedTheme = makePresentationTheme(mediaBox: mediaBox, themeReference: .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme)), extendingThemeReference: themeReference, accentColor: accentColor ?? UIColor(rgb: UInt32(bitPattern: settings.accentColor)), backgroundColors: nil, bubbleColors: bubbleColors ?? settings.messageColors.flatMap { (UIColor(rgb: UInt32(bitPattern: $0.top)), UIColor(rgb: UInt32(bitPattern: $0.bottom))) }, wallpaper: wallpaper ?? settings.wallpaper, serviceBackgroundColor: serviceBackgroundColor, preview: preview) {
theme = loadedTheme
} else {
return nil

View File

@ -1105,6 +1105,28 @@ public enum PresentationThemeName: Equatable {
}
}
public extension PresentationThemeReference {
public var name: PresentationThemeName {
switch self {
case let .builtin(theme):
switch theme {
case .day:
return .builtin(.day)
case .dayClassic:
return .builtin(.dayClassic)
case .night:
return .builtin(.night)
case .nightAccent:
return .builtin(.nightAccent)
}
case let .cloud(info):
return .custom(info.theme.title)
default:
return .custom("")
}
}
}
public final class PresentationTheme: Equatable {
public let name: PresentationThemeName
public let index: Int64

View File

@ -220,6 +220,16 @@ public enum PresentationThemeReference: PostboxCoding, Equatable {
return (Int64(namespace) << 32) | Int64(bitPattern: UInt64(UInt32(bitPattern: id)))
}
public var generalThemeReference: PresentationThemeReference {
let generalThemeReference: PresentationThemeReference
if case let .cloud(theme) = self, let settings = theme.theme.settings {
generalThemeReference = .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme))
} else {
generalThemeReference = self
}
return generalThemeReference
}
}
public func coloredThemeIndex(reference: PresentationThemeReference, accentColor: PresentationThemeAccentColor?) -> Int64 {