Skip to content

Commit

Permalink
Merge commit 'd4408c2bb03d9ae43afc9755d0e9835f978e011c'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Aug 11, 2023
2 parents cdd58e0 + d4408c2 commit 3e2896e
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 113 deletions.
2 changes: 1 addition & 1 deletion submodules/AccountContext/Sources/AccountContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public protocol SharedAccountContext: AnyObject {

func makeMediaPickerScreen(context: AccountContext, hasSearch: Bool, completion: @escaping (Any) -> Void) -> ViewController

func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void) -> ViewController
func makeStoryMediaPickerScreen(context: AccountContext, getSourceRect: @escaping () -> CGRect, completion: @escaping (Any, UIView, CGRect, UIImage?, @escaping (Bool?) -> (UIView, CGRect)?, @escaping () -> Void) -> Void, dismissed: @escaping () -> Void, groupsPresented: @escaping () -> Void) -> ViewController

func makeProxySettingsController(sharedContext: SharedAccountContext, account: UnauthorizedAccount) -> ViewController

Expand Down
15 changes: 13 additions & 2 deletions submodules/LocationResources/Sources/VenueIconResources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public struct VenueIconArguments: TransformImageCustomArguments {
}

public func venueIcon(engine: TelegramEngine, type: String, flag: String? = nil, background: Bool) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> {
let isBuiltinIcon = ["", "home", "work"].contains(type)
let isBuiltinIcon = ["", "home", "work"].contains(type) || flag != nil
let data: Signal<Data?, NoError> = isBuiltinIcon ? .single(nil) : venueIconData(engine: engine, resource: VenueIconResource(type: type))
return data |> map { data in
return { arguments in
Expand Down Expand Up @@ -164,7 +164,18 @@ public func venueIcon(engine: TelegramEngine, type: String, flag: String? = nil,
c.fillEllipse(in: CGRect(origin: CGPoint(), size: arguments.drawingRect.size))
}
let boundsSize = CGSize(width: arguments.drawingRect.size.width - 4.0 * 2.0, height: arguments.drawingRect.size.height - 4.0 * 2.0)
if let image = iconImage, let cgImage = generateTintedImage(image: image, color: foregroundColor)?.cgImage {
if let flag {
let attributedString = NSAttributedString(string: flag, attributes: [NSAttributedString.Key.font: Font.regular(22.0), NSAttributedString.Key.foregroundColor: UIColor.white])

let line = CTLineCreateWithAttributedString(attributedString)
let lineBounds = CTLineGetBoundsWithOptions(line, .useGlyphPathBounds)

let bounds = CGRect(origin: .zero, size: boundsSize)
let lineOrigin = CGPoint(x: floorToScreenPixels((bounds.size.width - lineBounds.size.width) / 2.0), y: floorToScreenPixels((bounds.size.height - lineBounds.size.height) / 2.0))

c.translateBy(x: lineOrigin.x + 3.0, y: lineOrigin.y + 7.0)
CTLineDraw(line, c)
} else if let image = iconImage, let cgImage = generateTintedImage(image: image, color: foregroundColor)?.cgImage {
let fittedSize = image.size.aspectFitted(boundsSize)
c.draw(cgImage, in: CGRect(origin: CGPoint(x: floor((arguments.drawingRect.width - fittedSize.width) / 2.0), y: floor((arguments.drawingRect.height - fittedSize.height) / 2.0)), size: fittedSize))
} else if isBuiltinIcon {
Expand Down
44 changes: 29 additions & 15 deletions submodules/LocationUI/Sources/LocationActionListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,22 +268,36 @@ final class LocationActionListItemNode: ListViewItemNode {
var arguments: TransformImageCustomArguments?
if let updatedIcon = updatedIcon {
switch updatedIcon {
case .location:
strongSelf.iconNode.isHidden = false
strongSelf.venueIconNode.isHidden = true
strongSelf.iconNode.image = generateLocationIcon(theme: item.presentationData.theme)
case .liveLocation, .stopLiveLocation:
strongSelf.iconNode.isHidden = false
strongSelf.venueIconNode.isHidden = true
strongSelf.iconNode.image = generateLiveLocationIcon(theme: item.presentationData.theme, stop: updatedIcon == .stopLiveLocation)
case let .venue(venue):
strongSelf.iconNode.isHidden = true
strongSelf.venueIconNode.isHidden = false
strongSelf.venueIconNode.setSignal(venueIcon(engine: item.engine, type: venue.venue?.type ?? "", background: true))

if venue.venue?.id == "city" {
arguments = VenueIconArguments(defaultBackgroundColor: item.presentationData.theme.chat.inputPanel.actionControlFillColor, defaultForegroundColor: .white)
case .location:
strongSelf.iconNode.isHidden = false
strongSelf.venueIconNode.isHidden = true
strongSelf.iconNode.image = generateLocationIcon(theme: item.presentationData.theme)
case .liveLocation, .stopLiveLocation:
strongSelf.iconNode.isHidden = false
strongSelf.venueIconNode.isHidden = true
strongSelf.iconNode.image = generateLiveLocationIcon(theme: item.presentationData.theme, stop: updatedIcon == .stopLiveLocation)
case let .venue(venue):
strongSelf.iconNode.isHidden = true
strongSelf.venueIconNode.isHidden = false

func flagEmoji(countryCode: String) -> String {
let base : UInt32 = 127397
var flagString = ""
for v in countryCode.uppercased().unicodeScalars {
flagString.unicodeScalars.append(UnicodeScalar(base + v.value)!)
}
return flagString
}
let type = venue.venue?.type
var flag: String?
if let venue = venue.venue, venue.provider == "city", let countryCode = venue.id {
flag = flagEmoji(countryCode: countryCode)
}

if venue.venue?.provider == "city" {
arguments = VenueIconArguments(defaultBackgroundColor: item.presentationData.theme.chat.inputPanel.actionControlFillColor, defaultForegroundColor: .white)
}
strongSelf.venueIconNode.setSignal(venueIcon(engine: item.engine, type: type ?? "", flag: flag, background: true))
}

if updatedIcon == .stopLiveLocation {
Expand Down
16 changes: 12 additions & 4 deletions submodules/LocationUI/Sources/LocationPickerControllerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private enum LocationPickerEntry: Comparable, Identifiable {
case let .city(_, title, subtitle, _, _, _, coordinate, name, countryCode):
let icon: LocationActionListItemIcon
if let name {
icon = .venue(TelegramMediaMap(latitude: 0, longitude: 0, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: MapVenue(title: name, address: "City", provider: nil, id: "city", type: "building/default"), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil))
icon = .venue(TelegramMediaMap(latitude: 0, longitude: 0, heading: nil, accuracyRadius: nil, geoPlace: nil, venue: MapVenue(title: name, address: presentationData.strings.Location_TypeCity, provider: "city", id: countryCode, type: "building/default"), liveBroadcastingTimeout: nil, liveProximityNotificationRadius: nil))
} else {
icon = .location
}
Expand Down Expand Up @@ -583,20 +583,28 @@ final class LocationPickerControllerNode: ViewControllerTracingNode, CLLocationM
switch strongSelf.mode {
case .share:
if source == .story {
title = "Add This Location"
title = presentationData.strings.Location_AddThisLocation
} else {
title = presentationData.strings.Map_SendThisLocation
}
case .pick:
title = presentationData.strings.Map_SetThisLocation
}
entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, state.countryCode, true))
if source == .story {
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, nil, false))
} else 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.countryCode))
}
} else {
entries.append(.location(presentationData.theme, title, address ?? presentationData.strings.Map_Locating, nil, nil, nil, coordinate, state.street, nil, true))
}
case .selecting:
let title: String
switch strongSelf.mode {
case .share:
if source == .story {
title = "Add This Location"
title = presentationData.strings.Location_AddThisLocation
} else {
title = presentationData.strings.Map_SendThisLocation
}
Expand Down
4 changes: 4 additions & 0 deletions submodules/MediaPickerUI/Sources/MediaPickerGridItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ final class MediaPickerGridItemNode: GridItemNode {

self.progressDisposable.set(nil)
self.updateProgress(nil, animated: false)

self.backgroundNode.image = nil
self.imageNode.contentMode = .scaleAspectFill
}

if self.draftNode.supernode == nil {
Expand Down Expand Up @@ -403,6 +406,7 @@ final class MediaPickerGridItemNode: GridItemNode {
if asset.localIdentifier == self.currentAsset?.localIdentifier {
return
}
self.backgroundNode.image = nil

self.progressDisposable.set(
(interaction.downloadManager.downloadProgress(identifier: asset.localIdentifier)
Expand Down
Loading

0 comments on commit 3e2896e

Please sign in to comment.