This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public protocol Copyable { | |
| init(other: Self) | |
| } | |
| public extension Copyable { | |
| public func copy() -> Self { | |
| return Self.init(other: self) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIImage { | |
| static func roundedTextAvatar(text: String?, | |
| color: UIColor, | |
| circular: Bool, | |
| textAttributes: [NSAttributedStringKey: Any]?, | |
| size: CGSize) -> UIImage? { | |
| let scale = Float(UIScreen.main.scale) | |
| UIGraphicsBeginImageContextWithOptions(size, false, CGFloat(scale)) | |
| let context = UIGraphicsGetCurrentContext() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| public var initials: String { | |
| var finalString = String() | |
| var words = components(separatedBy: .whitespacesAndNewlines) | |
| if let firstCharacter = words.first?.first { | |
| finalString.append(String(firstCharacter)) | |
| words.removeFirst() | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protocol ChatsService { | |
| func getChats(request: GetConversationsRequest) throws -> [Message] | |
| func getChatMessages(request: GetConversationMessagesRequest) throws -> [Message] | |
| func submitMessage(request: SubmitMessageRequest) throws -> Message | |
| func getUnreadMessagesNumber() throws -> Int | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RemoteChatsProvider: ChatsProvider { | |
| func getChats(request: GetConversationsRequest) throws -> [Message] { | |
| var items: [MessageDto] = [] | |
| var outputError: Error? = nil | |
| let dispatchGroup = DispatchGroup() | |
| dispatchGroup.enter() | |
| CompanyMessagesAPI.companyMessagesGetConversations(request: request, completion: { (successfulResponse, error) in | |
| do { | |
| items = try SwaggerApiResponseHandler.unwrapResponse((successfulResponse, error)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension SwaggerClientAPI { | |
| private enum HeadersKeys: String { | |
| case authorization = "Authorization" | |
| } | |
| class func setBearer(_ token: String) { | |
| SwaggerClientAPI.customHeaders = [HeadersKeys.authorization.rawValue: "Bearer \(token)"] | |
| } | |
| class func clearBearer() { | |
| SwaggerClientAPI.customHeaders.removeValue(forKey: HeadersKeys.authorization.rawValue) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ConversationsListInteractor: ConversationsListInteractorInput { | |
| let chatsProvider: ChatsService = Assembler.container.resolve(ChatsProvider.self)! | |
| weak var output: ConversationsListInteractorOutput? | |
| // MARK: - Input | |
| func requestItems(request: ConversationsList.DataContext.Request) { | |
| DispatchQueue(label: "ConversationsListInteractor").async { | |
| do { | |
| let items = try self.chatsProvider.getChats(request: GetConversationsRequest(skip: request.skip, take: request.take)) | |
| let models = items.map({ ConversationsListModel(currentModel: $0) }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if let data = self.currentModel.imageData { | |
| view.avatarImage.image = UIImage(data: data) | |
| } else { | |
| view.avatarImage.setImage(string: currentModel.username, color: UIColor.gray, circular: true, textAttributes: nil) | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let gradientView = UIView(frame: CGRect(x: 0, y: self.textLabel.frame.maxY - 100, width: 375, height: 100)) | |
| self.view.addSubview(gradientView) | |
| let gradientLayer: CAGradientLayer = CAGradientLayer() | |
| gradientLayer.frame = gradientView.bounds | |
| // colors of your overlay. [0] - start color, [1] - end color | |
| gradientLayer.colors = [UIColor(white: 1, alpha: 0.95).cgColor, UIColor(white: 1, alpha: 0.6).cgColor] | |
| gradientLayer.startPoint = CGPoint(x: 0, y: 0) | |
| gradientLayer.endPoint = CGPoint(x: 0, y: 1) | |
| gradientView.layer.addSublayer(gradientLayer) | |
| // rotate view 180 degrees |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gradientLayer.startPoint = CGPoint(x: 0, y: 0) | |
| gradientLayer.endPoint = CGPoint(x: 0, y: 1) |
OlderNewer