Merge pull request #5 from scoreyou/fix/dateFormatter
Fix/date formatter
This commit is contained in:
commit
8a4d162529
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKitAdditions"
|
||||
s.version = "0.0.7"
|
||||
s.version = "0.0.8"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/NikAshanin/LeadKitAdditions"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -25,10 +25,11 @@
|
|||
EF05EDE91EAFA8A000CAE7B6 /* PassCodeHolderProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDE81EAFA8A000CAE7B6 /* PassCodeHolderProtocol.swift */; };
|
||||
EF05EDEB1EAFA8E600CAE7B6 /* PassCodeError.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDEA1EAFA8E600CAE7B6 /* PassCodeError.swift */; };
|
||||
EF05EDED1EAFA96D00CAE7B6 /* PassCodeHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDEC1EAFA96D00CAE7B6 /* PassCodeHolder.swift */; };
|
||||
EF05EDF61EB0D4C300CAE7B6 /* BarButtonLoadingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDF51EB0D4C300CAE7B6 /* BarButtonLoadingService.swift */; };
|
||||
EF05EDF81EB0D5A600CAE7B6 /* UIBarButtonItem+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDF71EB0D5A600CAE7B6 /* UIBarButtonItem+Extensions.swift */; };
|
||||
EF05EDFC1EB0D77400CAE7B6 /* DefaultNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDFA1EB0D77400CAE7B6 /* DefaultNetworkService.swift */; };
|
||||
EF05EDFD1EB0D77400CAE7B6 /* SimpleNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDFB1EB0D77400CAE7B6 /* SimpleNetworkService.swift */; };
|
||||
EF05EDFD1EB0D77400CAE7B6 /* ApiNetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EDFB1EB0D77400CAE7B6 /* ApiNetworkService.swift */; };
|
||||
EF05EE021EB206C000CAE7B6 /* LoadingBarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EE011EB206C000CAE7B6 /* LoadingBarButton.swift */; };
|
||||
EF05EE041EB21A2D00CAE7B6 /* ApiErrorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF05EE031EB21A2D00CAE7B6 /* ApiErrorProtocol.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
|
@ -54,10 +55,11 @@
|
|||
EF05EDE81EAFA8A000CAE7B6 /* PassCodeHolderProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PassCodeHolderProtocol.swift; sourceTree = "<group>"; };
|
||||
EF05EDEA1EAFA8E600CAE7B6 /* PassCodeError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PassCodeError.swift; sourceTree = "<group>"; };
|
||||
EF05EDEC1EAFA96D00CAE7B6 /* PassCodeHolder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PassCodeHolder.swift; sourceTree = "<group>"; };
|
||||
EF05EDF51EB0D4C300CAE7B6 /* BarButtonLoadingService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarButtonLoadingService.swift; sourceTree = "<group>"; };
|
||||
EF05EDF71EB0D5A600CAE7B6 /* UIBarButtonItem+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+Extensions.swift"; sourceTree = "<group>"; };
|
||||
EF05EDFA1EB0D77400CAE7B6 /* DefaultNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefaultNetworkService.swift; sourceTree = "<group>"; };
|
||||
EF05EDFB1EB0D77400CAE7B6 /* SimpleNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleNetworkService.swift; sourceTree = "<group>"; };
|
||||
EF05EDFB1EB0D77400CAE7B6 /* ApiNetworkService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiNetworkService.swift; sourceTree = "<group>"; };
|
||||
EF05EE011EB206C000CAE7B6 /* LoadingBarButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingBarButton.swift; sourceTree = "<group>"; };
|
||||
EF05EE031EB21A2D00CAE7B6 /* ApiErrorProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApiErrorProtocol.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -117,6 +119,7 @@
|
|||
children = (
|
||||
EF05EDBD1EAF706200CAE7B6 /* ApiResponse.swift */,
|
||||
EF05EDBE1EAF706200CAE7B6 /* BaseDateFormatter.swift */,
|
||||
EF05EE011EB206C000CAE7B6 /* LoadingBarButton.swift */,
|
||||
);
|
||||
path = Classes;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -125,7 +128,6 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
EF05EDF91EB0D75A00CAE7B6 /* Network */,
|
||||
EF05EDF51EB0D4C300CAE7B6 /* BarButtonLoadingService.swift */,
|
||||
EF05EDC71EAF91D500CAE7B6 /* BasePassCodeService.swift */,
|
||||
EF05EDB31EAF703A00CAE7B6 /* BaseUserService.swift */,
|
||||
EF05EDC51EAF70EB00CAE7B6 /* TouchIDService.swift */,
|
||||
|
|
@ -147,6 +149,7 @@
|
|||
isa = PBXGroup;
|
||||
children = (
|
||||
EF05EDB91EAF705500CAE7B6 /* ApiError.swift */,
|
||||
EF05EE031EB21A2D00CAE7B6 /* ApiErrorProtocol.swift */,
|
||||
EF05EDBA1EAF705500CAE7B6 /* ConnectionError.swift */,
|
||||
);
|
||||
path = Enums;
|
||||
|
|
@ -201,8 +204,8 @@
|
|||
EF05EDF91EB0D75A00CAE7B6 /* Network */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
EF05EDFB1EB0D77400CAE7B6 /* ApiNetworkService.swift */,
|
||||
EF05EDFA1EB0D77400CAE7B6 /* DefaultNetworkService.swift */,
|
||||
EF05EDFB1EB0D77400CAE7B6 /* SimpleNetworkService.swift */,
|
||||
);
|
||||
path = Network;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -361,19 +364,20 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
EF05EE041EB21A2D00CAE7B6 /* ApiErrorProtocol.swift in Sources */,
|
||||
EF05EDB81EAF704800CAE7B6 /* UserDefaults+UserService.swift in Sources */,
|
||||
EF05EDE11EAFA74200CAE7B6 /* BasePassCodeViewController.swift in Sources */,
|
||||
EF05EDC61EAF70EB00CAE7B6 /* TouchIDService.swift in Sources */,
|
||||
EF05EDE31EAFA7A600CAE7B6 /* BasePassCodeViewModel.swift in Sources */,
|
||||
EF05EDBB1EAF705500CAE7B6 /* ApiError.swift in Sources */,
|
||||
EF05EDE91EAFA8A000CAE7B6 /* PassCodeHolderProtocol.swift in Sources */,
|
||||
EF05EDFD1EB0D77400CAE7B6 /* SimpleNetworkService.swift in Sources */,
|
||||
EF05EDFD1EB0D77400CAE7B6 /* ApiNetworkService.swift in Sources */,
|
||||
EF05EDF81EB0D5A600CAE7B6 /* UIBarButtonItem+Extensions.swift in Sources */,
|
||||
EF05EDED1EAFA96D00CAE7B6 /* PassCodeHolder.swift in Sources */,
|
||||
EF05EDF61EB0D4C300CAE7B6 /* BarButtonLoadingService.swift in Sources */,
|
||||
EF05EDB71EAF704800CAE7B6 /* Observable+Extensions.swift in Sources */,
|
||||
EF05EDC01EAF706200CAE7B6 /* ApiResponse.swift in Sources */,
|
||||
EF05EDBC1EAF705500CAE7B6 /* ConnectionError.swift in Sources */,
|
||||
EF05EE021EB206C000CAE7B6 /* LoadingBarButton.swift in Sources */,
|
||||
EF05EDEB1EAFA8E600CAE7B6 /* PassCodeError.swift in Sources */,
|
||||
EF05EDB41EAF703A00CAE7B6 /* BaseUserService.swift in Sources */,
|
||||
EF05EDE51EAFA80D00CAE7B6 /* PassCodeConfiguration.swift in Sources */,
|
||||
|
|
|
|||
|
|
@ -24,16 +24,16 @@ import UIKit
|
|||
import RxSwift
|
||||
import RxCocoa
|
||||
|
||||
public enum BarButtonLoadingServiceSide {
|
||||
public enum LoadingBarButtonSide {
|
||||
case left
|
||||
case right
|
||||
}
|
||||
|
||||
public class BarButtonLoadingService {
|
||||
public class LoadingBarButton {
|
||||
|
||||
fileprivate weak var navigationItem: UINavigationItem?
|
||||
fileprivate var savedBarButton: UIBarButtonItem?
|
||||
private let side: BarButtonLoadingServiceSide
|
||||
fileprivate var initialBarButton: UIBarButtonItem?
|
||||
private let side: LoadingBarButtonSide
|
||||
|
||||
private var barButtonItem: UIBarButtonItem? {
|
||||
get {
|
||||
|
|
@ -54,20 +54,19 @@ public class BarButtonLoadingService {
|
|||
}
|
||||
}
|
||||
|
||||
public init(navigationItem: UINavigationItem, side: BarButtonLoadingServiceSide) {
|
||||
public init(navigationItem: UINavigationItem, side: LoadingBarButtonSide) {
|
||||
self.navigationItem = navigationItem
|
||||
self.side = side
|
||||
initialBarButton = barButtonItem
|
||||
}
|
||||
|
||||
fileprivate func setBarButton(waiting: Bool = false) {
|
||||
fileprivate func setState(waiting: Bool = false) {
|
||||
if waiting {
|
||||
savedBarButton = barButtonItem
|
||||
|
||||
let activityIndicatorItem = UIBarButtonItem.activityIndicator
|
||||
barButtonItem = activityIndicatorItem.barButton
|
||||
activityIndicatorItem.activityIndicator.startAnimating()
|
||||
} else {
|
||||
barButtonItem = savedBarButton
|
||||
barButtonItem = initialBarButton
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -75,12 +74,12 @@ public class BarButtonLoadingService {
|
|||
|
||||
extension Observable {
|
||||
|
||||
public func changeLoadingUI(using loadingService: BarButtonLoadingService) -> Observable<Observable.E> {
|
||||
public func changeLoadingUI(using barButton: LoadingBarButton) -> Observable<Observable.E> {
|
||||
return observeOn(MainScheduler.instance)
|
||||
.do(onSubscribe: {
|
||||
loadingService.setBarButton(waiting: true)
|
||||
barButton.setState(waiting: true)
|
||||
}, onDispose: {
|
||||
loadingService.setBarButton(waiting: false)
|
||||
barButton.setState(waiting: false)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// Copyright (c) 2017 Touch Instinct
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the Software), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public protocol ApiErrorProtocol: RawRepresentable {}
|
||||
|
||||
extension Error {
|
||||
|
||||
public func isApiError<T: ApiErrorProtocol>(_ apiErrorType: T) -> Bool where T.RawValue == Int {
|
||||
if let error = self as? ApiError,
|
||||
case let .error(code: code, message: _) = error,
|
||||
code == apiErrorType.rawValue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,4 +66,27 @@ public extension Observable {
|
|||
}
|
||||
}
|
||||
|
||||
public func handleApiError<T: ApiErrorProtocol>(_ apiErrorType: T,
|
||||
handler: @escaping () -> Void) -> Observable<Observable.E>
|
||||
where T.RawValue == Int {
|
||||
|
||||
return observeOn(CurrentThreadScheduler.instance)
|
||||
.do(onError: { error in
|
||||
if error.isApiError(apiErrorType) {
|
||||
handler()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public func changeLoadingBehaviour(isLoading: PublishSubject<Bool>) -> Observable<Observable.E> {
|
||||
return observeOn(CurrentThreadScheduler.instance)
|
||||
.do(onNext: { _ in
|
||||
isLoading.onNext(false)
|
||||
}, onError: { _ in
|
||||
isLoading.onNext(false)
|
||||
}, onSubscribe: { _ in
|
||||
isLoading.onNext(true)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,8 @@ import LeadKit
|
|||
import Alamofire
|
||||
import ObjectMapper
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
import RxAlamofire
|
||||
|
||||
open class SimpleNetworkService: DefaultNetworkService {
|
||||
open class ApiNetworkService: DefaultNetworkService {
|
||||
|
||||
open func request<T: ImmutableMappable>(with parameters: ApiRequestParameters) -> Observable<T> {
|
||||
let apiResponseRequest = rxRequest(with: parameters) as Observable<(response: HTTPURLResponse, model: ApiResponse)>
|
||||
|
|
@ -20,13 +20,10 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Alamofire
|
||||
import LeadKit
|
||||
import ObjectMapper
|
||||
import RxSwift
|
||||
import RxCocoa
|
||||
import RxAlamofire
|
||||
|
||||
open class DefaultNetworkService: NetworkService {
|
||||
|
||||
|
|
@ -37,7 +34,7 @@ open class DefaultNetworkService: NetworkService {
|
|||
}
|
||||
|
||||
open class var defaultTimeoutInterval: TimeInterval {
|
||||
fatalError("You should override this var: defaultTimeoutInterval")
|
||||
return 20.0
|
||||
}
|
||||
|
||||
public override init(sessionManager: SessionManager) {
|
||||
|
|
@ -67,21 +64,4 @@ open class DefaultNetworkService: NetworkService {
|
|||
return sessionManager
|
||||
}
|
||||
|
||||
public static func apiRequestParameters(url: String, parameters: [String: Any] = [:]) -> ApiRequestParameters {
|
||||
return ApiRequestParameters(baseUrl: baseUrl, url: url, parameters: parameters)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private extension ApiRequestParameters {
|
||||
|
||||
init(baseUrl: String, url: String, parameters: [String: Any] = [:]) {
|
||||
|
||||
self.init(url: baseUrl + url,
|
||||
method: .post,
|
||||
parameters: parameters,
|
||||
encoding: JSONEncoding.default,
|
||||
headers: nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue