Various improvements

This commit is contained in:
Ilya Laktyushin
2024-07-16 06:41:23 +04:00
parent 002e0a7082
commit ada188209e
6 changed files with 42 additions and 26 deletions

View File

@@ -917,8 +917,10 @@ public func dataAndStorageController(context: AccountContext, focusOnItemTag: Da
let defaultWebBrowser: String
if let option = options.first(where: { $0.identifier == webBrowserSettings.defaultWebBrowser }) {
defaultWebBrowser = option.title
} else {
} else if webBrowserSettings.defaultWebBrowser == "inApp" {
defaultWebBrowser = presentationData.strings.WebBrowser_InAppSafari
} else {
defaultWebBrowser = presentationData.strings.WebBrowser_Telegram
}
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.ChatSettings_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false)

View File

@@ -8,18 +8,20 @@ import TelegramPresentationData
import ItemListUI
import PhotoResources
import OpenInExternalAppUI
import AccountContext
import AppBundle
class WebBrowserItem: ListViewItem, ItemListItem {
let engine: TelegramEngine
let context: AccountContext
let presentationData: ItemListPresentationData
let title: String
let application: OpenInApplication
let application: OpenInApplication?
let checked: Bool
public let sectionId: ItemListSectionId
let action: () -> Void
public init(engine: TelegramEngine, presentationData: ItemListPresentationData, title: String, application: OpenInApplication, checked: Bool, sectionId: ItemListSectionId, action: @escaping () -> Void) {
self.engine = engine
public init(context: AccountContext, presentationData: ItemListPresentationData, title: String, application: OpenInApplication?, checked: Bool, sectionId: ItemListSectionId, action: @escaping () -> Void) {
self.context = context
self.presentationData = presentationData
self.title = title
self.application = application
@@ -131,6 +133,7 @@ private final class WebBrowserItemNode: ListViewItemNode {
let makeIconLayout = self.iconNode.asyncLayout()
let currentItem = self.item
return { item, params, neighbors in
let leftInset: CGFloat = params.leftInset + 16.0 + 43.0
@@ -140,18 +143,25 @@ private final class WebBrowserItemNode: ListViewItemNode {
let imageApply = makeIconLayout(arguments)
var updatedIconSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError>?
if currentItem?.application != item.application {
if currentItem == nil {
switch item.application {
case .none:
let icons = item.context.sharedContext.applicationBindings.getAvailableAlternateIcons()
let current = item.context.sharedContext.applicationBindings.getAlternateIconName()
let currentIcon = icons.first(where: { $0.name == current })?.imageName ?? "BlueIcon"
if let image = UIImage(named: currentIcon, in: getAppBundle(), compatibleWith: nil) {
updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image))
}
case .safari:
if let image = UIImage(bundleImageName: "Open In/Safari") {
updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .image(image: image))
updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image))
}
case .maps:
if let image = UIImage(bundleImageName: "Open In/Maps") {
updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .image(image: image))
updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .image(image: image))
}
case let .other(_, identifier, _, store):
updatedIconSignal = openInAppIcon(engine: item.engine, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store)))
updatedIconSignal = openInAppIcon(engine: item.context.engine, appIcon: .resource(resource: OpenInAppIconResource(appStoreId: identifier, store: store)))
}
}

View File

@@ -26,7 +26,7 @@ private enum WebBrowserSettingsSection: Int32 {
private enum WebBrowserSettingsControllerEntry: ItemListNodeEntry {
case browserHeader(PresentationTheme, String)
case browser(PresentationTheme, String, OpenInApplication, String?, Bool, Int32)
case browser(PresentationTheme, String, OpenInApplication?, String?, Bool, Int32)
var section: ItemListSectionId {
switch self {
@@ -71,7 +71,7 @@ private enum WebBrowserSettingsControllerEntry: ItemListNodeEntry {
case let .browserHeader(_, text):
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
case let .browser(_, title, application, identifier, selected, _):
return WebBrowserItem(engine: arguments.context.engine, presentationData: presentationData, title: title, application: application, checked: selected, sectionId: self.section) {
return WebBrowserItem(context: arguments.context, presentationData: presentationData, title: title, application: application, checked: selected, sectionId: self.section) {
arguments.updateDefaultBrowser(identifier)
}
}
@@ -84,9 +84,10 @@ private func webBrowserSettingsControllerEntries(context: AccountContext, presen
let options = availableOpenInOptions(context: context, item: .url(url: "http://telegram.org"))
entries.append(.browserHeader(presentationData.theme, presentationData.strings.WebBrowser_DefaultBrowser))
entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_InAppSafari, .safari, nil, selectedBrowser == nil, 0))
entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_Telegram, nil, nil, selectedBrowser == nil, 0))
entries.append(.browser(presentationData.theme, presentationData.strings.WebBrowser_InAppSafari, .safari, "inApp", selectedBrowser == "inApp", 1))
var index: Int32 = 1
var index: Int32 = 2
for option in options {
entries.append(.browser(presentationData.theme, option.title, option.application, option.identifier, option.identifier == selectedBrowser, index))
index += 1