mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-05 20:52:48 +00:00
Merge commit '4fe0d477157bf975f9478d7334d628ad9d9930a8'
This commit is contained in:
@@ -14,6 +14,7 @@ import PresentationDataUtils
|
||||
import LegacyMediaPickerUI
|
||||
import WallpaperResources
|
||||
import AccountContext
|
||||
import MediaResources
|
||||
|
||||
private final class EditThemeControllerArguments {
|
||||
let context: AccountContext
|
||||
@@ -503,11 +504,40 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
||||
resolvedWallpaper = nil
|
||||
}
|
||||
|
||||
|
||||
let prepare: Signal<CreateThemeResult, CreateThemeError>
|
||||
if let resolvedWallpaper = resolvedWallpaper, case let .file(file) = resolvedWallpaper, resolvedWallpaper.isPattern {
|
||||
let resource = file.file.resource
|
||||
let representation = CachedPatternWallpaperRepresentation(color: file.settings.color ?? 0xd6e2ee, bottomColor: file.settings.bottomColor, intensity: file.settings.intensity ?? 50, rotation: file.settings.rotation)
|
||||
|
||||
var data: Data?
|
||||
if let path = context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||
data = maybeData
|
||||
} else if let path = context.sharedContext.accountManager.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
|
||||
data = maybeData
|
||||
}
|
||||
|
||||
if let data = data {
|
||||
context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true)
|
||||
prepare = (context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true)
|
||||
|> filter({ $0.complete })
|
||||
|> take(1)
|
||||
|> castError(CreateThemeError.self)
|
||||
|> mapToSignal { _ -> Signal<CreateThemeResult, CreateThemeError> in
|
||||
return .complete()
|
||||
})
|
||||
} else {
|
||||
prepare = .complete()
|
||||
}
|
||||
} else {
|
||||
prepare = .complete()
|
||||
}
|
||||
|
||||
switch mode {
|
||||
case .create:
|
||||
if let themeResource = themeResource {
|
||||
let _ = (createTheme(account: context.account, title: state.title, resource: themeResource, thumbnailData: themeThumbnailData, settings: settings)
|
||||
|> deliverOnMainQueue).start(next: { next in
|
||||
let _ = (prepare |> then(createTheme(account: context.account, title: state.title, resource: themeResource, thumbnailData: themeThumbnailData, settings: settings)
|
||||
|> deliverOnMainQueue)).start(next: { next in
|
||||
if case let .result(resultTheme) = next {
|
||||
let _ = applyTheme(accountManager: context.sharedContext.accountManager, account: context.account, theme: resultTheme).start()
|
||||
let _ = (updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in
|
||||
@@ -540,8 +570,8 @@ public func editThemeController(context: AccountContext, mode: EditThemeControll
|
||||
})
|
||||
}
|
||||
case let .edit(info):
|
||||
let _ = (updateTheme(account: context.account, accountManager: context.sharedContext.accountManager, theme: info.theme, title: state.title, slug: state.slug, resource: themeResource, settings: settings)
|
||||
|> deliverOnMainQueue).start(next: { next in
|
||||
let _ = (prepare |> then(updateTheme(account: context.account, accountManager: context.sharedContext.accountManager, theme: info.theme, title: state.title, slug: state.slug, resource: themeResource, settings: settings)
|
||||
|> deliverOnMainQueue)).start(next: { next in
|
||||
if case let .result(resultTheme) = next {
|
||||
let _ = applyTheme(accountManager: context.sharedContext.accountManager, account: context.account, theme: resultTheme).start()
|
||||
let _ = (updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in
|
||||
|
||||
@@ -41,6 +41,8 @@ public final class ThemePreviewController: ViewController {
|
||||
return self._ready
|
||||
}
|
||||
|
||||
private var validLayout: ContainerViewLayout?
|
||||
|
||||
private var didPlayPresentationAnimation = false
|
||||
|
||||
private var presentationData: PresentationData
|
||||
@@ -399,11 +401,11 @@ public final class ThemePreviewController: ViewController {
|
||||
}
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { [weak self] previousDefaultTheme in
|
||||
if let strongSelf = self {
|
||||
if let strongSelf = self, let layout = strongSelf.validLayout, layout.size.width >= 375.0 {
|
||||
Queue.mainQueue().after(0.3) {
|
||||
let navigationController = strongSelf.navigationController as? NavigationController
|
||||
if let (previousDefaultTheme, autoNightMode) = previousDefaultTheme {
|
||||
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .actionSucceeded(title: strongSelf.presentationData.strings.Theme_ThemeChanged, text: strongSelf.presentationData.strings.Theme_ThemeChangedText, cancel: strongSelf.presentationData.strings.Undo_Undo), elevatedLayout: false, animateInAsReplacement: false, action: { value in
|
||||
strongSelf.present(UndoOverlayController(presentationData: strongSelf.presentationData, content: .actionSucceeded(title: strongSelf.presentationData.strings.Theme_ThemeChanged, text: strongSelf.presentationData.strings.Theme_ThemeChangedText, cancel: strongSelf.presentationData.strings.Undo_Undo), elevatedLayout: true, animateInAsReplacement: false, action: { value in
|
||||
if value == .undo {
|
||||
let _ = updatePresentationThemeSettingsInteractively(accountManager: context.sharedContext.accountManager, { current -> PresentationThemeSettings in
|
||||
var updated: PresentationThemeSettings
|
||||
@@ -435,6 +437,8 @@ public final class ThemePreviewController: ViewController {
|
||||
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
self.validLayout = layout
|
||||
|
||||
self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationHeight, transition: transition)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ private struct ThemeSettingsThemeEntry: Comparable, Identifiable {
|
||||
let wallpaper: TelegramWallpaper?
|
||||
|
||||
var stableId: Int64 {
|
||||
return self.themeReference.index
|
||||
return self.themeReference.generalThemeReference.index
|
||||
}
|
||||
|
||||
static func ==(lhs: ThemeSettingsThemeEntry, rhs: ThemeSettingsThemeEntry) -> Bool {
|
||||
|
||||
@@ -31,8 +31,10 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
private let cancelButton = HighlightableButtonNode()
|
||||
private let doneButton = HighlightableButtonNode()
|
||||
private let cancelButton = HighlightTrackingButtonNode()
|
||||
private let cancelHighlightBackgroundNode = ASDisplayNode()
|
||||
private let doneButton = HighlightTrackingButtonNode()
|
||||
private let doneHighlightBackgroundNode = ASDisplayNode()
|
||||
private let separatorNode = ASDisplayNode()
|
||||
private let topSeparatorNode = ASDisplayNode()
|
||||
|
||||
@@ -47,7 +49,9 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
|
||||
super.init()
|
||||
|
||||
self.addSubnode(self.cancelHighlightBackgroundNode)
|
||||
self.addSubnode(self.cancelButton)
|
||||
self.addSubnode(self.doneHighlightBackgroundNode)
|
||||
self.addSubnode(self.doneButton)
|
||||
self.addSubnode(self.separatorNode)
|
||||
self.addSubnode(self.topSeparatorNode)
|
||||
@@ -57,11 +61,11 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
self.cancelButton.highligthedChanged = { [weak self] highlighted in
|
||||
if let strongSelf = self {
|
||||
if highlighted {
|
||||
strongSelf.cancelButton.backgroundColor = strongSelf.theme.list.itemHighlightedBackgroundColor
|
||||
strongSelf.cancelHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
|
||||
strongSelf.cancelHighlightBackgroundNode.alpha = 1.0
|
||||
} else {
|
||||
UIView.animate(withDuration: 0.3, animations: {
|
||||
strongSelf.cancelButton.backgroundColor = .clear
|
||||
})
|
||||
strongSelf.cancelHighlightBackgroundNode.alpha = 0.0
|
||||
strongSelf.cancelHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,11 +73,11 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
self.doneButton.highligthedChanged = { [weak self] highlighted in
|
||||
if let strongSelf = self {
|
||||
if highlighted {
|
||||
strongSelf.doneButton.backgroundColor = strongSelf.theme.list.itemHighlightedBackgroundColor
|
||||
strongSelf.doneHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
|
||||
strongSelf.doneHighlightBackgroundNode.alpha = 1.0
|
||||
} else {
|
||||
UIView.animate(withDuration: 0.3, animations: {
|
||||
strongSelf.doneButton.backgroundColor = .clear
|
||||
})
|
||||
strongSelf.doneHighlightBackgroundNode.alpha = 0.0
|
||||
strongSelf.doneHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +96,8 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
self.backgroundColor = theme.rootController.tabBar.backgroundColor
|
||||
self.separatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
|
||||
self.topSeparatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
|
||||
self.cancelHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
|
||||
self.doneHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
|
||||
|
||||
let cancelTitle: String
|
||||
switch self.cancelButtonType {
|
||||
@@ -118,7 +124,9 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
|
||||
|
||||
func updateLayout(size: CGSize, layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
self.cancelButton.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
|
||||
self.cancelHighlightBackgroundNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
|
||||
self.doneButton.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
|
||||
self.doneHighlightBackgroundNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
|
||||
self.separatorNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: UIScreenPixel, height: size.height + layout.intrinsicInsets.bottom))
|
||||
self.topSeparatorNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: UIScreenPixel))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user