| | |
| | | import RxSwift |
| | | |
| | | class GamesDataSourceViewModel:RefreshModel<GamesRecordModel>{ |
| | | private var type:GamesSubType! |
| | | private var type:GamesSubType! |
| | | |
| | | init(type:GamesSubType) { |
| | | super.init() |
| | | self.type = type |
| | | } |
| | | init(type:GamesSubType) { |
| | | super.init() |
| | | self.type = type |
| | | } |
| | | |
| | | let userId = BehaviorRelay<Int>(value:0) |
| | | let userId = BehaviorRelay<Int>(value:0) |
| | | |
| | | override func api() -> (Observable<BaseResponse<[GamesRecordModel]>>)? { |
| | | if type == .offline{ |
| | | return Services.game_generalGameRecord(userId: userId.value, page: page) |
| | | }else if type == .crossMatch{ |
| | | return Services.game_generalGameCrossRecord(userId: userId.value, page: page) |
| | | }else{ |
| | | return Services.game_generalGameAccuracyRecord(userId: userId.value, page: page) |
| | | } |
| | | } |
| | | override func api() -> (Observable<BaseResponse<[GamesRecordModel]>>)? { |
| | | if type == .offline{ |
| | | return Services.game_generalGameRecord(userId: userId.value, page: page) |
| | | }else if type == .crossMatch{ |
| | | return Services.game_generalGameCrossRecord(userId: userId.value, page: page) |
| | | }else{ |
| | | return Services.game_generalGameAccuracyRecord(userId: userId.value, page: page) |
| | | } |
| | | } |
| | | } |
| | | |
| | | class GamesDataSourceSubListVC: BaseVC { |
| | | |
| | | private var type:GamesSubType! |
| | | private var tableView:BaseTableView! |
| | | private var viewModel:GamesDataSourceViewModel! |
| | | private var type:GamesSubType! |
| | | private var tableView:BaseTableView! |
| | | private var viewModel:GamesDataSourceViewModel! |
| | | |
| | | init(type:GamesSubType) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.type = type |
| | | self.viewModel = GamesDataSourceViewModel(type: type) |
| | | } |
| | | init(type:GamesSubType) { |
| | | super.init(nibName: nil, bundle: nil) |
| | | self.type = type |
| | | self.viewModel = GamesDataSourceViewModel(type: type) |
| | | } |
| | | |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | required init?(coder: NSCoder) { |
| | | fatalError("init(coder:) has not been implemented") |
| | | } |
| | | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | |
| | | |
| | | |
| | | // tableView.jq_setEmptyView() |
| | | viewModel.configure(tableView) |
| | | Services.userDetails().subscribe(onNext: {[weak self] data in |
| | | if let userId = data.data?.userId{ |
| | | self?.viewModel.userId.accept(userId) |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | }) { error in |
| | | // tableView.jq_setEmptyView() |
| | | viewModel.configure(tableView) |
| | | Services.userDetails().subscribe(onNext: {[weak self] data in |
| | | if let userId = data.data?.userId{ |
| | | self?.viewModel.userId.accept(userId) |
| | | self?.viewModel.beginRefresh() |
| | | } |
| | | }) { error in |
| | | |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | }.disposed(by: disposeBag) |
| | | } |
| | | |
| | | override func setUI() { |
| | | tableView = BaseTableView(frame: .zero, style: .plain) |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.separatorStyle = .none |
| | | tableView.register(UINib(nibName: "GamesDataSourceTCell", bundle: nil), forCellReuseIdentifier: "_GamesDataSourceTCell") |
| | | view.addSubview(tableView) |
| | | tableView.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview().inset(UIEdgeInsets(top: 7.5, left: 0, bottom: 0, right: 0)) |
| | | } |
| | | } |
| | | override func setUI() { |
| | | tableView = BaseTableView(frame: .zero, style: .plain) |
| | | tableView.delegate = self |
| | | tableView.dataSource = self |
| | | tableView.separatorStyle = .none |
| | | tableView.register(UINib(nibName: "GamesDataSourceTCell", bundle: nil), forCellReuseIdentifier: "_GamesDataSourceTCell") |
| | | view.addSubview(tableView) |
| | | tableView.snp.makeConstraints { make in |
| | | make.edges.equalToSuperview().inset(UIEdgeInsets(top: 7.5, left: 0, bottom: 0, right: 0)) |
| | | } |
| | | } |
| | | } |
| | | |
| | | extension GamesDataSourceSubListVC:UITableViewDelegate{ |
| | |
| | | } |
| | | |
| | | extension GamesDataSourceSubListVC:UITableViewDataSource{ |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_GamesDataSourceTCell") as! GamesDataSourceTCell |
| | | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| | | let cell = tableView.dequeueReusableCell(withIdentifier: "_GamesDataSourceTCell") as! GamesDataSourceTCell |
| | | |
| | | if type == .offline{ |
| | | cell.label_gameName.text = viewModel.dataSource.value[indexPath.row].game_name |
| | | cell.label_score.text = "\(viewModel.dataSource.value[indexPath.row].score)" |
| | | cell.label_type.text = viewModel.dataSource.value[indexPath.row].time |
| | | } |
| | | return cell |
| | | } |
| | | if type == .offline{ |
| | | cell.label_gameName.text = viewModel.dataSource.value[indexPath.row].game_name |
| | | cell.label_score.text = "\(viewModel.dataSource.value[indexPath.row].score)" |
| | | cell.label_type.text = viewModel.dataSource.value[indexPath.row].time |
| | | } |
| | | return cell |
| | | } |
| | | |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | if type == .offline{ |
| | | return viewModel.dataSource.value.count |
| | | } |
| | | return 0 |
| | | } |
| | | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { |
| | | if type == .offline{ |
| | | return viewModel.dataSource.value.count |
| | | } |
| | | return 0 |
| | | } |
| | | } |