|
//
// PhotoDetailListViewModel.swift
// PaiaiDataKit
//
// Created by ffib on 2019/3/19.
// Copyright © 2019 yb. All rights reserved.
//
import Foundation
import RxSwift
import RxCocoa
import RxDataSources
public protocol PhotoDetailListViewModelSynchronization: class {
func willShow(_ item: PhotoItem)
}
public protocol PhotoDetailListViewModelDelegate: class {
func didSelected()
}
public final class PhotoDetailListViewModel {
private var items: BehaviorRelay<[PhotoItem]>
public var currIndex: Int
public weak var delegate: PhotoDetailListViewModelDelegate?
public weak var synchronization: PhotoDetailListViewModelSynchronization?
public var content: Observable<[AnimatableSectionModel<Int, PhotoItem>]> {
return items.map({ model in
return [AnimatableSectionModel(model: 0, items: model)]
})
}
public init(items: [PhotoItem], currIndex: Int) {
self.items = BehaviorRelay<[PhotoItem]>(value: items)
self.currIndex = currIndex
}
public func willShow(index: Int) {
currIndex = index
synchronization?.willShow(items.value[currIndex])
}
public func didSelected() {
delegate?.didSelected()
}
}
|