|
| 1 | +import UIKit |
| 2 | +import Domain |
| 3 | +import RxSwift |
| 4 | +import RxCocoa |
| 5 | +import SnapKit |
| 6 | +import Then |
| 7 | +import Core |
| 8 | +import DesignSystem |
| 9 | + |
| 10 | +public final class WinterInternViewController: BaseViewController<WinterInternVieModel> { |
| 11 | + public var viewWillappearWithTap: (() -> Void)? |
| 12 | + public var isTabNavigation: Bool = true |
| 13 | + private let bookmarkButtonDidClicked = PublishRelay<Int>() |
| 14 | + private let pageCount = PublishRelay<Int>() |
| 15 | + private let listEmptyView = ListEmptyView().then { |
| 16 | + $0.setEmptyView(title: "아직 등록된 모집의뢰서가 없어요") |
| 17 | + $0.isHidden = true |
| 18 | + } |
| 19 | + private let recruitmentTableView = UITableView().then { |
| 20 | + $0.register( |
| 21 | + RecruitmentTableViewCell.self, |
| 22 | + forCellReuseIdentifier: RecruitmentTableViewCell.identifier |
| 23 | + ) |
| 24 | + $0.separatorStyle = .none |
| 25 | + $0.rowHeight = 72 |
| 26 | + $0.showsVerticalScrollIndicator = false |
| 27 | + } |
| 28 | + private let filterButton = UIButton().then { |
| 29 | + $0.setImage(.jobisIcon(.filterIcon), for: .normal) |
| 30 | + } |
| 31 | + private let searchButton = UIButton().then { |
| 32 | + $0.setImage(.jobisIcon(.searchIcon), for: .normal) |
| 33 | + } |
| 34 | + |
| 35 | + public override func addView() { |
| 36 | + self.view.addSubview(recruitmentTableView) |
| 37 | + recruitmentTableView.addSubview(listEmptyView) |
| 38 | + } |
| 39 | + |
| 40 | + public override func setLayout() { |
| 41 | + recruitmentTableView.snp.makeConstraints { |
| 42 | + $0.edges.equalToSuperview() |
| 43 | + } |
| 44 | + listEmptyView.snp.makeConstraints { |
| 45 | + $0.centerX.equalToSuperview() |
| 46 | + $0.top.equalToSuperview().inset(80) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + public override func bind() { |
| 51 | + let input = WinterInternVieModel.Input( |
| 52 | + viewAppear: self.viewDidLoadPublisher, |
| 53 | + bookMarkButtonDidTap: bookmarkButtonDidClicked, |
| 54 | + pageChange: recruitmentTableView.rx.willDisplayCell |
| 55 | + .filter { |
| 56 | + $0.indexPath.row == self.recruitmentTableView.numberOfRows( |
| 57 | + inSection: $0.indexPath.section |
| 58 | + ) - 1 |
| 59 | + }, |
| 60 | + recruitmentTableViewDidTap: recruitmentTableView.rx |
| 61 | + .modelSelected(RecruitmentEntity.self) |
| 62 | + .asObservable() |
| 63 | + .map { $0.recruitID } |
| 64 | + .do(onNext: { _ in |
| 65 | + self.isTabNavigation = false |
| 66 | + }), |
| 67 | + searchButtonDidTap: searchButton.rx.tap.asSignal(), |
| 68 | + filterButtonDidTap: filterButton.rx.tap.asSignal() |
| 69 | + ) |
| 70 | + |
| 71 | + let output = viewModel.transform(input) |
| 72 | + |
| 73 | + output.recruitmentData |
| 74 | + .skip(1) |
| 75 | + .do(onNext: { |
| 76 | + self.listEmptyView.isHidden = !$0.isEmpty |
| 77 | + }) |
| 78 | + .bind( |
| 79 | + to: recruitmentTableView.rx.items( |
| 80 | + cellIdentifier: RecruitmentTableViewCell.identifier, |
| 81 | + cellType: RecruitmentTableViewCell.self |
| 82 | + )) { _, element, cell in |
| 83 | + cell.adapt(model: element) |
| 84 | + cell.bookmarkButtonDidTap = { |
| 85 | + self.bookmarkButtonDidClicked.accept(cell.model!.recruitID) |
| 86 | + } |
| 87 | + } |
| 88 | + .disposed(by: disposeBag) |
| 89 | + } |
| 90 | + |
| 91 | + public override func configureViewController() { |
| 92 | + viewWillAppearPublisher.asObservable() |
| 93 | + .bind { |
| 94 | + self.hideTabbar() |
| 95 | + if self.isTabNavigation { |
| 96 | + self.viewWillappearWithTap?() |
| 97 | + } |
| 98 | + } |
| 99 | + .disposed(by: disposeBag) |
| 100 | + } |
| 101 | + |
| 102 | + public override func configureNavigation() { |
| 103 | + self.setSmallTitle(title: "체험형 현장실습") |
| 104 | + navigationItem.rightBarButtonItems = [ |
| 105 | + UIBarButtonItem(customView: searchButton), |
| 106 | + UIBarButtonItem(customView: filterButton) |
| 107 | + ] |
| 108 | + } |
| 109 | +} |
0 commit comments