Skip to content

Commit

Permalink
Merge branch 'release/2.11.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoboschini committed Feb 20, 2019
2 parents 6d02c95 + 7056bc0 commit 241f812
Show file tree
Hide file tree
Showing 31 changed files with 412 additions and 306 deletions.
2 changes: 2 additions & 0 deletions Near-iOS-UI/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled_rules:
- trailing_whitespace
18 changes: 18 additions & 0 deletions Near-iOS-UI/Near-iOS-UI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@
26CAC2FF1F56BB4E009DDDF2 /* Frameworks */,
26CAC3001F56BB4E009DDDF2 /* Headers */,
26CAC3011F56BB4E009DDDF2 /* Resources */,
D7B4340B2211E7830002E675 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -593,6 +594,23 @@
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-NearUIBinding-Tests-NeariOSUITests/Pods-NearUIBinding-Tests-NeariOSUITests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
D7B4340B2211E7830002E675 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nif which swiftlint >/dev/null; then swiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
EA3E0B00CF78A0C236329F11 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
2 changes: 1 addition & 1 deletion Near-iOS-UI/Near-iOS-UI/Classes/NITCouponCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class NITCouponCell : UITableViewCell {
class NITCouponCell: UITableViewCell {

@IBOutlet weak var name: UILabel!
@IBOutlet weak var value: UILabel!
Expand Down
7 changes: 4 additions & 3 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITImageDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public class NITImageDownloader: NSObject {

@objc public static let sharedInstance = NITImageDownloader()

var imageCache: [String : UIImage] = [:]
var imageCache: [String: UIImage] = [:]

func downloadImageWithUrl(url: URL, completionBlock: @escaping (_ succeeded: Bool, _ image: UIImage?, _ url: URL) -> Void) {
func downloadImageWithUrl(url: URL,
completionBlock: @escaping (_ succeeded: Bool, _ image: UIImage?, _ url: URL) -> Void) {
if let cachedImage = self.imageCache[url.absoluteString] {
completionBlock(true, cachedImage, url)
} else {
Expand All @@ -29,7 +30,7 @@ public class NITImageDownloader: NSObject {
return
}

DispatchQueue.main.async() { () -> Void in
DispatchQueue.main.async { () -> Void in
completionBlock(true, image, url)
self.imageCache[url.absoluteString] = image
}
Expand Down
8 changes: 6 additions & 2 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITMultilineButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ public class NITMultilineButton: UIButton {
let bundle = Bundle.NITBundle(for: NITMultilineButton.self)
bundle.loadNibNamed("NITMultilineButton", owner: self, options: nil)
defaultSadImage = UIImage(named: "sad", in: Bundle.NITBundle(for: NITMultilineButton.self), compatibleWith: nil)
defaultWorriedImage = UIImage(named: "worried", in: Bundle.NITBundle(for: NITMultilineButton.self), compatibleWith: nil)
defaultHappyImage = UIImage(named: "happyGreen", in: Bundle.NITBundle(for: NITMultilineButton.self), compatibleWith: nil)
defaultWorriedImage = UIImage(named: "worried",
in: Bundle.NITBundle(for: NITMultilineButton.self),
compatibleWith: nil)
defaultHappyImage = UIImage(named: "happyGreen",
in: Bundle.NITBundle(for: NITMultilineButton.self),
compatibleWith: nil)

addSubview(contentView)
contentView.translatesAutoresizingMaskIntoConstraints = false
Expand Down
14 changes: 7 additions & 7 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITNotificationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NITNotificationCell: UITableViewCell {
var readColor = NITUIAppearance.sharedInstance.nearGrey()
var dateColor = NITUIAppearance.sharedInstance.nearGrey()
var messageColor = NITUIAppearance.sharedInstance.nearBlack()
private var cardBackgroundReadColor = UIColor(red: 249.0/255.0, green: 249.0/255.0, blue: 249.0/255.0, alpha: 1.0)
private var cardBackgroundReadColor = UIColor(red: 239.0/255.0, green: 239.0/255.0, blue: 239.0/255.0, alpha: 1.0)
var shadowOpacity: Float = 0.15
var state: NITNotificationCellState = .unread {
didSet {
Expand Down Expand Up @@ -93,12 +93,12 @@ class NITNotificationCell: UITableViewCell {

func makeShadow(_ shadow: Bool) {
if shadow {
contentView.layer.shadowOffset = CGSize(width: 0, height: 1);
contentView.layer.shadowOffset = CGSize(width: 0, height: 1)
contentView.layer.shadowColor = UIColor.black.cgColor
contentView.layer.shadowRadius = 5;
contentView.layer.shadowOpacity = shadowOpacity;
contentView.layer.shadowRadius = 5
contentView.layer.shadowOpacity = shadowOpacity
} else {
contentView.layer.shadowOpacity = 0;
contentView.layer.shadowOpacity = 0
}
}

Expand All @@ -115,7 +115,7 @@ class NITNotificationCell: UITableViewCell {
func changeStateUI() {
switch state {
case .read:
selectionStyle = .default
selectionStyle = .none
makeBoldMessage(false)
makeBoldMore(false)
makeBoldDate(false)
Expand All @@ -125,7 +125,7 @@ class NITNotificationCell: UITableViewCell {
setLabelsColor(readColor)
contentView.backgroundColor = cardBackgroundReadColor
case .unread:
selectionStyle = .default
selectionStyle = .none
makeBoldMessage(true)
makeBoldMore(true)
makeBoldDate(true)
Expand Down
26 changes: 16 additions & 10 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITPermissionBarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class NITPermissionBarButton: UIView {

var alreadyMissing = [NITPermissionInfo]()

@objc @IBInspectable public var missingLocationIcon: UIImage?
@objc @IBInspectable public var missingBluetoothIcon: UIImage?
@objc @IBInspectable public var missingNotificationIcon: UIImage?
@IBInspectable public var missingLocationIcon: UIImage?
@IBInspectable public var missingBluetoothIcon: UIImage?
@IBInspectable public var missingNotificationIcon: UIImage?

private var defaultMissingLocationIcon: UIImage?
private var defaultMissingBluetoothIcon: UIImage?
Expand All @@ -47,9 +47,15 @@ class NITPermissionBarButton: UIView {
}

private func setup() {
defaultMissingBluetoothIcon = UIImage(named: "bluetoothBianco", in: Bundle.NITBundle(for: NITPermissionBarButton.self), compatibleWith: nil)
defaultMissingLocationIcon = UIImage(named: "localizzazioneBianco", in: Bundle.NITBundle(for: NITPermissionBarButton.self), compatibleWith: nil)
defaultMissingNotificationIcon = UIImage(named: "notificheBianco", in: Bundle.NITBundle(for: NITPermissionBarButton.self), compatibleWith: nil)
defaultMissingBluetoothIcon = UIImage(named: "bluetoothBianco",
in: Bundle.NITBundle(for: NITPermissionBarButton.self),
compatibleWith: nil)
defaultMissingLocationIcon = UIImage(named: "localizzazioneBianco",
in: Bundle.NITBundle(for: NITPermissionBarButton.self),
compatibleWith: nil)
defaultMissingNotificationIcon = UIImage(named: "notificheBianco",
in: Bundle.NITBundle(for: NITPermissionBarButton.self),
compatibleWith: nil)
}

override func layoutSubviews() {
Expand All @@ -75,9 +81,9 @@ class NITPermissionBarButton: UIView {
}
}

public func addMissingConstraint(_ permissionInfo : NITPermissionInfo) {
if (alreadyMissing.contains(permissionInfo)) {
return;
public func addMissingConstraint(_ permissionInfo: NITPermissionInfo) {
if alreadyMissing.contains(permissionInfo) {
return
}
alreadyMissing.append(permissionInfo)
if let image = imageFrom(permissionInfo) {
Expand All @@ -90,7 +96,7 @@ class NITPermissionBarButton: UIView {
}
}

func imageFrom(_ permissionInfo : NITPermissionInfo) -> UIImage? {
func imageFrom(_ permissionInfo: NITPermissionInfo) -> UIImage? {
switch permissionInfo {
case .blueTooth:
return getMissingBluetoothIcon()
Expand Down
4 changes: 2 additions & 2 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITPermissionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class NITPermissionButton: UIButton {
super.layoutSubviews()
if let image = imageView?.image {
let margin = 30.0 - image.size.width / 2
let tr = titleRect(forContentRect: bounds)
let tRect = titleRect(forContentRect: bounds)
contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.left
imageEdgeInsets = UIEdgeInsets(top: 0, left: margin, bottom: 0, right: 0)
titleEdgeInsets = UIEdgeInsets(top: 0, left: (bounds.width - tr.width - image.size.width - margin) / 2,
titleEdgeInsets = UIEdgeInsets(top: 0, left: (bounds.width - tRect.width - image.size.width - margin) / 2,
bottom: 0, right: 0)
}
}
Expand Down
30 changes: 21 additions & 9 deletions Near-iOS-UI/Near-iOS-UI/Classes/NITPermissionsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
// Created by francesco.leoni on 04/09/17.
// Copyright © 2017 Near. All rights reserved.
//
// d

import UIKit
import CoreLocation
import UserNotifications

public protocol NITPermissionsManagerDelegate: class {
func permissionsManager(_ manager: NITPermissionsManager, didGrantLocationAuthorization granted: Bool, withStatus status: CLAuthorizationStatus)
func permissionsManager(_ manager: NITPermissionsManager,
didGrantLocationAuthorization granted: Bool,
withStatus status: CLAuthorizationStatus)
func permissionsManagerDidRequestNotificationPermissions(_ manager: NITPermissionsManager)
}

Expand All @@ -25,6 +28,7 @@ public class NITPermissionsManager: NSObject {
@available(iOS 10.0, *)
private var notificationCenter: UNUserNotificationCenter {
get {
// swiftlint:disable force_cast
return _notificationCenter as! UNUserNotificationCenter
}
set {
Expand All @@ -35,15 +39,19 @@ public class NITPermissionsManager: NSObject {
public override convenience init() {
let locationManager = CLLocationManager()
if #available(iOS 10.0, *) {
self.init(locationManager: locationManager, notificationCenter: UNUserNotificationCenter.current(), application: UIApplication.shared)
self.init(locationManager: locationManager,
notificationCenter: UNUserNotificationCenter.current(),
application: UIApplication.shared)
} else {
// Fallback on earlier versions
self.init(locationManager: locationManager, application: UIApplication.shared)
}
}

@available(iOS 10.0, *)
public init(locationManager: CLLocationManager, notificationCenter: UNUserNotificationCenter, application: UIApplication) {
public init(locationManager: CLLocationManager,
notificationCenter: UNUserNotificationCenter,
application: UIApplication) {
self.locationManager = locationManager
_notificationCenter = notificationCenter
self.application = application
Expand Down Expand Up @@ -71,7 +79,8 @@ public class NITPermissionsManager: NSObject {
notificationCenter.getNotificationSettings { (settings) in
DispatchQueue.main.async {
if settings.authorizationStatus == .notDetermined {
self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge], completionHandler: { (granted, error) in
self.notificationCenter.requestAuthorization(options: [.alert, .sound, .badge],
completionHandler: { (_, _) in
OperationQueue.main.addOperation({
self.delegate?.permissionsManagerDidRequestNotificationPermissions(self)
})
Expand All @@ -89,10 +98,11 @@ public class NITPermissionsManager: NSObject {
}
}

public func allPermissionsGranted(minLevel: CLAuthorizationStatus = .authorizedAlways, completionHandler: @escaping (Bool) -> Void) {
public func allPermissionsGranted(minLevel: CLAuthorizationStatus = .authorizedAlways,
completionHandler: @escaping (Bool) -> Void) {
isNotificationAvailable { (available) in
if available {
if self.isLocationGranted(status: minLevel){
if self.isLocationGranted(status: minLevel) {
completionHandler(true)
} else {
completionHandler(false)
Expand All @@ -116,7 +126,9 @@ public class NITPermissionsManager: NSObject {
}
} else {
if let settings = application.currentUserNotificationSettings {
if (settings.types.contains(.alert) || settings.types.contains(.badge) || settings.types.contains(.sound)) {
if settings.types.contains(.alert) ||
settings.types.contains(.badge) ||
settings.types.contains(.sound) {
completionHandler(true)
} else {
completionHandler(false)
Expand Down Expand Up @@ -154,7 +166,7 @@ public class NITPermissionsManager: NSObject {

public func isLocationGranted(status: CLAuthorizationStatus) -> Bool {
let osStatus = CLLocationManager.authorizationStatus()
if (osStatus == status) {
if osStatus == status {
return true
}
return false
Expand Down Expand Up @@ -182,7 +194,7 @@ public class NITPermissionsManager: NSObject {
if let url = URL(string: UIApplication.openSettingsURLString) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else{
} else {
UIApplication.shared.openURL(url)
}
}
Expand Down
Loading

0 comments on commit 241f812

Please sign in to comment.