64 lines
1.7 KiB
Swift
64 lines
1.7 KiB
Swift
//
|
|
// ScheduleViewModel.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/23.
|
|
//
|
|
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxDataSources
|
|
import MJRefresh
|
|
|
|
typealias ViewedListSectionModel = SectionModel<String, ViewedModel>
|
|
typealias ScheduleListSectionModel = AnimatableSectionModel<String, ScheduleModel>
|
|
|
|
class ScheduleViewModel: ViewModelType {
|
|
|
|
struct Input {}
|
|
|
|
struct Output {
|
|
var sectionedItems: Observable<[ViewedListSectionModel]>
|
|
var scheduleSectionedItems: Observable<[ScheduleListSectionModel]>
|
|
var refreshResult: Observable<RefreshResult>
|
|
var pagination: Observable<PaginationModel?>
|
|
var error: Observable<Error>
|
|
}
|
|
|
|
let input: Input
|
|
let output: Output
|
|
|
|
private var listService: ListService<ScheduleListResponse>
|
|
private let sectionedItems = PublishSubject<[ViewedListSectionModel]>()
|
|
private let scheduleSectionedItems = PublishSubject<[ScheduleListSectionModel]>()
|
|
|
|
var refresh: MJRefreshComponentAction {
|
|
return {
|
|
self.listService.request.onNext(.refresh)
|
|
}
|
|
}
|
|
var loadMore: MJRefreshComponentAction {
|
|
return {
|
|
self.listService.request.onNext(.more)
|
|
}
|
|
}
|
|
|
|
func loadViewedData(_ list: [ViewedModel]) {
|
|
sectionedItems.onNext(list.mapSection())
|
|
}
|
|
|
|
// MARK: - init
|
|
init() {
|
|
listService = ItineraryService.query()
|
|
|
|
input = Input()
|
|
output = Output(
|
|
sectionedItems: sectionedItems.asObservable(),
|
|
scheduleSectionedItems: listService.animatableSectionedItems,
|
|
refreshResult: listService.refreshResult,
|
|
pagination: listService.pagination,
|
|
error: listService.error
|
|
)
|
|
}
|
|
}
|