Refactoring [skip ci]

This commit is contained in:
Ali
2021-09-25 01:06:04 +03:00
parent 00b6826303
commit 94380c546b
29 changed files with 268 additions and 321 deletions

View File

@@ -3,7 +3,6 @@ import UIKit
import Display
import AsyncDisplayKit
import SwiftSignalKit
import Postbox
import TelegramCore
import MapKit
import TelegramPresentationData
@@ -71,7 +70,7 @@ public final class OpenInActionSheetController: ActionSheetController {
}
var items: [ActionSheetItem] = []
items.append(OpenInActionSheetItem(postbox: context.account.postbox, context: context, strings: strings, options: availableOpenInOptions(context: context, item: item), invokeAction: invokeActionImpl))
items.append(OpenInActionSheetItem(context: context, strings: strings, options: availableOpenInOptions(context: context, item: item), invokeAction: invokeActionImpl))
if let action = additionalAction {
items.append(ActionSheetButtonItem(title: action.title, action: { [weak self] in
@@ -100,14 +99,12 @@ public final class OpenInActionSheetController: ActionSheetController {
}
private final class OpenInActionSheetItem: ActionSheetItem {
let postbox: Postbox
let context: AccountContext
let strings: PresentationStrings
let options: [OpenInOption]
let invokeAction: (OpenInAction) -> Void
init(postbox: Postbox, context: AccountContext, strings: PresentationStrings, options: [OpenInOption], invokeAction: @escaping (OpenInAction) -> Void) {
self.postbox = postbox
init(context: AccountContext, strings: PresentationStrings, options: [OpenInOption], invokeAction: @escaping (OpenInAction) -> Void) {
self.context = context
self.strings = strings
self.options = options
@@ -115,7 +112,7 @@ private final class OpenInActionSheetItem: ActionSheetItem {
}
func node(theme: ActionSheetControllerTheme) -> ActionSheetItemNode {
return OpenInActionSheetItemNode(postbox: self.postbox, context: self.context, theme: theme, strings: self.strings, options: self.options, invokeAction: self.invokeAction)
return OpenInActionSheetItemNode(context: self.context, theme: theme, strings: self.strings, options: self.options, invokeAction: self.invokeAction)
}
func updateNode(_ node: ActionSheetItemNode) {
@@ -131,7 +128,7 @@ private final class OpenInActionSheetItemNode: ActionSheetItemNode {
let openInNodes: [OpenInAppNode]
init(postbox: Postbox, context: AccountContext, theme: ActionSheetControllerTheme, strings: PresentationStrings, options: [OpenInOption], invokeAction: @escaping (OpenInAction) -> Void) {
init(context: AccountContext, theme: ActionSheetControllerTheme, strings: PresentationStrings, options: [OpenInOption], invokeAction: @escaping (OpenInAction) -> Void) {
self.theme = theme
self.strings = strings
@@ -152,7 +149,7 @@ private final class OpenInActionSheetItemNode: ActionSheetItemNode {
self.openInNodes = options.map { option in
let node = OpenInAppNode()
node.setup(postbox: postbox, context: context, theme: theme, option: option, invokeAction: invokeAction)
node.setup(context: context, theme: theme, option: option, invokeAction: invokeAction)
return node
}
@@ -217,7 +214,7 @@ private final class OpenInAppNode : ASDisplayNode {
self.addSubnode(self.textNode)
}
func setup(postbox: Postbox, context: AccountContext, theme: ActionSheetControllerTheme, option: OpenInOption, invokeAction: @escaping (OpenInAction) -> Void) {
func setup(context: AccountContext, theme: ActionSheetControllerTheme, option: OpenInOption, invokeAction: @escaping (OpenInAction) -> Void) {
let textFont = Font.regular(floor(theme.baseFontSize * 11.0 / 17.0))
self.textNode.attributedText = NSAttributedString(string: option.title, font: textFont, textColor: theme.primaryTextColor, paragraphAlignment: .center)
@@ -229,14 +226,14 @@ private final class OpenInAppNode : ASDisplayNode {
switch option.application {
case .safari:
if let image = UIImage(bundleImageName: "Open In/Safari") {
self.iconNode.setSignal(openInAppIcon(postbox: postbox, appIcon: .image(image: image)))
self.iconNode.setSignal(openInAppIcon(engine: context.engine, appIcon: .image(image: image)))
}
case .maps:
if let image = UIImage(bundleImageName: "Open In/Maps") {
self.iconNode.setSignal(openInAppIcon(postbox: postbox, appIcon: .image(image: image)))
self.iconNode.setSignal(openInAppIcon(engine: context.engine, appIcon: .image(image: image)))
}
case let .other(_, identifier, _, store):
self.iconNode.setSignal(openInAppIcon(postbox: postbox, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store))))
self.iconNode.setSignal(openInAppIcon(engine: context.engine, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store))))
}
self.action = {