jsdw_ios/QuickLocation/Section/Group/GroupViewModel.swift

98 lines
4.9 KiB
Swift

//
// GroupViewModel.swift
// QuickLocation
//
import Foundation
import RxSwift
import RxCocoa
import RxDataSources
typealias CircleListSectionModel = SectionModel<String, CircleGroupItem>
// MARK: - Models
///
struct HotGroupItem {
let id: String
let name: String
let icon: String
let memberCount: Int
let onlineCount: Int
}
///
struct CircleGroupItem {
let id: String
let name: String
let icon: String
let memberCount: Int
let onlineCount: Int
let address: String
}
// MARK: - ViewModel
final class GroupViewModel {
struct Output {
let hotGroups: Driver<[HotGroupItem]>
let createdSections: Observable<[CircleListSectionModel]>
let joinedSections: Observable<[CircleListSectionModel]>
let segmentTitles: Driver<[String]>
}
let output: Output
private let hotGroupsSubject = BehaviorRelay<[HotGroupItem]>(value: [])
private let createdSectionsSubject = PublishSubject<[CircleListSectionModel]>()
private let joinedSectionsSubject = PublishSubject<[CircleListSectionModel]>()
let segmentTitles = BehaviorRelay<[String]>(value: ["我创建的圈子", "我加入的圈子"])
// MARK: - Init
init() {
output = Output(
hotGroups: hotGroupsSubject.asDriver(),
createdSections: createdSectionsSubject.asObservable(),
joinedSections: joinedSectionsSubject.asObservable(),
segmentTitles: segmentTitles.asDriver()
)
}
func loadMockData() {
hotGroupsSubject.accept([
HotGroupItem(id: "h1", name: "户外探险队", icon: "map_avatar_1", memberCount: 128, onlineCount: 32),
HotGroupItem(id: "h2", name: "城市慢跑团", icon: "map_avatar_2", memberCount: 256, onlineCount: 45),
HotGroupItem(id: "h3", name: "骑行爱好者", icon: "map_avatar_3", memberCount: 89, onlineCount: 12),
HotGroupItem(id: "h4", name: "登山俱乐部", icon: "map_avatar_4", memberCount: 342, onlineCount: 67),
HotGroupItem(id: "h5", name: "摄影交流圈", icon: "map_avatar_5", memberCount: 156, onlineCount: 28)
])
let createdItems = [
CircleGroupItem(id: "c1", name: "户外探险队", icon: "map_avatar_1", memberCount: 128, onlineCount: 32, address: "重庆市渝北区"),
CircleGroupItem(id: "c2", name: "周末徒步小组", icon: "map_avatar_2", memberCount: 45, onlineCount: 8, address: "重庆市江北区"),
CircleGroupItem(id: "c3", name: "夜跑小分队", icon: "map_avatar_3", memberCount: 67, onlineCount: 15, address: "重庆市南岸区"),
CircleGroupItem(id: "c4", name: "钓鱼爱好者", icon: "map_avatar_4", memberCount: 32, onlineCount: 6, address: "重庆市北碚区"),
CircleGroupItem(id: "c5", name: "美食探店团", icon: "map_avatar_5", memberCount: 89, onlineCount: 23, address: "重庆市渝中区"),
CircleGroupItem(id: "c6", name: "桌游俱乐部", icon: "map_avatar_1", memberCount: 56, onlineCount: 18, address: "重庆市沙坪坝区"),
CircleGroupItem(id: "c7", name: "电影交流群", icon: "map_avatar_2", memberCount: 112, onlineCount: 34, address: "重庆市九龙坡区")
]
createdSectionsSubject.onNext([SectionModel(model: "created", items: createdItems)])
let joinedItems = [
CircleGroupItem(id: "j1", name: "城市慢跑团", icon: "map_avatar_2", memberCount: 256, onlineCount: 45, address: "重庆市两江新区"),
CircleGroupItem(id: "j2", name: "骑行爱好者", icon: "map_avatar_3", memberCount: 89, onlineCount: 12, address: "重庆市沙坪坝区"),
CircleGroupItem(id: "j3", name: "登山俱乐部", icon: "map_avatar_4", memberCount: 342, onlineCount: 67, address: "重庆市九龙坡区"),
CircleGroupItem(id: "j4", name: "摄影交流圈", icon: "map_avatar_5", memberCount: 156, onlineCount: 28, address: "重庆市大渡口区"),
CircleGroupItem(id: "j5", name: "羽毛球爱好者", icon: "map_avatar_1", memberCount: 98, onlineCount: 22, address: "重庆市巴南区"),
CircleGroupItem(id: "j6", name: "宠物家长群", icon: "map_avatar_2", memberCount: 67, onlineCount: 15, address: "重庆市渝北区"),
CircleGroupItem(id: "j7", name: "读书分享会", icon: "map_avatar_3", memberCount: 45, onlineCount: 11, address: "重庆市江北区"),
CircleGroupItem(id: "j8", name: "电竞战队", icon: "map_avatar_4", memberCount: 134, onlineCount: 42, address: "重庆市南岸区"),
CircleGroupItem(id: "j9", name: "手工DIY圈", icon: "map_avatar_5", memberCount: 78, onlineCount: 19, address: "重庆市渝中区"),
CircleGroupItem(id: "j10", name: "瑜伽冥想群", icon: "map_avatar_1", memberCount: 56, onlineCount: 24, address: "重庆市巴南区")
]
joinedSectionsSubject.onNext([SectionModel(model: "joined", items: joinedItems)])
}
}