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"
......@@ -150,7 +150,6 @@
0EAA9DB52029F0AA005E245C /* ProxyCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0EAA9DB32029F0AA005E245C /* ProxyCell.xib */; };
0EB1A5CF1F8EBE03009923E2 /* DeviceCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0EB1A5CE1F8EBE03009923E2 /* DeviceCell.xib */; };
0EB1A5D11F8EBE23009923E2 /* DeviceCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB1A5D01F8EBE23009923E2 /* DeviceCell.swift */; };
0EB479951FA28A7300106AFD /* ButtonTransparentBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB479941FA28A7300106AFD /* ButtonTransparentBackground.swift */; };
0EBB72A92034F44200D88F46 /* ProfilesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EBB72A82034F44200D88F46 /* ProfilesService.swift */; };
0EBCAA4E202E60F000E2A545 /* default.wav in Resources */ = {isa = PBXBuildFile; fileRef = 0EBCAA4D202E60F000E2A545 /* default.wav */; };
0ECEE9A3220D1935000E1CF4 /* VideoToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0ECEE9A2220D1935000E1CF4 /* VideoToolbox.framework */; };
......@@ -217,8 +216,6 @@
1A2D18FD1F292DAD00B2C785 /* ConversationCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1A2D18FB1F292DAD00B2C785 /* ConversationCell.xib */; };
1A2D18FF1F29352D00B2C785 /* MeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */; };
1A2D19011F29353A00B2C785 /* MeDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */; };
1A3CA32B1F102BB700283748 /* Chameleon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A3CA32A1F102BB700283748 /* Chameleon.framework */; };
1A3CA32D1F13DA7200283748 /* Chameleon+Ring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */; };
1A3D28A71F0EB9DB00B524EE /* Bool+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */; };
1A3D28A91F0EBF0200B524EE /* UIView+Ring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A3D28A81F0EBF0200B524EE /* UIView+Ring.swift */; };
1A5DC01E1F355DA70075E8EF /* ContactsAdapterDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A5DC01D1F355DA70075E8EF /* ContactsAdapterDelegate.swift */; };
......@@ -478,7 +475,6 @@
0EB12451224AB1030025F8CA /* ContactsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ContactsUI.framework; path = System/Library/Frameworks/ContactsUI.framework; sourceTree = SDKROOT; };
0EB1A5CE1F8EBE03009923E2 /* DeviceCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DeviceCell.xib; sourceTree = "<group>"; };
0EB1A5D01F8EBE23009923E2 /* DeviceCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceCell.swift; sourceTree = "<group>"; };
0EB479941FA28A7300106AFD /* ButtonTransparentBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonTransparentBackground.swift; sourceTree = "<group>"; };
0EBB72A82034F44200D88F46 /* ProfilesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilesService.swift; sourceTree = "<group>"; };
0EBCAA4D202E60F000E2A545 /* default.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = default.wav; sourceTree = "<group>"; };
0ECEE9A2220D1935000E1CF4 /* VideoToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VideoToolbox.framework; path = System/Library/Frameworks/VideoToolbox.framework; sourceTree = SDKROOT; };
......@@ -546,7 +542,6 @@
1A2D18FE1F29352D00B2C785 /* MeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeViewModel.swift; sourceTree = "<group>"; };
1A2D19001F29353A00B2C785 /* MeDetailViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeDetailViewModel.swift; sourceTree = "<group>"; };
1A3CA32A1F102BB700283748 /* Chameleon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Chameleon.framework; path = Carthage/Build/iOS/Chameleon.framework; sourceTree = "<group>"; };
1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Chameleon+Ring.swift"; sourceTree = "<group>"; };
1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Bool+String.swift"; sourceTree = "<group>"; };
1A3D28A81F0EBF0200B524EE /* UIView+Ring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Ring.swift"; sourceTree = "<group>"; };
1A5DC00A1F3558980075E8EF /* ContactsAdapter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContactsAdapter.h; sourceTree = "<group>"; };
......@@ -706,7 +701,6 @@
5C093F011FB495830011D90E /* Differentiator.framework in Frameworks */,
0ED666101F9FED1C00743D42 /* AMPopTip.framework in Frameworks */,
0EEFBA3C1F83DA21000EDBAD /* libsecp256k1.a in Frameworks */,
1A3CA32B1F102BB700283748 /* Chameleon.framework in Frameworks */,
1A1E476F1F0E894600EA9A36 /* SwiftyBeaver.framework in Frameworks */,
1A1E476D1F0E808500EA9A36 /* Reusable.framework in Frameworks */,
56559B0E1EE8777600BF20E1 /* RxRealm.framework in Frameworks */,
......@@ -912,7 +906,6 @@
0273C3071E0C68BF00CF00BA /* DesignableButton.swift */,
56AC650D1E85694D00EA1AA9 /* DesignableTextField.swift */,
1A2041901F1FD46200C08435 /* DesignableView.swift */,
0EB479941FA28A7300106AFD /* ButtonTransparentBackground.swift */,
0E438A99204F47E700402900 /* SettingsTableView.swift */,
);
path = UI;
......@@ -929,7 +922,6 @@
1A3D28A61F0EB9DB00B524EE /* Bool+String.swift */,
1A3D28A81F0EBF0200B524EE /* UIView+Ring.swift */,
1AABA7451F0FE9C000739605 /* UIColor+Ring.swift */,
1A3CA32C1F13DA7200283748 /* Chameleon+Ring.swift */,
1A2D18991F2642C000B2C785 /* NotificationCenter+Ring.swift */,
1A2D189B1F264AD900B2C785 /* UIViewController+Ring.swift */,
1A2D18A51F27F7A400B2C785 /* UIViewController+Rx.swift */,
......@@ -1843,7 +1835,6 @@
"$(SRCROOT)/Carthage/Build/iOS/RxRealm.framework",
"$(SRCROOT)/Carthage/Build/iOS/Reusable.framework",
"$(SRCROOT)/Carthage/Build/iOS/SwiftyBeaver.framework",
"$(SRCROOT)/Carthage/Build/iOS/Chameleon.framework",
"$(SRCROOT)/Carthage/build/iOS/AMPopTip.framework",
"$(SRCROOT)/Carthage/Build/iOS/Reachability.framework",
"$(SRCROOT)/Carthage/Build/iOS/Differentiator.framework",
......@@ -1862,7 +1853,6 @@
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/RxRealm.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Reusable.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftyBeaver.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Chameleon.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/AMPopTip.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Differentiator.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SQLite.framework",
......@@ -1899,7 +1889,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "${PROJECT_DIR}/swiftgen/swiftgen.sh";
shellScript = "${PROJECT_DIR}/swiftgen/swiftgen.sh\n";
};
6236602D200914C9002598C1 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
......@@ -1986,7 +1976,6 @@
0EE1B54E1F75ACDE00BA98EE /* CNContactVCardSerialization+Helpers.swift in Sources */,
0E0FF1AA1FC3843E003898C2 /* DBContainer.swift in Sources */,
56308BA71EA00E5700660275 /* NameRegistrationResponse.m in Sources */,
1A3CA32D1F13DA7200283748 /* Chameleon+Ring.swift in Sources */,
0ED2B6FC1F96A158001572F0 /* LinkNewDeviceViewController.swift in Sources */,
1ABE07E21F0D924700D36361 /* Strings.swift in Sources */,
0E6F544D223BFE3E00ECC3CE /* DisposableCell.swift in Sources */,
......@@ -2029,7 +2018,6 @@
0E0FF1AF1FC38CBC003898C2 /* ProfileDataHelper.swift in Sources */,
563AEC771EA664C0003A5641 /* RegistrationResponse.m in Sources */,
564C445B1E8EA44E000F92B1 /* Durations.swift in Sources */,
0EB479951FA28A7300106AFD /* ButtonTransparentBackground.swift in Sources */,
0E320D54224ADFD00070B515 /* DialpadViewModel.swift in Sources */,
0EB1A5D11F8EBE23009923E2 /* DeviceCell.swift in Sources */,
0E6949791FA7E71C0029B60A /* BaseViewController.swift in Sources */,
......@@ -2237,7 +2225,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
......@@ -2288,7 +2276,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
......@@ -2328,7 +2316,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Ring/Bridging/Ring-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VALID_ARCHS = arm64;
VERSIONING_SYSTEM = "";
};
......@@ -2367,7 +2355,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Ring/Bridging/Ring-Bridging-Header.h";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VALID_ARCHS = arm64;
VERSIONING_SYSTEM = "";
};
......@@ -2494,7 +2482,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Development;
......@@ -2533,7 +2521,7 @@
SWIFT_OBJC_BRIDGING_HEADER = "Ring/Bridging/Ring-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
VALID_ARCHS = arm64;
VERSIONING_SYSTEM = "";
};
......
......@@ -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() {