Skip to content

Commit

Permalink
[Chore] sopt-makers#173- 뷰 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
devxsby committed Apr 18, 2023
1 parent af30f83 commit 0a87a6e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Foundation

public enum AttendanceStateType: String, CaseIterable {
case all = "전체"
case attendance = "출석"
case tardy = "지각"
case absent = "결석"
case participate = "참여"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ public class ShowAttendanceRepository {
extension ShowAttendanceRepository: ShowAttendanceRepositoryInterface {
public func fetchAttendanceScheduleModel() -> AnyPublisher<AttendanceScheduleModel, Error> {
return Future<AttendanceScheduleModel, Error> { promise in
// promise(.success(AttendanceScheduleModel(type: "HAS_ATTENDANCE",
// location: "솝트대학교 IT 창업관",
// name: "3차 세미나",
// startDate: "2023-04-06T14:00:00", endDate: "2023-04-06T18:00:00",
// message: "",
// attendances: [TodayAttendanceModel(status: "ATTENDANCE", attendedAt: "2023-04-13T14:00:00"),
// TodayAttendanceModel(status: "ABSENT", attendedAt: "2023-04-13T14:02:00")])))
promise(.success(AttendanceScheduleModel(type: "HAS_ATTENDANCE",
location: "솝트대학교 IT 창업관",
name: "3차 세미나",
startDate: "2023-04-29T14:00:00", endDate: "2023-04-29T18:00:00",
message: "",
attendances: [TodayAttendanceModel(status: "ATTENDANCE", attendedAt: "2023-04-29T14:00:00"),
TodayAttendanceModel(status: "ABSENT", attendedAt: "2023-04-29T14:02:00")])))

promise(.success(AttendanceScheduleModel(type: "NO_SESSION",
location: "",
name: "",
startDate: "", endDate: "", message: "",
attendances: [TodayAttendanceModel(status: "", attendedAt: ""),
TodayAttendanceModel(status: "", attendedAt: "")])))
// promise(.success(AttendanceScheduleModel(type: "NO_SESSION",
// location: "",
// name: "",
// startDate: "", endDate: "", message: "",
// attendances: [TodayAttendanceModel(status: "", attendedAt: ""),
// TodayAttendanceModel(status: "", attendedAt: "")])))
}
.eraseToAnyPublisher()
// return self.attendanceService.fetchAttendanceSchedule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl
}
}

private var viewdidload = PassthroughSubject<Void, Never>()
private var viewWillAppear = PassthroughSubject<Void, Never>()

// MARK: - UI Components

private let containerScrollView = UIScrollView()
private lazy var containerScrollView: UIScrollView = {
let sv = UIScrollView()
sv.showsVerticalScrollIndicator = false
sv.refreshControl = refresher
return sv
}()

private let contentView = UIView()

private lazy var navibar = OPNavigationBar(self, type: .bothButtons)
private lazy var navibar = OPNavigationBar(self, type: .oneLeftButton)
.addMiddleLabel(title: I18N.Attendance.attendance)
.addRightButtonAction {
self.refreshButtonDidTap()
}

private lazy var headerScheduleView: TodayScheduleView = {
switch sceneType {
Expand All @@ -57,6 +60,12 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl

private let attendanceScoreView = AttendanceScoreView()

private let refresher: UIRefreshControl = {
let rf = UIRefreshControl()
rf.tintColor = .gray
return rf
}()

// MARK: - Initialization

public init(viewModel: ShowAttendanceViewModel,
Expand All @@ -75,10 +84,13 @@ public final class ShowAttendanceVC: UIViewController, ShowAttendanceViewControl
public override func viewDidLoad() {
super.viewDidLoad()
self.bindViewModels()
self.bindViews()
self.setUI()
self.setLayout()
self.viewdidload.send(())
}

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.viewWillAppear.send(())
}
}

Expand Down Expand Up @@ -128,25 +140,20 @@ extension ShowAttendanceVC {

extension ShowAttendanceVC {

private func bindViews() {
private func bindViewModels() {

navibar.rightButtonTapped
let refreshStarted = refresher.publisher(for: .valueChanged)
.mapVoid()
.asDriver()
.withUnretained(self)
.sink { owner, _ in
owner.refreshButtonDidTap()
}.store(in: self.cancelBag)
}

private func bindViewModels() {

let input = ShowAttendanceViewModel.Input(viewDidLoad: viewdidload.asDriver(),
refreshButtonTapped: navibar.rightButtonTapped)
let input = ShowAttendanceViewModel.Input(viewWillAppear: viewWillAppear.asDriver(),
refreshStarted: refreshStarted)
let output = self.viewModel.transform(from: input, cancelBag: self.cancelBag)

output.$scheduleModel
.sink(receiveValue: { [weak self] model in
guard let self, let model else { return }
self.endRefresh()

if self.viewModel.sceneType == .scheduledDay {
self.sceneType = .scheduledDay
Expand All @@ -162,13 +169,13 @@ extension ShowAttendanceVC {
output.$scoreModel
.sink { model in
guard let model else { return }
self.endRefresh()
self.setScoreData(model)
}.store(in: self.cancelBag)
}

@objc
private func refreshButtonDidTap() {
print("refresh button did tap")
private func endRefresh() {
self.refresher.endRefreshing()
}

private func setScheduledData(_ model: AttendanceScheduleModel) {
Expand All @@ -185,7 +192,7 @@ extension ShowAttendanceVC {
private func setScoreData(_ model: AttendanceScoreModel) {
attendanceScoreView.setMyInfoData(name: model.name, part: model.part, generation: model.generation,
count: model.score)
attendanceScoreView.setMyTotalScoreData(attendance: model.total.attendance, tardy: model.total.tardy, absent: model.total.absent)
attendanceScoreView.setMyTotalScoreData(attendance: model.total.attendance, tardy: model.total.tardy, absent: model.total.absent, participate: model.total.participate)
attendanceScoreView.setMyAttendanceTableData(model.attendances)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public final class ShowAttendanceViewModel: ViewModelType {
// MARK: - Inputs

public struct Input {
let viewDidLoad: Driver<Void>
let refreshButtonTapped: Driver<Void>
let viewWillAppear: Driver<Void>
let refreshStarted: Driver<Void>
}

// MARK: - Outputs
Expand All @@ -54,7 +54,7 @@ extension ShowAttendanceViewModel {

self.bindOutput(output: output, cancelBag: cancelBag)

input.viewDidLoad.merge(with: input.refreshButtonTapped)
input.viewWillAppear.merge(with: input.refreshStarted)
.withUnretained(self)
.sink { owner, _ in
owner.useCase.fetchAttendanceSchedule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ final class AttendanceScoreView: UIView {

/// 2. 전체 출결 점수 영역

private let allScoreView = SingleScoreView(type: .all)
private let attendanceScoreView = SingleScoreView(type: .attendance)
private let tardyScoreView = SingleScoreView(type: .tardy)
private let absentScoreView = SingleScoreView(type: .absent)
private let participateScoreView = SingleScoreView(type: .participate)

private lazy var myScoreContainerStackView: UIStackView = {
let stackView = UIStackView(arrangedSubviews: [allScoreView, attendanceScoreView, tardyScoreView, absentScoreView])
let stackView = UIStackView(arrangedSubviews: [attendanceScoreView, tardyScoreView, absentScoreView, participateScoreView])
stackView.backgroundColor = DSKitAsset.Colors.black40.color
stackView.clipsToBounds = true
stackView.layer.cornerRadius = 8
Expand Down Expand Up @@ -145,11 +145,11 @@ extension AttendanceScoreView {
myInfoContainerView.setData(name: name, part: part, generation: generation, count: count)
}

func setMyTotalScoreData(attendance: Int, tardy: Int, absent: Int) {
allScoreView.setData(attendance + tardy + absent)
func setMyTotalScoreData(attendance: Int, tardy: Int, absent: Int, participate: Int) {
attendanceScoreView.setData(attendance)
tardyScoreView.setData(tardy)
absentScoreView.setData(absent)
participateScoreView.setData(participate)
}

func setMyAttendanceTableData(_ model: [AttendanceModel]) {
Expand Down

0 comments on commit 0a87a6e

Please sign in to comment.