Various fixes

This commit is contained in:
Ilya Laktyushin 2023-08-01 16:13:33 +02:00
parent e4e34381fe
commit a628f1a293
6 changed files with 56 additions and 24 deletions

View File

@ -70,7 +70,7 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg
self.textView.keyboardAppearance = .dark self.textView.keyboardAppearance = .dark
self.textView.autocorrectionType = .default self.textView.autocorrectionType = .default
self.textView.spellCheckingType = .no self.textView.spellCheckingType = .no
self.textView.textContainer.maximumNumberOfLines = 1 self.textView.textContainer.maximumNumberOfLines = 2
self.textView.textContainer.lineBreakMode = .byTruncatingTail self.textView.textContainer.lineBreakMode = .byTruncatingTail
self.iconView = UIImageView() self.iconView = UIImageView()
@ -111,7 +111,7 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
let iconSize = floor(self.bounds.height * 0.6) let iconSize = min(76.0, floor(self.bounds.height * 0.6))
self.iconView.frame = CGRect(origin: CGPoint(x: floor(iconSize * 0.2), y: floorToScreenPixels((self.bounds.height - iconSize) / 2.0)), size: CGSize(width: iconSize, height: iconSize)) self.iconView.frame = CGRect(origin: CGPoint(x: floor(iconSize * 0.2), y: floorToScreenPixels((self.bounds.height - iconSize) / 2.0)), size: CGSize(width: iconSize, height: iconSize))
self.textView.frame = CGRect(origin: CGPoint(x: self.bounds.width - self.textSize.width, y: floorToScreenPixels((self.bounds.height - self.textSize.height) / 2.0)), size: self.textSize) self.textView.frame = CGRect(origin: CGPoint(x: self.bounds.width - self.textSize.width, y: floorToScreenPixels((self.bounds.height - self.textSize.height) / 2.0)), size: self.textSize)
self.backgroundView.frame = self.bounds self.backgroundView.frame = self.bounds
@ -165,7 +165,7 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg
self.textView.font = font self.textView.font = font
let paragraphStyle = NSMutableParagraphStyle() let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .right paragraphStyle.alignment = .left
text.addAttribute(.paragraphStyle, value: paragraphStyle, range: range) text.addAttribute(.paragraphStyle, value: paragraphStyle, range: range)
let textColor: UIColor let textColor: UIColor
@ -202,7 +202,7 @@ public final class DrawingLocationEntityView: DrawingEntityView, UITextViewDeleg
self.textView.textColor = .white self.textView.textColor = .white
self.backgroundView.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.2) self.backgroundView.backgroundColor = UIColor(rgb: 0x000000, alpha: 0.2)
} }
self.textView.textAlignment = .right self.textView.textAlignment = .left
self.updateText() self.updateText()

View File

@ -342,7 +342,7 @@ final class LocationInfoListItemNode: ListViewItemNode {
shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0)) shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0))
shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing + directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0)) shapes.append(.roundedRectLine(startPoint: CGPoint(x: directionsWidth + directionsSpacing + directionsWidth + directionsSpacing, y: 0.0), width: directionsWidth, diameter: 32.0))
shimmerNode.update(backgroundColor: item.presentationData.theme.list.itemBlocksBackgroundColor, foregroundColor: item.presentationData.theme.list.mediaPlaceholderColor, shimmeringColor: item.presentationData.theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: shapes, size: shimmerNode.frame.size) shimmerNode.update(backgroundColor: item.presentationData.theme.list.plainBackgroundColor, foregroundColor: item.presentationData.theme.list.mediaPlaceholderColor, shimmeringColor: item.presentationData.theme.list.itemBlocksBackgroundColor.withAlphaComponent(0.4), shapes: shapes, size: shimmerNode.frame.size)
} else if let shimmerNode = strongSelf.placeholderNode { } else if let shimmerNode = strongSelf.placeholderNode {
strongSelf.placeholderNode = nil strongSelf.placeholderNode = nil
shimmerNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak shimmerNode] _ in shimmerNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak shimmerNode] _ in

View File

