Commit eb4a2d48 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

project: support iOS 12.2

Support iOS 12.2 and convert to swift5 syntax.
Also this patch removes framework Chameleon.

Change-Id: I4135c87b14c9c04dff86c3e7eede33162bb8ca34
parent 630f63c3
......@@ -3,7 +3,6 @@ github "RxSwiftCommunity/RxDataSources" ~> 3.0
github "pkluz/PKHUD" ~> 5.0
github "AliSoftware/Reusable" ~> 4.0
github "SwiftyBeaver/SwiftyBeaver" ~> 1.0
github "ViccAlexander/Chameleon"
github "andreamazz/AMPopTip"
github "ashleymills/Reachability.swift"
github "stephencelis/SQLite.swift" ~> 0.11.4
......
github "AliSoftware/Reusable" "4.0.4"
github "ReactiveX/RxSwift" "4.4.0"
github "AliSoftware/Reusable" "4.1.0"
github "ReactiveX/RxSwift" "4.5.0"
github "RxSwiftCommunity/RxDataSources" "3.1.0"
github "RxSwiftCommunity/RxRealm" "0.7.6"
github "SwiftyBeaver/SwiftyBeaver" "1.6.1"
github "ViccAlexander/Chameleon" "2.2.0"
github "andreamazz/AMPopTip" "3.5.0"
github "ashleymills/Reachability.swift" "v4.3.0"
github "RxSwiftCommunity/RxRealm" "0.7.7"
github "SwiftyBeaver/SwiftyBeaver" "1.7.0"
github "andreamazz/AMPopTip" "4.0.1"
github "ashleymills/Reachability.swift" "v4.3.1"
github "gskbyte/GSKStretchyHeaderView" "1.0.4"
github "optonaut/ActiveLabel.swift" "1.0.1"
github "pkluz/PKHUD" "5.2.0"
github "realm/realm-cocoa" "v3.12.0"
github "stephencelis/SQLite.swift" "0.11.5"
github "pkluz/PKHUD" "5.3.0"
github "realm/realm-cocoa" "v3.16.1"
github "stephencelis/SQLite.swift" "0.11.6"
This diff is collapsed.
......@@ -24,8 +24,6 @@
import UIKit
import SwiftyBeaver
import RxSwift
import Chameleon
//import Contacts
import PushKit
import ContactsUI
......@@ -90,7 +88,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
fileprivate let disposeBag = DisposeBag()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// ignore sigpipe
// swiftlint:disable nesting
......@@ -131,9 +129,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
})
.disposed(by: self.disposeBag)
// themetize the app
Chameleon.setRingThemeUsingPrimaryColor(UIColor.jamiMain, withSecondaryColor: UIColor.jamiSecondary, andContentStyle: .light)
self.interactionsManager = GeneratedInteractionsManager(accountService: self.accountService,
contactService: self.contactsService,
conversationService: self.conversationsService,
......@@ -278,6 +273,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
if !enabled { LocalNotificationsHelper.setNotification(enable: true)}
case .provisional:
if !enabled { LocalNotificationsHelper.setNotification(enable: true)}
@unknown default:
break
}
})
} else {
......
......@@ -30,13 +30,11 @@
#import "RegistrationResponse.h"
#import "NameRegistrationResponse.h"
#import "MessagesAdapter.h"
#import "Chameleon/Chameleon.h"
#import "ContactsAdapter.h"
#import "PresenceAdapter.h"
#import "VideoAdapter.h"
#import "AudioAdapter.h"
#import <CommonCrypto/CommonCrypto.h>
//#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
#import <UserNotifications/UserNotifications.h>
#import "CallsAdapter.h"
......
......@@ -18,8 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "Chameleon/Chameleon-Swift.h"
#import "Ring-Swift.h"
#import "SystemAdapter.h"
......
......@@ -21,7 +21,6 @@
*/
import UIKit
import Chameleon
import RxSwift
import Reusable
import SwiftyBeaver
......@@ -127,8 +126,8 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
@objc func capturedVideoSwipped(gesture: UISwipeGestureRecognizer) {
if self.avatarView.isHidden == false { return }
if gesture.direction == UISwipeGestureRecognizerDirection.left && (self.isVideoHidden == false) { return }
if gesture.direction == UISwipeGestureRecognizerDirection.right && (self.isVideoHidden == true) { return }
if gesture.direction == UISwipeGestureRecognizer.Direction.left && (self.isVideoHidden == false) { return }
if gesture.direction == UISwipeGestureRecognizer.Direction.right && (self.isVideoHidden == true) { return }
self.hideCapturedVideo()
}
......@@ -174,7 +173,7 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
}
func setUpCallButtons() {
self.mainView.bringSubview(toFront: self.buttonsContainer)
self.mainView.bringSubviewToFront(self.buttonsContainer)
self.buttonsContainer.viewModel = self.viewModel.containerViewModel
self.buttonsContainer.cancelButton.rx.tap
.subscribe(onNext: { [weak self] in
......@@ -183,9 +182,10 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
}).disposed(by: self.disposeBag)
self.buttonsContainer.acceptCallButton.rx.tap
.subscribe(onNext: { [weak self] in
self?.viewModel.answerCall()
.subscribe(onNext: { [unowned self] in
self.viewModel.answerCall()
.subscribe()
.disposed(by: self.disposeBag)
}).disposed(by: self.disposeBag)
self.buttonsContainer.dialpadButton.rx.tap
......
......@@ -105,6 +105,8 @@ enum InteractionStatus: String {
case .sent: self = .succeed
case .read: self = .read
case .failure: self = .failed
@unknown default:
self = .unknown
}
}
......
......@@ -80,15 +80,15 @@ class EditProfileViewController: UIViewController, UITextFieldDelegate, UIImageP
message: nil,
preferredStyle: .actionSheet)
let cameraAction = UIAlertAction(title: L10n.Alerts.profileTakePhoto, style: UIAlertActionStyle.default) { _ in
let cameraAction = UIAlertAction(title: L10n.Alerts.profileTakePhoto, style: UIAlertAction.Style.default) { _ in
self.takePicture()
}
let pictureAction = UIAlertAction(title: L10n.Alerts.profileUploadPhoto, style: UIAlertActionStyle.default) { _ in
let pictureAction = UIAlertAction(title: L10n.Alerts.profileUploadPhoto, style: UIAlertAction.Style.default) { _ in
self.importPicture()
}
let cancelAction = UIAlertAction(title: L10n.Alerts.profileCancelPhoto, style: UIAlertActionStyle.cancel)
let cancelAction = UIAlertAction(title: L10n.Alerts.profileCancelPhoto, style: UIAlertAction.Style.cancel)
alert.addAction(cameraAction)
alert.addAction(pictureAction)
......@@ -100,11 +100,11 @@ class EditProfileViewController: UIViewController, UITextFieldDelegate, UIImageP
}
func takePicture() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.front
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.cameraDevice = UIImagePickerController.CameraDevice.front
imagePicker.allowsEditing = true
imagePicker.modalPresentationStyle = .overFullScreen
self.present(imagePicker, animated: true, completion: nil)
......@@ -115,19 +115,20 @@ class EditProfileViewController: UIViewController, UITextFieldDelegate, UIImageP
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
imagePicker.modalPresentationStyle = .overFullScreen
self.present(imagePicker, animated: true, completion: nil)
}
// MARK: - Delegates
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
internal func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
var image: UIImage!
if let img = info[UIImagePickerControllerEditedImage] as? UIImage {
if let img = info[.editedImage] as? UIImage {
image = img
} else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage {
} else if let img = info[.originalImage] as? UIImage {
image = img
}
......
......@@ -92,7 +92,7 @@ class EditProfileViewModel {
guard let account = self.accountService.currentAccount else {return}
var photo: String?
if let image = self.image, !image.isEqual(defaultImage),
let imageData = UIImagePNGRepresentation(image) {
let imageData = image.pngData() {
photo = imageData.base64EncodedString()
}
self.profileService.updateAccountProfile(accountId: account.id,
......
......@@ -63,8 +63,8 @@ extension CNContactVCardSerialization {
}
if let scaledImage = scaledImage {
if UIImagePNGRepresentation(scaledImage) != nil {
image = UIImagePNGRepresentation(scaledImage)!
if scaledImage.pngData() != nil {
image = scaledImage.pngData()!
}
}
......
/*
* Copyright (C) 2017-2019 Savoir-faire Linux Inc.
*
* Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
* Author: Quentin Muret <quentin.muret@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import Foundation
import Chameleon
extension Chameleon {
static func setRingThemeUsingPrimaryColor (_ primaryColor: UIColor, withSecondaryColor secondaryColor: UIColor, andContentStyle contentStyle: UIContentStyle) {
var contentColor: UIColor
var secondaryContentColor: UIColor
switch contentStyle {
case .contrast:
contentColor = ContrastColorOf(primaryColor, returnFlat: false)
secondaryContentColor = ContrastColorOf(secondaryColor, returnFlat: false)
case .light:
contentColor = UIColor.white
secondaryContentColor = UIColor.white
case .dark:
contentColor = UIColor.flatBlackColorDark()
secondaryContentColor = UIColor.flatBlackColorDark()
}
MessageBubble.appearance().tintColor = secondaryContentColor
MessageBubble.appearance().backgroundColor = secondaryColor
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellSent.self]).tintColor = contentColor
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellSent.self]).backgroundColor = UIColor.jamiMsgCellSent
UILabel.appearance(whenContainedInInstancesOf: [MessageBubble.self, MessageCellSent.self]).textColor = UIColor.jamiMsgCellSentText
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellReceived.self]).tintColor = secondaryContentColor
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellReceived.self]).backgroundColor = UIColor.jamiMsgCellReceived
UILabel.appearance(whenContainedInInstancesOf: [MessageBubble.self, MessageCellReceived.self]).textColor = UIColor.jamiMsgCellReceivedText
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellGenerated.self]).tintColor = UIColor.clear
MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellGenerated.self]).backgroundColor = UIColor.clear
}
}
......@@ -25,11 +25,11 @@ extension NotificationCenter {
static var keyboardHeight: Observable<CGFloat> {
return Observable
.from([
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillShow)
NotificationCenter.default.rx.notification(UIResponder.keyboardWillShowNotification)
.map { notification -> CGFloat in
return (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
return (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.height ?? 0
},
NotificationCenter.default.rx.notification(NSNotification.Name.UIKeyboardWillHide)
NotificationCenter.default.rx.notification(UIResponder.keyboardWillHideNotification)
.map { _ -> CGFloat in
0
}
......
......@@ -48,11 +48,14 @@ extension String {
guard let messageData = self.data(using: .utf8) else {return ""}
var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes { digestBytes in
messageData.withUnsafeBytes { messageBytes in
CC_MD5(messageBytes, CC_LONG(messageData.count), digestBytes)
digestData.withUnsafeMutableBytes { (digestBytes: UnsafeMutableRawBufferPointer) -> Void in
messageData.withUnsafeBytes { (messageBytes: UnsafeRawBufferPointer) -> Void in
CC_MD5(messageBytes.baseAddress,
CC_LONG(messageData.count),
digestBytes.bindMemory(to: UInt8.self).baseAddress)
}
}
return digestData.map { String(format: "%02hhx", $0) }.joined()
}
......
......@@ -35,6 +35,44 @@ extension UIColor {
self.init(red: (hex >> 16) & 0xff, green: (hex >> 8) & 0xff, blue: hex & 0xff, alpha: alpha)
}
func lighten(by percentage: CGFloat = 30.0) -> UIColor? {
return self.adjust(by: abs(percentage) )
}
func darker(by percentage: CGFloat) -> UIColor? {
return self.adjust(by: -1 * abs(percentage) )
}
func adjust(by percentage: CGFloat = 30.0) -> UIColor? {
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
if self.getRed(&red, green: &green, blue: &blue, alpha: &alpha) {
return UIColor(red: min(red + percentage/100, 1.0),
green: min(green + percentage/100, 1.0),
blue: min(blue + percentage/100, 1.0),
alpha: alpha)
} else {
return nil
}
}
public convenience init?(hexString: String) {
let hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
let scanner = Scanner(string: hexString)
if hexString.hasPrefix("#") {
scanner.scanLocation = 1
}
var color: UInt32 = 0
scanner.scanHexInt32(&color)
let mask = 0x000000FF
let r = Int(color >> 16) & mask
let g = Int(color >> 8) & mask
let b = Int(color) & mask
let red = CGFloat(r) / 255.0
let green = CGFloat(g) / 255.0
let blue = CGFloat(b) / 255.0
self.init(red: red, green: green, blue: blue, alpha: 1)
}
static let jamiMain = UIColor(hex: 0x3F6DA7, alpha: 1.0)
static let jamiSecondary = UIColor(hex: 0x1F4971, alpha: 1.0)
static let jamiButtonLight = UIColor(hex: 0x285F97, alpha: 1.0)
......
......@@ -83,13 +83,13 @@ extension UIImage {
}
func convertToData(ofMaxSize maxSize: Int) -> Data? {
guard let imageData = UIImageJPEGRepresentation(self, 0.9) else {
guard let imageData = self.jpegData(compressionQuality: 0.9) else {
return nil
}
var fileSize = imageData.count
var i = 10
while fileSize > maxSize && i >= 0 {
guard let imageData = UIImageJPEGRepresentation(self, CGFloat(0.1 * Double(i))) else {
guard let imageData = self.jpegData(compressionQuality: CGFloat(0.1 * Double(i))) else {
return nil
}
fileSize = imageData.count
......@@ -125,10 +125,10 @@ extension UIImage {
newHeight = newWidth / ratio
} else if ratio < 1, ratio != 0 {
// android image orientation bug?
if self.imageOrientation == UIImageOrientation.right ||
self.imageOrientation == UIImageOrientation.left ||
self.imageOrientation == UIImageOrientation.rightMirrored ||
self.imageOrientation == UIImageOrientation.leftMirrored {
if self.imageOrientation == UIImage.Orientation.right ||
self.imageOrientation == UIImage.Orientation.left ||
self.imageOrientation == UIImage.Orientation.rightMirrored ||
self.imageOrientation == UIImage.Orientation.leftMirrored {
newHeight *= ratio
} else {
newWidth = newHeight * ratio
......@@ -172,10 +172,10 @@ extension UIImage {
newHeight = newWidth / ratio
} else if ratio < 1, ratio != 0 {
// android image orientation bug?
if self.imageOrientation == UIImageOrientation.right ||
self.imageOrientation == UIImageOrientation.left ||
self.imageOrientation == UIImageOrientation.rightMirrored ||
self.imageOrientation == UIImageOrientation.leftMirrored {
if self.imageOrientation == UIImage.Orientation.right ||
self.imageOrientation == UIImage.Orientation.left ||
self.imageOrientation == UIImage.Orientation.rightMirrored ||
self.imageOrientation == UIImage.Orientation.leftMirrored {
newHeight *= ratio
} else {
newWidth = newHeight * ratio
......@@ -198,8 +198,8 @@ extension UIImage {
//Setups up the font attributes that will be later used to dictate how the text should be drawn
let textFont = UIFont.systemFont(ofSize: 20, weight: .semibold)
let textFontAttributes = [
NSAttributedStringKey.font: textFont,
NSAttributedStringKey.foregroundColor: textColor]
NSAttributedString.Key.font: textFont,
NSAttributedString.Key.foregroundColor: textColor]
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
backgroundColor.setFill()
......@@ -207,7 +207,7 @@ extension UIImage {
//Put the image into a rectangle as large as the original image.
self.draw(in: rect)
// Our drawing bounds
let textSize = text.size(withAttributes: [NSAttributedStringKey.font: textFont])
let textSize = text.size(withAttributes: [NSAttributedString.Key.font: textFont])
let textRect = CGRect(x: rect.size.width/2 - textSize.width/2, y: rect.size.height/2 - textSize.height/2,
width: textSize.width, height: textSize.height)
text.draw(in: textRect, withAttributes: textFontAttributes)
......
......@@ -25,7 +25,7 @@ extension UILabel {
let attrString = NSMutableAttributedString(string: withText)
let style = NSMutableParagraphStyle()
style.lineSpacing = withLineSpacing
attrString.addAttribute(NSAttributedStringKey.paragraphStyle,
attrString.addAttribute(NSAttributedString.Key.paragraphStyle,
value: style,
range: NSRange(location: 0, length: withText.utf16.count))
self.attributedText = attrString
......
......@@ -132,7 +132,7 @@ extension UIViewController {
self.navigationController?.navigationBar.layer.masksToBounds = false
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
let textAttributes = [NSAttributedStringKey.foregroundColor: UIColor.jamiMain]
let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.jamiMain]
self.navigationController?.navigationBar.titleTextAttributes = textAttributes
self.navigationController?.navigationBar.tintColor = UIColor.jamiMain
}
......
......@@ -35,7 +35,7 @@ class ContactRequestCell: UITableViewCell, NibReusable {
override func setSelected(_ selected: Bool, animated: Bool) {
self.backgroundColor = UIColor.jamiUITableViewCellSelection
UIView.animate(withDuration: 0.35, animations: {
self.backgroundColor = UIColor.jamiUITableViewCellSelection.lighten(byPercentage: 5.0)
self.backgroundColor = UIColor.jamiUITableViewCellSelection.lighten(by: 5.0)
})
}
......
......@@ -59,8 +59,8 @@ class ContactRequestsViewController: UIViewController, StoryboardBased, ViewMode
self.setupTableView()
self.setupBindings()
self.navigationController?.navigationBar
.titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Light", size: 25)!,
NSAttributedStringKey.foregroundColor: UIColor.jamiMain]
.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue-Light", size: 25)!,
NSAttributedString.Key.foregroundColor: UIColor.jamiMain]
}
func applyL10n() {
......@@ -70,7 +70,7 @@ class ContactRequestsViewController: UIViewController, StoryboardBased, ViewMode
func setupTableView() {
self.tableView.estimatedRowHeight = 100.0
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.allowsSelection = true
//Register cell
......
......@@ -296,7 +296,7 @@ class MessageCell: UITableViewCell, NibReusable {
self.progressBar.tintColor = UIColor.jamiMain
} else if item.bubblePosition() == .sent {
self.cancelButton.tintColor = UIColor(hex: 0xf00000, alpha: 1.0)
self.progressBar.tintColor = UIColor.jamiMain.lighten(byPercentage: 0.2)
self.progressBar.tintColor = UIColor.jamiMain.lighten(by: 0.2)
}
if item.shouldDisplayTransferedImage {
......
......@@ -64,8 +64,8 @@ class ConversationViewController: UIViewController,
Register to keyboard notifications to adjust tableView insets when the keybaord appears
or disappears
*/
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(withNotification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(withNotification:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(withNotification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(withNotification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
keyboardDismissTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
}
......@@ -90,15 +90,15 @@ class ConversationViewController: UIViewController,
message: nil,
preferredStyle: .alert)
let pictureAction = UIAlertAction(title: "Upload photo or movie", style: UIAlertActionStyle.default) { _ in
let pictureAction = UIAlertAction(title: "Upload photo or movie", style: UIAlertAction.Style.default) { _ in
self.importImage()
}
let documentsAction = UIAlertAction(title: "Upload file", style: UIAlertActionStyle.default) { _ in
let documentsAction = UIAlertAction(title: "Upload file", style: UIAlertAction.Style.default) { _ in
self.importDocument()
}
let cancelAction = UIAlertAction(title: L10n.Alerts.profileCancelPhoto, style: UIAlertActionStyle.cancel)
let cancelAction = UIAlertAction(title: L10n.Alerts.profileCancelPhoto, style: UIAlertAction.Style.cancel)
alert.addAction(pictureAction)
alert.addAction(documentsAction)
alert.addAction(cancelAction)
......@@ -109,11 +109,11 @@ class ConversationViewController: UIViewController,
}
func takePicture() {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDevice.rear
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.cameraDevice = UIImagePickerController.CameraDevice.rear
imagePicker.modalPresentationStyle = .overFullScreen
self.present(imagePicker, animated: false, completion: nil)
}
......@@ -131,14 +131,14 @@ class ConversationViewController: UIViewController,
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
imagePicker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String]
imagePicker.modalPresentationStyle = .overFullScreen
self.present(imagePicker, animated: true, completion: nil)
}
func copyImageToCache(image: UIImage, imagePath: String) {
guard let imageData = UIImagePNGRepresentation(image) else { return }
guard let imageData = image.pngData() else { return }
do {
self.log.debug("copying image to: \(String(describing: imagePath))")
try imageData.write(to: URL(fileURLWithPath: imagePath), options: .atomic)
......@@ -148,26 +148,27 @@ class ConversationViewController: UIViewController,
}
// swiftlint:disable cyclomatic_complexity
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
internal func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
picker.dismiss(animated: true, completion: nil)
var image: UIImage!
if picker.sourceType == UIImagePickerControllerSourceType.camera {
if picker.sourceType == UIImagePickerController.SourceType.camera {
// image from camera
if let img = info[UIImagePickerControllerEditedImage] as? UIImage {
if let img = info[.editedImage] as? UIImage {
image = img
} else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage {
} else if let img = info[.originalImage] as? UIImage {
image = self.fixImageOrientation(image: img)
}
// copy image to tmp
let imageFileName = "IMG.png"
guard let imageData = UIImagePNGRepresentation(image) else { return }
guard let imageData = image.pngData() else { return }
self.viewModel.sendAndSaveFile(displayName: imageFileName, imageData: imageData)
} else if picker.sourceType == UIImagePickerControllerSourceType.photoLibrary {
} else if picker.sourceType == UIImagePickerController.SourceType.photoLibrary {
// image from library
guard let imageURL = info[UIImagePickerControllerReferenceURL] as? URL else { return }
guard let imageURL = info[UIImagePickerController.InfoKey.referenceURL] as? URL else { return }
self.log.debug("imageURL: \(String(describing: imageURL))")
let result = PHAsset.fetchAssets(withALAssetURLs: [imageURL], options: nil)
......@@ -190,9 +191,9 @@ class ConversationViewController: UIViewController,
guard let phAsset = result.firstObject else { return }
if phAsset.mediaType == .image {
if let img = info[UIImagePickerControllerEditedImage] as? UIImage {
if let img = info[.editedImage] as? UIImage {
image = img
} else if let img = info[UIImagePickerControllerOriginalImage] as? UIImage {
} else if let img = info[.originalImage] as? UIImage {
image = img
}
// copy image to tmp
......@@ -230,7 +231,7 @@ class ConversationViewController: UIViewController,
guard let userInfo: Dictionary = notification.userInfo else {
return
}
guard let keyboardFrame: NSValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
guard let keyboardFrame: NSValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height
......@@ -272,7 +273,7 @@ class ConversationViewController: UIViewController,
// Replace "< Home" with a back arrow while we are crunching everything to the left side of the bar for now.
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "back_button")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back_button")
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.plain, target: nil, action: nil)
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItem.Style.plain, target: nil, action: nil)
let titleView: UIView = UIView.init(frame: CGRect(x: 0, y: 0, width: view.frame.width - 32, height: totalHeight))
......@@ -462,7 +463,7 @@ class ConversationViewController: UIViewController,
self.tableView.dataSource = self
self.tableView.estimatedRowHeight = 50
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.separatorStyle = .none
//Register cell
......@@ -761,7 +762,7 @@ class ConversationViewController: UIViewController,
activityViewController.popoverPresentationController?.sourceView = self.view
activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection()
activityViewController.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.maxX, width: 0, height: 0)
activityViewController.excludedActivityTypes = [UIActivityType.airDrop]
activityViewController.excludedActivityTypes = [UIActivity.ActivityType.airDrop]
self.present(activityViewController, animated: true, completion: nil)
}
}
......
......@@ -55,8 +55,8 @@ open class GrowingTextView: UITextView {
private func commonInit() {
contentMode = .redraw
associateConstraints()
NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: NSNotification.Name.UITextViewTextDidChange, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(textDidEndEditing), name: NSNotification.Name.UITextViewTextDidEndEditing, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(textDidChange), name: UITextView.textDidChangeNotification, object: self)
NotificationCenter.default.addObserver(self, selector: #selector(textDidEndEditing), name: UITextView.textDidEndEditingNotification, object: self)
}
deinit {
......@@ -64,7 +64,7 @@ open class GrowingTextView: UITextView {
}
open override var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: 30)
return CGSize(width: UIView.noIntrinsicMetric, height: 30)
}
private func associateConstraints() {
......
......@@ -45,7 +45,7 @@ class MessageAccessoryView: UIView, NibLoadable, GrowingTextViewDelegate {
return
}
self.bottomAnchor
.constraintLessThanOrEqualToSystemSpacingBelow(window.safeAreaLayoutGuide.bottomAnchor,
.constraint(lessThanOrEqualToSystemSpacingBelow: window.safeAreaLayoutGuide.bottomAnchor,
multiplier: 1)
.isActive = true
}
......