| | |
| | | |
| | | import UIKit |
| | | import JQTools |
| | | import RxSwift |
| | | import RxRelay |
| | | |
| | | class HomeItemViewModel:RefreshModel<SimpleModel>{ |
| | | |
| | | class HomeItemViewModel:RefreshInnerModel<MeditationModel>{ |
| | | var id = BehaviorRelay<Int>(value: 0) |
| | | override func api() -> (Observable<BaseResponse<BaseResponseList<MeditationModel>>>)? { |
| | | return Services.getMeditationPage(id.value, page: page) |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | private var collectionView:UICollectionView! |
| | | private var topTitle:String! |
| | | private var id:Int! |
| | | |
| | | private var viewModel = HomeItemViewModel() |
| | | |
| | | init(topTitle:String,id:Int) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.topTitle = topTitle |
| | | self.id = id |
| | | self.viewModel.id.accept(id) |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | |
| | | title = self.topTitle |
| | | |
| | | viewModel.configure(collectionView) |
| | | viewModel.beginRefresh() |
| | | } |
| | | |
| | | override func setUI() { |
| | |
| | | extension HomeItemListVC:UICollectionViewDelegate & UICollectionViewDataSource{ |
| | | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
| | | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeRelaxBanner_2_CCell", for: indexPath) as! HomeRelaxBanner_2_CCell |
| | | let model = viewModel.dataSource.value!.list[indexPath.row] |
| | | cell.backgroundColor = .jq_randomColor |
| | | cell.setMeditationModel(model) |
| | | return cell |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
| | | return 50 |
| | | return viewModel.dataSource.value?.list.count ?? 0 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | let vc = HomeItemDetailVC() |
| | | let id = viewModel.dataSource.value!.list[indexPath.row].id |
| | | let vc = HomeItemDetailVC(id: id) |
| | | push(vc: vc) |
| | | } |
| | | } |