@ -37,7 +37,7 @@ private enum LocationPickerEntryId: Hashable {
private enum LocationPickerEntry: Comparable, Identifiable { private enum LocationPickerEntry: Comparable, Identifiable {
case city(PresentationTheme, String, String, TelegramMediaMap?, Int64?, String?, CLLocationCoordinate2D?, String?) case city(PresentationTheme, String, String, TelegramMediaMap?, Int64?, String?, CLLocationCoordinate2D?, String?)
case location(PresentationTheme, String, String, TelegramMediaMap?, Int64?, String?, CLLocationCoordinate2D?, String?) case location(PresentationTheme, String, String, TelegramMediaMap?, Int64?, String?, CLLocationCoordinate2D?, String?, Bool)
case liveLocation(PresentationTheme, String, String, CLLocationCoordinate2D?) case liveLocation(PresentationTheme, String, String, CLLocationCoordinate2D?)
case header(PresentationTheme, String) case header(PresentationTheme, String)
case venue(PresentationTheme, TelegramMediaMap?, Int64?, String?, Int) case venue(PresentationTheme, TelegramMediaMap?, Int64?, String?, Int)
@ -68,8 +68,8 @@ private enum LocationPickerEntry: Comparable, Identifiable {
} else { } else {
return false return false
} }
case let .location(lhsTheme, lhsTitle, lhsSubtitle, lhsVenue, lhsQueryId, lhsResultId, lhsCoordinate, lhsName): case let .location(lhsTheme, lhsTitle, lhsSubtitle, lhsVenue, lhsQueryId, lhsResultId, lhsCoordinate, lhsName, lhsIsTop):
if case let .location(rhsTheme, rhsTitle, rhsSubtitle, rhsVenue, rhsQueryId, rhsResultId, rhsCoordinate, rhsName) = rhs, lhsTheme === rhsTheme, lhsTitle == rhsTitle, lhsSubtitle == rhsSubtitle, lhsVenue?.venue?.id == rhsVenue?.venue?.id, lhsQueryId == rhsQueryId && lhsResultId == rhsResultId, lhsCoordinate == rhsCoordinate, lhsName == rhsName { if case let .location(rhsTheme, rhsTitle, rhsSubtitle, rhsVenue, rhsQueryId, rhsResultId, rhsCoordinate, rhsName, rhsIsTop) = rhs, lhsTheme === rhsTheme, lhsTitle == rhsTitle, lhsSubtitle == rhsSubtitle, lhsVenue?.venue?.id == rhsVenue?.venue?.id, lhsQueryId == rhsQueryId && lhsResultId == rhsResultId, lhsCoordinate == rhsCoordinate, lhsName == rhsName, lhsIsTop == rhsIsTop {
return true return true
} else { } else {
return false return false
@ -161,7 +161,7 @@ private enum LocationPickerEntry: Comparable, Identifiable {
}, highlighted: { highlighted in }, highlighted: { highlighted in
interaction?.updateSendActionHighlight(highlighted) interaction?.updateSendActionHighlight(highlighted)
}) })
case let .location(_, title, subtitle, venue, queryId, resultId, coordinate, name): case let .location(_, title, subtitle, venue, queryId, resultId, coordinate, name, isTop):
let icon: LocationActionListItemIcon let icon: LocationActionListItemIcon
if let venue = venue { if let venue = venue {
icon = .venue(venue) icon = .venue(venue)
@ -175,7 +175,9 @@ private enum LocationPickerEntry: Comparable, Identifiable {
interaction?.sendLocation(coordinate, name) interaction?.sendLocation(coordinate, name)
} }
}, highlighted: { highlighted in }, highlighted: { highlighted in
interaction?.updateSendActionHighlight(highlighted) if isTop {
interaction?.updateSendActionHighlight(highlighted)
}
}) })
case let .liveLocation(_, title, subtitle, coordinate): case let .liveLocation(_, title, subtitle, coordinate):
return LocationActionListItem(presentationData: ItemListPresentationData(presentationData), engine: engine, title: title, subtitle: subtitle, icon: .liveLocation, beginTimeAndTimeout: nil, action: { return LocationActionListItem(presentationData: ItemListPresentationData(presentationData), engine: engine, title: title, subtitle: subtitle, icon: .liveLocation, beginTimeAndTimeout: nil, action: {
@ -585,7 +587,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
case .pick: case .pick:
title = presentationData.strings.Map_SetThisLocation title = presentationData.strings.Map_SetThisLocation
} }
entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street)) entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, true))
case .selecting: case .selecting:
let title: String let title: String
switch strongSelf.mode { switch strongSelf.mode {
@ -598,7 +600,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
case .pick: case .pick:
title = presentationData.strings.Map_SetThisLocation title = presentationData.strings.Map_SetThisLocation
} }
entries.append(.location(presentationData.theme, title, presentationData.strings.Map_Locating, nil, nil, nil, nil, nil)) entries.append(.location(presentationData.theme, title, presentationData.strings.Map_Locating, nil, nil, nil, nil, nil, true))
case let .venue(venue, queryId, resultId): case let .venue(venue, queryId, resultId):
let title: String let title: String
switch strongSelf.mode { switch strongSelf.mode {
@ -607,7 +609,7 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
case .pick: case .pick:
title = presentationData.strings.Map_SetThisPlace title = presentationData.strings.Map_SetThisPlace
} }
entries.append(.location(presentationData.theme, title, venue.venue?.title ?? "", venue, queryId, resultId, venue.coordinate, nil)) entries.append(.location(presentationData.theme, title, venue.venue?.title ?? "", venue, queryId, resultId, venue.coordinate, nil, true))
case .none: case .none:
let title: String let title: String
var coordinate = userLocation?.coordinate var coordinate = userLocation?.coordinate
@ -627,10 +629,14 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
title = presentationData.strings.Map_SetThisLocation title = presentationData.strings.Map_SetThisLocation
} }
if source == .story { if source == .story {
entries.append(.city(presentationData.theme, state.city ?? presentationData.strings.Map_Locating, "City", nil, nil, nil, coordinate, state.city)) if state.city != "" {
entries.append(.location(presentationData.theme, state.street ?? presentationData.strings.Map_Locating, "Street", nil, nil, nil, coordinate, state.street)) entries.append(.city(presentationData.theme, state.city ?? presentationData.strings.Map_Locating, "City", nil, nil, nil, coordinate, state.city))
}
if state.street != "" {
entries.append(.location(presentationData.theme, state.street ?? presentationData.strings.Map_Locating, "Street", nil, nil, nil, coordinate, state.street, false))
}
} else { } else {
entries.append(.location(presentationData.theme, title, (userLocation?.horizontalAccuracy).flatMap { presentationData.strings.Map_AccurateTo(stringForDistance(strings: presentationData.strings, distance: $0)).string } ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street)) entries.append(.location(presentationData.theme, title, (userLocation?.horizontalAccuracy).flatMap { presentationData.strings.Map_AccurateTo(stringForDistance(strings: presentationData.strings, distance: $0)).string } ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, true))
} }
} }
@ -781,9 +787,20 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
var streetName: String? var streetName: String?
if let city = placemark?.city, let country = placemark?.country { if let city = placemark?.city, let country = placemark?.country {
cityName = "\(city), \(country)" cityName = "\(city), \(country)"
} else {
cityName = ""
} }
if let street = placemark?.street, let city = placemark?.city { if let street = placemark?.street {
streetName = "\(street), \(city)" if let city = placemark?.city {
streetName = "\(street), \(city)"
} else {
streetName = street
}
} else {
streetName = ""
}
if streetName == "" && cityName == "" {
streetName = "Location"
} }
strongSelf.updateState { state in strongSelf.updateState { state in
var state = state var state = state
@ -808,9 +825,20 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
var streetName: String? var streetName: String?
if let city = placemark?.city, let country = placemark?.country { if let city = placemark?.city, let country = placemark?.country {
cityName = "\(city), \(country)" cityName = "\(city), \(country)"
} else {
cityName = ""
} }
if let street = placemark?.street, let city = placemark?.city { if let street = placemark?.street {
streetName = "\(street), \(city)" if let city = placemark?.city {
streetName = "\(street), \(city)"
} else {
streetName = street
}
} else {
streetName = ""
}
if streetName == "" && cityName == "" {
streetName = "Location"
} }
strongSelf.updateState { state in strongSelf.updateState { state in
var state = state var state = state

View File

@ -804,7 +804,7 @@ public final class StoryItemSetContainerComponent: Component {
let rotatedX = tx * cosTheta - ty * sinTheta let rotatedX = tx * cosTheta - ty * sinTheta
let rotatedY = tx * sinTheta + ty * cosTheta let rotatedY = tx * sinTheta + ty * cosTheta
return abs(rotatedX) <= area.coordinates.width / 100.0 * referenceSize.width / 2.0 && abs(rotatedY) <= area.coordinates.height / 100.0 * referenceSize.height / 2.0 return abs(rotatedX) <= area.coordinates.width / 100.0 * referenceSize.width / 2.0 * 1.1 && abs(rotatedY) <= area.coordinates.height / 100.0 * referenceSize.height / 2.0 * 1.1
} }
for area in component.slice.item.storyItem.mediaAreas { for area in component.slice.item.storyItem.mediaAreas {

View File

@ -90,7 +90,7 @@ private struct LanguageSelectionControllerState: Equatable {
var toLanguage: String var toLanguage: String
} }
public func languageSelectionController(context: AccountContext, fromLanguage: String, toLanguage: String, completion: @escaping (String, String) -> Void) -> ViewController { public func languageSelectionController(context: AccountContext, forceTheme: PresentationTheme? = nil, fromLanguage: String, toLanguage: String, completion: @escaping (String, String) -> Void) -> ViewController {
let statePromise = ValuePromise(LanguageSelectionControllerState(section: .translation, fromLanguage: fromLanguage, toLanguage: toLanguage), ignoreRepeated: true) let statePromise = ValuePromise(LanguageSelectionControllerState(section: .translation, fromLanguage: fromLanguage, toLanguage: toLanguage), ignoreRepeated: true)
let stateValue = Atomic(value: LanguageSelectionControllerState(section: .translation, fromLanguage: fromLanguage, toLanguage: toLanguage)) let stateValue = Atomic(value: LanguageSelectionControllerState(section: .translation, fromLanguage: fromLanguage, toLanguage: toLanguage))
let updateState: ((LanguageSelectionControllerState) -> LanguageSelectionControllerState) -> Void = { f in let updateState: ((LanguageSelectionControllerState) -> LanguageSelectionControllerState) -> Void = { f in
@ -149,6 +149,10 @@ public func languageSelectionController(context: AccountContext, fromLanguage: S
let signal = combineLatest(queue: Queue.mainQueue(), context.sharedContext.presentationData, statePromise.get()) let signal = combineLatest(queue: Queue.mainQueue(), context.sharedContext.presentationData, statePromise.get())
|> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState, Any)) in |> map { presentationData, state -> (ItemListControllerState, (ItemListNodeState, Any)) in
var presentationData = presentationData
if let forceTheme {
presentationData = presentationData.withUpdated(theme: forceTheme)
}
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .sectionControl([presentationData.strings.Translate_Languages_Original, presentationData.strings.Translate_Languages_Translation], 1), leftNavigationButton: ItemListNavigationButton(content: .none, style: .regular, enabled: false, action: {}), rightNavigationButton: ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: true, action: { let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .sectionControl([presentationData.strings.Translate_Languages_Original, presentationData.strings.Translate_Languages_Translation], 1), leftNavigationButton: ItemListNavigationButton(content: .none, style: .regular, enabled: false, action: {}), rightNavigationButton: ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: true, action: {
completion(state.fromLanguage, state.toLanguage) completion(state.fromLanguage, state.toLanguage)
dismissImpl?() dismissImpl?()

View File

@ -1043,8 +1043,8 @@ public class TranslateScreen: ViewController {
changeLanguageImpl = { [weak self] fromLang, toLang, completion in changeLanguageImpl = { [weak self] fromLang, toLang, completion in
let pushController = self?.pushController let pushController = self?.pushController
let presentController = self?.presentController let presentController = self?.presentController
let controller = languageSelectionController(context: context, fromLanguage: fromLang, toLanguage: toLang, completion: { fromLang, toLang in let controller = languageSelectionController(context: context, forceTheme: forceTheme, fromLanguage: fromLang, toLanguage: toLang, completion: { fromLang, toLang in
let controller = TranslateScreen(context: context, text: text, canCopy: canCopy, fromLanguage: fromLang, toLanguage: toLang, isExpanded: true) let controller = TranslateScreen(context: context, forceTheme: forceTheme, text: text, canCopy: canCopy, fromLanguage: fromLang, toLanguage: toLang, isExpanded: true)
controller.pushController = pushController ?? { _ in } controller.pushController = pushController ?? { _ in }
controller.presentController = presentController ?? { _ in } controller.presentController = presentController ?? { _ in }
presentController?(controller) presentController?(controller)