mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 03:40:18 +00:00
Various fixes
This commit is contained in:
parent
ccd07a574f
commit
85c1b270ff
@ -4676,13 +4676,13 @@ Any member of this group will be able to see messages in the channel.";
|
|||||||
"EditTheme.EditTitle" = "Edit Theme";
|
"EditTheme.EditTitle" = "Edit Theme";
|
||||||
"EditTheme.Title" = "Theme Name";
|
"EditTheme.Title" = "Theme Name";
|
||||||
"EditTheme.ShortLink" = "link";
|
"EditTheme.ShortLink" = "link";
|
||||||
"EditTheme.ShortLinkInfo" = "Short Link Info";
|
"EditTheme.ShortLinkInfo" = "Your theme will be updated for all users each time you change it. Anyone can install it using this link.\n\nTheme links must be longer than 5 characters and can use a-z, 0-9 and underscores.";
|
||||||
"EditTheme.Preview" = "CHAT PREVIEW";
|
"EditTheme.Preview" = "CHAT PREVIEW";
|
||||||
"EditTheme.UploadNewTheme" = "Select a File...";
|
"EditTheme.UploadNewTheme" = "Create from File...";
|
||||||
"EditTheme.UploadEditedTheme" = "Select Updated File...";
|
"EditTheme.UploadEditedTheme" = "Update from File...";
|
||||||
"EditTheme.UploadNewInfo" = "This theme will be based on your current theme and wallpaper. Otherwise, you can use a custom theme file if you already have one.";
|
"EditTheme.UploadNewInfo" = "This theme will be based on your current theme and wallpaper. Alternatively, you can use a custom theme file if you already have one.";
|
||||||
"EditTheme.UploadEditedInfo" = "You can select a new file to update the theme. It will be updated for all users.";
|
"EditTheme.UploadEditedInfo" = "You can select a new file to update the theme. It will be updated for all users.";
|
||||||
"EditTheme.ThemeTemplateAlert" = "A copy of your theme template has been added to your Saved Messages.";
|
"EditTheme.ThemeTemplateAlert" = "New Theme Added\n\nPress and hold on your theme to edit it or get a sharing link. Users who install your theme will get automatic updates each time you change it.\n\nFor advanced editing purposes, you can find a file with your theme in Saved Messages.";
|
||||||
"EditTheme.FileReadError" = "Invalid theme file";
|
"EditTheme.FileReadError" = "Invalid theme file";
|
||||||
|
|
||||||
"Wallpaper.ErrorNotFound" = "Sorry, this chat background doesn't seem to exist.";
|
"Wallpaper.ErrorNotFound" = "Sorry, this chat background doesn't seem to exist.";
|
||||||
|
|||||||
@ -131,7 +131,7 @@ private enum EditThemeControllerEntry: ItemListNodeEntry {
|
|||||||
|
|
||||||
func item(_ arguments: EditThemeControllerArguments) -> ListViewItem {
|
func item(_ arguments: EditThemeControllerArguments) -> ListViewItem {
|
||||||
switch self {
|
switch self {
|
||||||
case let .title(theme, strings, title, text, done):
|
case let .title(theme, strings, title, text, _):
|
||||||
return ItemListSingleLineInputItem(theme: theme, strings: strings, title: NSAttributedString(), text: text, placeholder: title, type: .regular(capitalization: true, autocorrection: false), returnKeyType: .default, clearType: .onFocus, tag: EditThemeEntryTag.title, sectionId: self.section, textUpdated: { value in
|
return ItemListSingleLineInputItem(theme: theme, strings: strings, title: NSAttributedString(), text: text, placeholder: title, type: .regular(capitalization: true, autocorrection: false), returnKeyType: .default, clearType: .onFocus, tag: EditThemeEntryTag.title, sectionId: self.section, textUpdated: { value in
|
||||||
arguments.updateState { current in
|
arguments.updateState { current in
|
||||||
var state = current
|
var state = current
|
||||||
@ -152,7 +152,7 @@ private enum EditThemeControllerEntry: ItemListNodeEntry {
|
|||||||
|
|
||||||
})
|
})
|
||||||
case let .slugInfo(theme, text):
|
case let .slugInfo(theme, text):
|
||||||
return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section)
|
return ItemListTextItem(theme: theme, text: .markdown(text), sectionId: self.section)
|
||||||
case let .chatPreviewHeader(theme, text):
|
case let .chatPreviewHeader(theme, text):
|
||||||
return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section)
|
return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section)
|
||||||
case let .chatPreview(theme, componentTheme, wallpaper, fontSize, strings, dateTimeFormat, nameDisplayOrder):
|
case let .chatPreview(theme, componentTheme, wallpaper, fontSize, strings, dateTimeFormat, nameDisplayOrder):
|
||||||
@ -162,7 +162,7 @@ private enum EditThemeControllerEntry: ItemListNodeEntry {
|
|||||||
arguments.openFile()
|
arguments.openFile()
|
||||||
})
|
})
|
||||||
case let .uploadInfo(theme, text):
|
case let .uploadInfo(theme, text):
|
||||||
return ItemListTextItem(theme: theme, text: .plain(text), sectionId: self.section)
|
return ItemListTextItem(theme: theme, text: .markdown(text), sectionId: self.section)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,22 +12,24 @@ final class ThemeGridControllerItem: GridItem {
|
|||||||
let context: AccountContext
|
let context: AccountContext
|
||||||
let wallpaper: TelegramWallpaper
|
let wallpaper: TelegramWallpaper
|
||||||
let index: Int
|
let index: Int
|
||||||
|
let editable: Bool
|
||||||
let selected: Bool
|
let selected: Bool
|
||||||
let interaction: ThemeGridControllerInteraction
|
let interaction: ThemeGridControllerInteraction
|
||||||
|
|
||||||
let section: GridSection? = nil
|
let section: GridSection? = nil
|
||||||
|
|
||||||
init(context: AccountContext, wallpaper: TelegramWallpaper, index: Int, selected: Bool, interaction: ThemeGridControllerInteraction) {
|
init(context: AccountContext, wallpaper: TelegramWallpaper, index: Int, editable: Bool, selected: Bool, interaction: ThemeGridControllerInteraction) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.wallpaper = wallpaper
|
self.wallpaper = wallpaper
|
||||||
self.index = index
|
self.index = index
|
||||||
|
self.editable = editable
|
||||||
self.selected = selected
|
self.selected = selected
|
||||||
self.interaction = interaction
|
self.interaction = interaction
|
||||||
}
|
}
|
||||||
|
|
||||||
func node(layout: GridNodeLayout, synchronousLoad: Bool) -> GridItemNode {
|
func node(layout: GridNodeLayout, synchronousLoad: Bool) -> GridItemNode {
|
||||||
let node = ThemeGridControllerItemNode()
|
let node = ThemeGridControllerItemNode()
|
||||||
node.setup(context: self.context, wallpaper: self.wallpaper, selected: self.selected, interaction: self.interaction, synchronousLoad: synchronousLoad)
|
node.setup(context: self.context, wallpaper: self.wallpaper, editable: self.editable, selected: self.selected, interaction: self.interaction, synchronousLoad: synchronousLoad)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ final class ThemeGridControllerItem: GridItem {
|
|||||||
assertionFailure()
|
assertionFailure()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node.setup(context: self.context, wallpaper: self.wallpaper, selected: self.selected, interaction: self.interaction, synchronousLoad: false)
|
node.setup(context: self.context, wallpaper: self.wallpaper, editable: self.editable, selected: self.selected, interaction: self.interaction, synchronousLoad: false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ final class ThemeGridControllerItemNode: GridItemNode {
|
|||||||
private let wallpaperNode: SettingsThemeWallpaperNode
|
private let wallpaperNode: SettingsThemeWallpaperNode
|
||||||
private var selectionNode: GridMessageSelectionNode?
|
private var selectionNode: GridMessageSelectionNode?
|
||||||
|
|
||||||
private var currentState: (AccountContext, TelegramWallpaper, Bool, Bool)?
|
private var currentState: (AccountContext, TelegramWallpaper, Bool, Bool, Bool)?
|
||||||
private var interaction: ThemeGridControllerInteraction?
|
private var interaction: ThemeGridControllerInteraction?
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
@ -61,11 +63,11 @@ final class ThemeGridControllerItemNode: GridItemNode {
|
|||||||
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
|
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.tapGesture(_:))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup(context: AccountContext, wallpaper: TelegramWallpaper, selected: Bool, interaction: ThemeGridControllerInteraction, synchronousLoad: Bool) {
|
func setup(context: AccountContext, wallpaper: TelegramWallpaper, editable: Bool, selected: Bool, interaction: ThemeGridControllerInteraction, synchronousLoad: Bool) {
|
||||||
self.interaction = interaction
|
self.interaction = interaction
|
||||||
|
|
||||||
if self.currentState == nil || self.currentState!.0 !== context || wallpaper != self.currentState!.1 || selected != self.currentState!.2 || synchronousLoad != self.currentState!.3 {
|
if self.currentState == nil || self.currentState!.0 !== context || wallpaper != self.currentState!.1 || selected != self.currentState!.2 || synchronousLoad != self.currentState!.3 || editable != self.currentState!.4 {
|
||||||
self.currentState = (context, wallpaper, selected, synchronousLoad)
|
self.currentState = (context, wallpaper, selected, synchronousLoad, editable)
|
||||||
self.updateSelectionState(animated: false)
|
self.updateSelectionState(animated: false)
|
||||||
self.setNeedsLayout()
|
self.setNeedsLayout()
|
||||||
}
|
}
|
||||||
@ -73,14 +75,14 @@ final class ThemeGridControllerItemNode: GridItemNode {
|
|||||||
|
|
||||||
@objc func tapGesture(_ recognizer: UITapGestureRecognizer) {
|
@objc func tapGesture(_ recognizer: UITapGestureRecognizer) {
|
||||||
if case .ended = recognizer.state {
|
if case .ended = recognizer.state {
|
||||||
if let (_, wallpaper, _, _) = self.currentState {
|
if let (_, wallpaper, _, _, _) = self.currentState {
|
||||||
self.interaction?.openWallpaper(wallpaper)
|
self.interaction?.openWallpaper(wallpaper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSelectionState(animated: Bool) {
|
func updateSelectionState(animated: Bool) {
|
||||||
if let (context, wallpaper, _, _) = self.currentState {
|
if let (context, wallpaper, _, _, editable) = self.currentState {
|
||||||
var editing = false
|
var editing = false
|
||||||
var id: Int64?
|
var id: Int64?
|
||||||
if case let .file(file) = wallpaper {
|
if case let .file(file) = wallpaper {
|
||||||
@ -94,7 +96,7 @@ final class ThemeGridControllerItemNode: GridItemNode {
|
|||||||
editing = active
|
editing = active
|
||||||
selectedIndices = indices
|
selectedIndices = indices
|
||||||
}
|
}
|
||||||
if let id = id, editing {
|
if let id = id, editing && editable {
|
||||||
let selected = selectedIndices.contains(id)
|
let selected = selectedIndices.contains(id)
|
||||||
|
|
||||||
if let selectionNode = self.selectionNode {
|
if let selectionNode = self.selectionNode {
|
||||||
@ -136,7 +138,7 @@ final class ThemeGridControllerItemNode: GridItemNode {
|
|||||||
super.layout()
|
super.layout()
|
||||||
|
|
||||||
let bounds = self.bounds
|
let bounds = self.bounds
|
||||||
if let (context, wallpaper, selected, synchronousLoad) = self.currentState {
|
if let (context, wallpaper, selected, synchronousLoad, _) = self.currentState {
|
||||||
self.wallpaperNode.setWallpaper(context: context, wallpaper: wallpaper, selected: selected, size: bounds.size, synchronousLoad: synchronousLoad)
|
self.wallpaperNode.setWallpaper(context: context, wallpaper: wallpaper, selected: selected, size: bounds.size, synchronousLoad: synchronousLoad)
|
||||||
self.selectionNode?.frame = CGRect(origin: CGPoint(), size: bounds.size)
|
self.selectionNode?.frame = CGRect(origin: CGPoint(), size: bounds.size)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,10 +84,11 @@ final class ThemeGridControllerInteraction {
|
|||||||
private struct ThemeGridControllerEntry: Comparable, Identifiable {
|
private struct ThemeGridControllerEntry: Comparable, Identifiable {
|
||||||
let index: Int
|
let index: Int
|
||||||
let wallpaper: TelegramWallpaper
|
let wallpaper: TelegramWallpaper
|
||||||
let selected: Bool
|
let isEditable: Bool
|
||||||
|
let isSelected: Bool
|
||||||
|
|
||||||
static func ==(lhs: ThemeGridControllerEntry, rhs: ThemeGridControllerEntry) -> Bool {
|
static func ==(lhs: ThemeGridControllerEntry, rhs: ThemeGridControllerEntry) -> Bool {
|
||||||
return lhs.index == rhs.index && lhs.wallpaper == rhs.wallpaper && lhs.selected == rhs.selected
|
return lhs.index == rhs.index && lhs.wallpaper == rhs.wallpaper && lhs.isEditable == rhs.isEditable && lhs.isSelected == rhs.isSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
static func <(lhs: ThemeGridControllerEntry, rhs: ThemeGridControllerEntry) -> Bool {
|
static func <(lhs: ThemeGridControllerEntry, rhs: ThemeGridControllerEntry) -> Bool {
|
||||||
@ -115,7 +116,7 @@ private struct ThemeGridControllerEntry: Comparable, Identifiable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func item(context: AccountContext, interaction: ThemeGridControllerInteraction) -> ThemeGridControllerItem {
|
func item(context: AccountContext, interaction: ThemeGridControllerInteraction) -> ThemeGridControllerItem {
|
||||||
return ThemeGridControllerItem(context: context, wallpaper: self.wallpaper, index: self.index, selected: self.selected, interaction: interaction)
|
return ThemeGridControllerItem(context: context, wallpaper: self.wallpaper, index: self.index, editable: self.isEditable, selected: self.isSelected, interaction: interaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,14 +365,20 @@ final class ThemeGridControllerNode: ASDisplayNode {
|
|||||||
var entries: [ThemeGridControllerEntry] = []
|
var entries: [ThemeGridControllerEntry] = []
|
||||||
var index = 1
|
var index = 1
|
||||||
|
|
||||||
entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, selected: true), at: 0)
|
var isSelectedEditable = true
|
||||||
|
if case .builtin = presentationData.chatWallpaper {
|
||||||
|
isSelectedEditable = false
|
||||||
|
} else if areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) {
|
||||||
|
isSelectedEditable = false
|
||||||
|
}
|
||||||
|
entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, isEditable: isSelectedEditable, isSelected: true), at: 0)
|
||||||
|
|
||||||
var defaultWallpaper: TelegramWallpaper?
|
var defaultWallpaper: TelegramWallpaper?
|
||||||
if !areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) {
|
if !areWallpapersEqual(presentationData.chatWallpaper, presentationData.theme.chat.defaultWallpaper) {
|
||||||
if case .builtin = presentationData.theme.chat.defaultWallpaper {
|
if case .builtin = presentationData.theme.chat.defaultWallpaper {
|
||||||
} else {
|
} else {
|
||||||
defaultWallpaper = presentationData.theme.chat.defaultWallpaper
|
defaultWallpaper = presentationData.theme.chat.defaultWallpaper
|
||||||
entries.insert(ThemeGridControllerEntry(index: 1, wallpaper: presentationData.theme.chat.defaultWallpaper, selected: false), at: 1)
|
entries.insert(ThemeGridControllerEntry(index: 1, wallpaper: presentationData.theme.chat.defaultWallpaper, isEditable: false, isSelected: false), at: 1)
|
||||||
index += 1
|
index += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,8 +407,12 @@ final class ThemeGridControllerNode: ASDisplayNode {
|
|||||||
if let defaultWallpaper = defaultWallpaper, areWallpapersEqual(defaultWallpaper, wallpaper) {
|
if let defaultWallpaper = defaultWallpaper, areWallpapersEqual(defaultWallpaper, wallpaper) {
|
||||||
isDefault = true
|
isDefault = true
|
||||||
}
|
}
|
||||||
|
var isEditable = true
|
||||||
|
if case .builtin = wallpaper {
|
||||||
|
isEditable = false
|
||||||
|
}
|
||||||
if !selected && !isDefault {
|
if !selected && !isDefault {
|
||||||
entries.append(ThemeGridControllerEntry(index: index, wallpaper: wallpaper, selected: false))
|
entries.append(ThemeGridControllerEntry(index: index, wallpaper: wallpaper, isEditable: isEditable, isSelected: false))
|
||||||
}
|
}
|
||||||
index += 1
|
index += 1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,6 +145,7 @@ private final class ThemeSettingsThemeItemIconNode : ASDisplayNode {
|
|||||||
|
|
||||||
private var theme: PresentationThemeReference?
|
private var theme: PresentationThemeReference?
|
||||||
private var currentTheme: PresentationTheme?
|
private var currentTheme: PresentationTheme?
|
||||||
|
private var accentColor: UIColor?
|
||||||
private var bordered: Bool?
|
private var bordered: Bool?
|
||||||
private var selected: Bool?
|
private var selected: Bool?
|
||||||
|
|
||||||
@ -175,9 +176,10 @@ private final class ThemeSettingsThemeItemIconNode : ASDisplayNode {
|
|||||||
self.currentTheme = currentTheme
|
self.currentTheme = currentTheme
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if theme != self.theme {
|
if theme != self.theme || accentColor != self.accentColor {
|
||||||
self.imageNode.setSignal(themeIconImage(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme, accentColor: accentColor))
|
self.imageNode.setSignal(themeIconImage(account: context.account, accountManager: context.sharedContext.accountManager, theme: theme, accentColor: accentColor))
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
|
self.accentColor = accentColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.currentTheme == nil || currentTheme !== self.currentTheme! || bordered != self.bordered || selected != self.selected {
|
if self.currentTheme == nil || currentTheme !== self.currentTheme! || bordered != self.bordered || selected != self.selected {
|
||||||
|
|||||||
@ -246,6 +246,8 @@ final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode {
|
|||||||
mainMedia = webpage.file ?? webpage.image
|
mainMedia = webpage.file ?? webpage.image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let themeMimeType = "application/x-tgtheme-ios"
|
||||||
|
|
||||||
if let file = mainMedia as? TelegramMediaFile, webpage.type != "telegram_theme" {
|
if let file = mainMedia as? TelegramMediaFile, webpage.type != "telegram_theme" {
|
||||||
if let embedUrl = webpage.embedUrl, !embedUrl.isEmpty {
|
if let embedUrl = webpage.embedUrl, !embedUrl.isEmpty {
|
||||||
if automaticPlayback {
|
if automaticPlayback {
|
||||||
@ -295,10 +297,13 @@ final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode {
|
|||||||
}
|
}
|
||||||
} else if type == "telegram_theme" {
|
} else if type == "telegram_theme" {
|
||||||
var file: TelegramMediaFile?
|
var file: TelegramMediaFile?
|
||||||
let mimeType = "application/x-tgtheme-ios"
|
if let contentFiles = webpage.files {
|
||||||
if let contentFiles = webpage.files, let filteredFile = contentFiles.filter({ $0.mimeType == mimeType }).first {
|
if let filteredFile = contentFiles.filter({ $0.mimeType == themeMimeType }).first {
|
||||||
file = filteredFile
|
file = filteredFile
|
||||||
} else if let contentFile = webpage.file, contentFile.mimeType == mimeType {
|
} else {
|
||||||
|
file = contentFiles.first
|
||||||
|
}
|
||||||
|
} else if let contentFile = webpage.file {
|
||||||
file = contentFile
|
file = contentFile
|
||||||
}
|
}
|
||||||
if let file = file {
|
if let file = file {
|
||||||
@ -332,9 +337,7 @@ final class ChatMessageWebpageBubbleContentNode: ChatMessageBubbleContentNode {
|
|||||||
case "telegram_theme":
|
case "telegram_theme":
|
||||||
title = item.presentationData.strings.Conversation_Theme
|
title = item.presentationData.strings.Conversation_Theme
|
||||||
text = nil
|
text = nil
|
||||||
if mediaAndFlags != nil {
|
actionTitle = item.presentationData.strings.Conversation_ViewTheme
|
||||||
actionTitle = item.presentationData.strings.Conversation_ViewTheme
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import StickerPackPreviewUI
|
|||||||
import PeerAvatarGalleryUI
|
import PeerAvatarGalleryUI
|
||||||
import PeerInfoUI
|
import PeerInfoUI
|
||||||
import SettingsUI
|
import SettingsUI
|
||||||
|
import AlertUI
|
||||||
|
|
||||||
private enum ChatMessageGalleryControllerData {
|
private enum ChatMessageGalleryControllerData {
|
||||||
case url(String)
|
case url(String)
|
||||||
@ -475,6 +476,9 @@ func openChatTheme(context: AccountContext, message: Message, present: @escaping
|
|||||||
let controller = ThemePreviewController(context: context, previewTheme: theme, source: .slug(slug, file))
|
let controller = ThemePreviewController(context: context, previewTheme: theme, source: .slug(slug, file))
|
||||||
present(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
present(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
|
present(textAlertController(context: context, title: nil, text: presentationData.strings.Theme_Unsupported, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -288,6 +288,14 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur
|
|||||||
present(previewController, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
present(previewController, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||||
}
|
}
|
||||||
}, error: { [weak controller] error in
|
}, error: { [weak controller] error in
|
||||||
|
let errorText: String
|
||||||
|
switch error {
|
||||||
|
case .generic, .slugInvalid:
|
||||||
|
errorText = presentationData.strings.Theme_ErrorNotFound
|
||||||
|
case .unsupported:
|
||||||
|
errorText = presentationData.strings.Theme_Unsupported
|
||||||
|
}
|
||||||
|
present(textAlertController(context: context, title: nil, text: errorText, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), nil)
|
||||||
controller?.dismiss()
|
controller?.dismiss()
|
||||||
})
|
})
|
||||||
dismissInput()
|
dismissInput()
|
||||||
|
|||||||
@ -728,11 +728,12 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func themeImage(account: Account, accountManager: AccountManager, fileReference: FileMediaReference, synchronousLoad: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
public func themeImage(account: Account, accountManager: AccountManager, fileReference: FileMediaReference, synchronousLoad: Bool = false) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
|
||||||
|
let isSupportedTheme = fileReference.media.mimeType == "application/x-tgtheme-ios"
|
||||||
let maybeFetched = accountManager.mediaBox.resourceData(fileReference.media.resource, option: .complete(waitUntilFetchStatus: false), attemptSynchronously: synchronousLoad)
|
let maybeFetched = accountManager.mediaBox.resourceData(fileReference.media.resource, option: .complete(waitUntilFetchStatus: false), attemptSynchronously: synchronousLoad)
|
||||||
let data = maybeFetched
|
let data = maybeFetched
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> mapToSignal { maybeData -> Signal<(Data?, Data?), NoError> in
|
|> mapToSignal { maybeData -> Signal<(Data?, Data?), NoError> in
|
||||||
if maybeData.complete {
|
if maybeData.complete && isSupportedTheme {
|
||||||
let loadedData: Data? = try? Data(contentsOf: URL(fileURLWithPath: maybeData.path), options: [])
|
let loadedData: Data? = try? Data(contentsOf: URL(fileURLWithPath: maybeData.path), options: [])
|
||||||
return .single((loadedData, nil))
|
return .single((loadedData, nil))
|
||||||
} else {
|
} else {
|
||||||
@ -769,25 +770,30 @@ public func themeImage(account: Account, accountManager: AccountManager, fileRef
|
|||||||
}
|
}
|
||||||
|
|
||||||
let reference = fileReference.resourceReference(fileReference.media.resource)
|
let reference = fileReference.resourceReference(fileReference.media.resource)
|
||||||
let fullSizeData = Signal<Data?, NoError> { subscriber in
|
let fullSizeData: Signal<Data?, NoError>
|
||||||
let fetch = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: reference).start()
|
if isSupportedTheme {
|
||||||
let disposable = (account.postbox.mediaBox.resourceData(reference.resource, option: .complete(waitUntilFetchStatus: false), attemptSynchronously: false)
|
fullSizeData = Signal { subscriber in
|
||||||
|> map { data -> Data? in
|
let fetch = fetchedMediaResource(mediaBox: account.postbox.mediaBox, reference: reference).start()
|
||||||
return data.complete ? try? Data(contentsOf: URL(fileURLWithPath: data.path)) : nil
|
let disposable = (account.postbox.mediaBox.resourceData(reference.resource, option: .complete(waitUntilFetchStatus: false), attemptSynchronously: false)
|
||||||
}).start(next: { next in
|
|> map { data -> Data? in
|
||||||
if let data = next {
|
return data.complete ? try? Data(contentsOf: URL(fileURLWithPath: data.path)) : nil
|
||||||
accountManager.mediaBox.storeResourceData(reference.resource.id, data: data)
|
}).start(next: { next in
|
||||||
}
|
if let data = next {
|
||||||
subscriber.putNext(next)
|
accountManager.mediaBox.storeResourceData(reference.resource.id, data: data)
|
||||||
}, error: { error in
|
}
|
||||||
subscriber.putError(error)
|
subscriber.putNext(next)
|
||||||
}, completed: {
|
}, error: { error in
|
||||||
subscriber.putCompletion()
|
subscriber.putError(error)
|
||||||
})
|
}, completed: {
|
||||||
return ActionDisposable {
|
subscriber.putCompletion()
|
||||||
fetch.dispose()
|
})
|
||||||
disposable.dispose()
|
return ActionDisposable {
|
||||||
|
fetch.dispose()
|
||||||
|
disposable.dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fullSizeData = .single(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return thumbnailData |> mapToSignal { thumbnailData in
|
return thumbnailData |> mapToSignal { thumbnailData in
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user