From d4b769f5a15d0beb15b7373ad0883d38a8e3aa8b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 23 Aug 2024 01:45:37 +0400 Subject: [PATCH 1/2] Various fixes --- .../Sources/BrowserInstantPageContent.swift | 1 - submodules/Camera/Sources/CameraDevice.swift | 5 +- .../LocationPickerControllerNode.swift | 74 ++++++++++++++++--- .../Sources/StatsOverviewItem.swift | 6 +- .../Sources/VideoMessageCameraScreen.swift | 6 +- 5 files changed, 72 insertions(+), 20 deletions(-) diff --git a/submodules/BrowserUI/Sources/BrowserInstantPageContent.swift b/submodules/BrowserUI/Sources/BrowserInstantPageContent.swift index f334322e60..bc327edadf 100644 --- a/submodules/BrowserUI/Sources/BrowserInstantPageContent.swift +++ b/submodules/BrowserUI/Sources/BrowserInstantPageContent.swift @@ -160,7 +160,6 @@ final class BrowserInstantPageContent: UIView, BrowserContent, UIScrollViewDeleg guard let self else { return } - self.webPage = result self.updateWebPage(result, anchor: self.initialAnchor) }) } diff --git a/submodules/Camera/Sources/CameraDevice.swift b/submodules/Camera/Sources/CameraDevice.swift index d8c75fbe14..6778c2dff5 100644 --- a/submodules/Camera/Sources/CameraDevice.swift +++ b/submodules/Camera/Sources/CameraDevice.swift @@ -271,7 +271,10 @@ final class CameraDevice { return } self.transaction(device) { device in - device.torchMode = active ? .on : .off + let torchMode: AVCaptureDevice.TorchMode = active ? .on : .off + if device.isTorchModeSupported(torchMode) { + device.torchMode = active ? .on : .off + } } } diff --git a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift index 77df9cf0d4..f34b5e9527 100644 --- a/submodules/LocationUI/Sources/LocationPickerControllerNode.swift +++ b/submodules/LocationUI/Sources/LocationPickerControllerNode.swift @@ -266,6 +266,7 @@ struct LocationPickerState { var mapMode: LocationMapMode var displayingMapModeOptions: Bool var selectedLocation: LocationPickerLocation + var appxCoordinate: CLLocationCoordinate2D? var geoAddress: MapGeoAddress? var city: String? var street: String? @@ -279,6 +280,7 @@ struct LocationPickerState { self.mapMode = .map self.displayingMapModeOptions = false self.selectedLocation = .none + self.appxCoordinate = nil self.geoAddress = nil self.city = nil self.street = nil @@ -636,7 +638,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM let title: String var coordinate = userLocation?.coordinate switch strongSelf.mode { - case .share: + case .share: if source == .story { if let initialLocation = strongSelf.controller?.initialLocation { title = presentationData.strings.Location_AddThisLocation @@ -647,12 +649,24 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM } else { title = presentationData.strings.Map_SendMyCurrentLocation } - case .pick: - title = presentationData.strings.Map_SetThisLocation + case .pick: + title = presentationData.strings.Map_SetThisLocation } if source == .story { if state.city != "" { - entries.append(.city(presentationData.theme, state.city ?? presentationData.strings.Map_Locating, presentationData.strings.Location_TypeCity, nil, nil, nil, coordinate, state.city, state.geoAddress)) + let title: String + let name: String? + let geoAddress: MapGeoAddress? + if let city = state.city, let _ = state.appxCoordinate { + title = city + name = city + geoAddress = state.geoAddress + } else { + title = presentationData.strings.Map_Locating + name = nil + geoAddress = nil + } + entries.append(.city(presentationData.theme, title, presentationData.strings.Location_TypeCity, nil, nil, nil, state.appxCoordinate, name, geoAddress)) } if state.street != "" { entries.append(.location(presentationData.theme, state.street ?? presentationData.strings.Map_Locating, state.isStreet ? presentationData.strings.Location_TypeStreet : presentationData.strings.Location_TypeLocation, nil, nil, nil, coordinate, state.street, state.geoAddress, false)) @@ -801,13 +815,44 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM let locale = localeWithStrings(presentationData.strings) let enLocale = Locale(identifier: "en-US") - let setupGeocoding: (CLLocationCoordinate2D, @escaping (MapGeoAddress?, String, String?, String?, String?, Bool) -> Void) -> Void = { coordinate, completion in + let setupGeocoding: (CLLocationCoordinate2D, Bool, @escaping (MapGeoAddress?, CLLocationCoordinate2D?, String, String?, String?, String?, Bool) -> Void) -> Void = { coordinate, current, completion in strongSelf.geocodingDisposable.set( combineLatest( queue: Queue.mainQueue(), reverseGeocodeLocation(latitude: coordinate.latitude, longitude: coordinate.longitude, locale: locale), reverseGeocodeLocation(latitude: coordinate.latitude, longitude: coordinate.longitude, locale: enLocale) - ).start(next: { placemark, enPlacemark in + |> mapToSignal { placemark -> Signal<(ReverseGeocodedPlacemark, CLLocationCoordinate2D)?, NoError> in + guard let placemark else { + return .single(nil) + } + if current { + var cityName: String + if let city = placemark.city { + if let countryCode = placemark.countryCode { + cityName = "\(city), \(displayCountryName(countryCode, locale: locale))" + } else { + cityName = city + } + } else { + cityName = "" + } + if !cityName.isEmpty { + return geocodeLocation(address: cityName, locale: enLocale) + |> map { placemarks in + if let location = placemarks?.first(where: { $0.thoroughfare == nil })?.location { + return (placemark, location.coordinate) + } else { + return (placemark, coordinate) + } + } + } else { + return .single((placemark, coordinate)) + } + } else { + return .single((placemark, coordinate)) + } + } + ).start(next: { placemark, enPlacemarkAndAppCoordinate in var address = placemark?.fullAddress ?? "" if address.isEmpty { address = presentationData.strings.Map_Unknown @@ -842,16 +887,24 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM } var mapGeoAddress: MapGeoAddress? - if let countryCode, let enPlacemark { + if let countryCode, let enPlacemark = enPlacemarkAndAppCoordinate?.0 { mapGeoAddress = MapGeoAddress(country: countryCode, state: enPlacemark.state, city: enPlacemark.city, street: enPlacemark.street) } - completion(mapGeoAddress, address, cityName, streetName, countryCode, placemark?.street != nil) + var resolvedAppxCoordinate: CLLocationCoordinate2D? + if current, let appxCoordinate = enPlacemarkAndAppCoordinate?.1 { + let loc = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude) + let appxLoc = CLLocation(latitude: appxCoordinate.latitude, longitude: appxCoordinate.longitude) + if appxLoc.distance(from: loc) < 1000000 { + resolvedAppxCoordinate = appxCoordinate + } + } + completion(mapGeoAddress, resolvedAppxCoordinate, address, cityName, streetName, countryCode, placemark?.street != nil) } )) } if case let .location(coordinate, address, global) = state.selectedLocation, address == nil { - setupGeocoding(coordinate, { [weak self] geoAddress, address, cityName, streetName, countryCode, isStreet in + setupGeocoding(coordinate, false, { [weak self] geoAddress, _, address, cityName, streetName, countryCode, isStreet in self?.updateState { state in var state = state state.selectedLocation = .location(coordinate, address, global) @@ -866,10 +919,11 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM } else { let coordinate = controller.initialLocation ?? userLocation?.coordinate if case .none = state.selectedLocation, let coordinate, state.city == nil { - setupGeocoding(coordinate, { [weak self] geoAddress, address, cityName, streetName, countryCode, isStreet in + setupGeocoding(coordinate, true, { [weak self] geoAddress, appxCoordinate, address, cityName, streetName, countryCode, isStreet in self?.updateState { state in var state = state state.geoAddress = geoAddress + state.appxCoordinate = appxCoordinate state.city = cityName state.street = streetName state.countryCode = countryCode diff --git a/submodules/StatisticsUI/Sources/StatsOverviewItem.swift b/submodules/StatisticsUI/Sources/StatsOverviewItem.swift index 7df6ea96f5..3a59f66013 100644 --- a/submodules/StatisticsUI/Sources/StatsOverviewItem.swift +++ b/submodules/StatisticsUI/Sources/StatsOverviewItem.swift @@ -873,7 +873,7 @@ class StatsOverviewItemNode: ListViewItemNode { item.presentationData, presentationStringsFormattedNumber(Int32(stats.balances.availableBalance), item.presentationData.dateTimeFormat.groupingSeparator), item.presentationData.strings.Monetization_StarsProceeds_Available, - (stats.balances.availableBalance == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.availableBalance, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), + (stats.balances.availableBalance == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.availableBalance, divide: false, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), .stars ) @@ -883,7 +883,7 @@ class StatsOverviewItemNode: ListViewItemNode { item.presentationData, presentationStringsFormattedNumber(Int32(stats.balances.currentBalance), item.presentationData.dateTimeFormat.groupingSeparator), item.presentationData.strings.Monetization_StarsProceeds_Current, - (stats.balances.currentBalance == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.currentBalance, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), + (stats.balances.currentBalance == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.currentBalance, divide: false, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), .stars ) @@ -893,7 +893,7 @@ class StatsOverviewItemNode: ListViewItemNode { item.presentationData, presentationStringsFormattedNumber(Int32(stats.balances.overallRevenue), item.presentationData.dateTimeFormat.groupingSeparator), item.presentationData.strings.Monetization_StarsProceeds_Total, - (stats.balances.overallRevenue == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.overallRevenue, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), + (stats.balances.overallRevenue == 0 ? "" : "≈\(formatTonUsdValue(stats.balances.overallRevenue, divide: false, rate: stats.usdRate, dateTimeFormat: item.presentationData.dateTimeFormat))", .generic), .stars ) diff --git a/submodules/TelegramUI/Components/VideoMessageCameraScreen/Sources/VideoMessageCameraScreen.swift b/submodules/TelegramUI/Components/VideoMessageCameraScreen/Sources/VideoMessageCameraScreen.swift index cd5491a460..402b226194 100644 --- a/submodules/TelegramUI/Components/VideoMessageCameraScreen/Sources/VideoMessageCameraScreen.swift +++ b/submodules/TelegramUI/Components/VideoMessageCameraScreen/Sources/VideoMessageCameraScreen.swift @@ -331,11 +331,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent { self.updateScreenBrightness(isFlashOn: isFlashOn) if controller.cameraState.position == .back { - if isFlashOn { - camera.setTorchActive(true) - } else { - camera.setTorchActive(false) - } + camera.setTorchActive(isFlashOn) } } From ecd3d87629352dc71654b435d8b646cdb00e4e49 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 23 Aug 2024 02:21:18 +0400 Subject: [PATCH 2/2] Various fixes --- .../PeerInfoScreen/Sources/PeerInfoScreen.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift index 41a613f8f5..2e78c65586 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift @@ -5962,6 +5962,20 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro }))) } + var addedPrivacy = false + if let privacyPolicyUrl = (data.cachedData as? CachedUserData)?.botInfo?.privacyPolicyUrl { + items.append(.action(ContextMenuActionItem(text: presentationData.strings.UserInfo_BotPrivacy, icon: { theme in + generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Info"), color: theme.contextMenu.primaryColor) + }, action: { [weak self] _, f in + f(.dismissWithoutContent) + + guard let self else { + return + } + self.context.sharedContext.openExternalUrl(context: self.context, urlContext: .generic, url: privacyPolicyUrl, forceExternal: false, presentationData: self.presentationData, navigationController: self.controller?.navigationController as? NavigationController, dismissInput: {}) + }))) + addedPrivacy = true + } if let cachedData = data.cachedData as? CachedUserData, let botInfo = cachedData.botInfo { for command in botInfo.commands { if command.text == "settings" { @@ -5978,7 +5992,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro f(.dismissWithoutContent) self?.performBotCommand(command: .help) }))) - } else if command.text == "privacy" { + } else if command.text == "privacy" && !addedPrivacy { items.append(.action(ContextMenuActionItem(text: presentationData.strings.UserInfo_BotPrivacy, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Info"), color: theme.contextMenu.primaryColor) }, action: { [weak self] _, f in