No Description

HomeViewModel.swift 1.6KB

    // // HomeViewModel.swift // PaiAi // // Created by zhengjianfei on 2016/12/29. // Copyright © 2016年 FFIB. All rights reserved. // import Foundation import RxSwift import RxCocoa import RxDataSources public protocol HomeViewModelDelegate: class { func scanQR() func createGroup() func didSelect(_ item: PhotoItem) } public typealias HomeSource = HomePhotoRepositorable & Gettable & Layoutable public struct HomeViewModel<T: HomeSource> { private let respository: T public var isReload: Observable<Bool> public var isloading: Observable<Bool> public weak var delegate: HomeViewModelDelegate? public init(respository: T) { self.respository = respository isReload = respository.loadingObserver.filter { $0 } isloading = respository.loadingObserver.filter { !$0 } } public var homePhotoContents: Observable<[AnimatableSectionModel<Int, T.Content.Element>]> { return respository.content.map({ model in return [AnimatableSectionModel(model: 0, items: model)] }) } public func reload() { respository.loadContent(isRefresh: true) } public func preload() { respository.loadContent(isRefresh: false) } public func layoutSizeForIndexPath(_ indexPath: IndexPath) -> CGSize { let i = indexPath.row return respository.layoutSizeForIndex(i) } public func scanQR() { delegate?.scanQR() } public func createGroup() { delegate?.createGroup() } func didSelect(_ item: T.Content.Element) { delegate?.didSelect(item) } }