Skip to content

Commit

Permalink
delete/#388 약속 상세, 약속 정보, 지각 꾸물이, 준비 현황 기능 로직 모두 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Sep 15, 2024
1 parent ed4e6e3 commit 4c0b042
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 971 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,70 +16,104 @@ class PromiseViewController: BaseViewController {
private let promiseInfoViewController: PromiseInfoViewController
private let promiseReadyStatusViewController: ReadyStatusViewController
private let promiseTardyViewController: TardyViewController
private let exitViewController = CustomActionSheetController(kind: .exitPromise)
private let deleteViewController = CustomActionSheetController(kind: .deletePromise)
private let exitViewController = CustomActionSheetController(
kind: .exitPromise
)
private let deleteViewController = CustomActionSheetController(
kind: .deletePromise
)
private let promisePageViewController = UIPageViewController(
transitionStyle: .scroll,
navigationOrientation: .vertical
)

private var removePromiseViewContoller: RemovePromiseViewController = RemovePromiseViewController(promiseName: "")
private var removePromiseViewContoller: RemovePromiseViewController = RemovePromiseViewController(
promiseName: ""
)
private var promiseViewControllerList: [BaseViewController] = []

private lazy var promiseSegmentedControl = PagePromiseSegmentedControl(
items: ["약속 정보", "준비 현황", "지각 꾸물이"]
items: [
"약속 정보",
"준비 현황",
"지각 꾸물이"
]
)


// MARK: - LifeCycle

init(viewModel: PromiseViewModel) {
init(
viewModel: PromiseViewModel
) {
self.viewModel = viewModel

promiseInfoViewController = PromiseInfoViewController(viewModel: viewModel)
promiseReadyStatusViewController = ReadyStatusViewController(viewModel: viewModel)
promiseTardyViewController = TardyViewController(viewModel: viewModel)
promiseInfoViewController = PromiseInfoViewController(
viewModel: viewModel
)
promiseReadyStatusViewController = ReadyStatusViewController(
viewModel: viewModel
)
promiseTardyViewController = TardyViewController(
viewModel: viewModel
)

promiseViewControllerList = [
promiseInfoViewController,
promiseReadyStatusViewController,
promiseTardyViewController
]

super.init(nibName: nil, bundle: nil)
super.init(
nibName: nil,
bundle: nil
)
}

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()

setupNavigationBarBackButton()
setupPromiseEditButton(isHidden: false)
setupBindings()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
override func viewWillAppear(
_ animated: Bool
) {
super.viewWillAppear(
animated
)

navigationController?.isNavigationBarHidden = false
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
override func viewWillDisappear(
_ animated: Bool
) {
super.viewWillDisappear(
animated
)

navigationController?.isNavigationBarHidden = true
}


// MARK: - Setup

override func setupView() {
view.backgroundColor = .white

addChild(promisePageViewController)
addChild(
promisePageViewController
)

view.addSubviews(
promiseSegmentedControl,
Expand All @@ -93,45 +127,65 @@ class PromiseViewController: BaseViewController {
)

promiseSegmentedControl.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.leading.trailing.equalToSuperview().inset(-6)
$0.height.equalTo(60)
$0.top.equalTo(
view.safeAreaLayoutGuide
)
$0.leading.trailing.equalToSuperview().inset(
-6
)
$0.height.equalTo(
Screen.height(
60
)
)
}

promisePageViewController.view.snp.makeConstraints {
$0.top.equalTo(promiseSegmentedControl.snp.bottom)
$0.top.equalTo(
promiseSegmentedControl.snp.bottom
)
$0.leading.trailing.bottom.equalToSuperview()
}
}

override func setupAction() {
promiseSegmentedControl.addTarget(
self,
action: #selector(didSegmentedControlIndexUpdated),
action: #selector(
didSegmentedControlIndexUpdated
),
for: .valueChanged
)

promiseTardyViewController.tardyView.finishMeetingButton.addTarget(
self,
action: #selector(finishMeetingButtonDidTap),
action: #selector(
finishMeetingButtonDidTap
),
for: .touchUpInside
)

promiseTardyViewController.arriveView.finishMeetingButton.addTarget(
self,
action: #selector(finishMeetingButtonDidTap),
action: #selector(
finishMeetingButtonDidTap
),
for: .touchUpInside
)

removePromiseViewContoller.exitButton.addTarget(
self,
action: #selector(exitButtonDidTap),
action: #selector(
exitButtonDidTap
),
for: .touchUpInside
)

removePromiseViewContoller.deleteButton.addTarget(
self,
action: #selector(deleteButtonDidTap),
action: #selector(
deleteButtonDidTap
),
for: .touchUpInside
)
}
Expand All @@ -148,112 +202,91 @@ class PromiseViewController: BaseViewController {

private extension PromiseViewController {
func setupBindings() {
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: true)
owner.promiseInfoViewController.setupContent()
owner.promiseInfoViewController.setUpTimeContent()
owner.removePromiseViewContoller.promiseNameLabel.text = info?.promiseName ?? ""

guard let isParticipant = info?.isParticipant else { return }

owner.setupPromiseEditButton(isHidden: !isParticipant)
owner.promiseInfoViewController.rootView.editButton.isHidden = !isParticipant
}
}

func setupPromiseEditButton(isHidden: Bool) {
let moreButton = UIBarButtonItem(
image: .imgMore.withRenderingMode(.alwaysOriginal),
style: .plain,
target: self,
action: #selector(self.moreButtonDidTap)
)

navigationItem.rightBarButtonItem = isHidden ? nil : moreButton

}

@objc
func didSegmentedControlIndexUpdated() {
let condition = viewModel.currentPageIndex.value <= promiseSegmentedControl.selectedSegmentIndex
let direction: UIPageViewController.NavigationDirection = condition ? .forward : .reverse
let (width, count, selectedIndex) = (
promiseSegmentedControl.bounds.width,
promiseSegmentedControl.numberOfSegments,
promiseSegmentedControl.selectedSegmentIndex
)

promiseSegmentedControl.selectedUnderLineView.snp.updateConstraints {
$0.leading.equalToSuperview().offset((width / CGFloat(count)) * CGFloat(selectedIndex))
}

viewModel.segmentIndexDidChange(
index: promiseSegmentedControl.selectedSegmentIndex
)

promisePageViewController.setViewControllers([
promiseViewControllerList[viewModel.currentPageIndex.value]
], direction: direction, animated: false)
// let condition = viewModel.currentPageIndex.value <= promiseSegmentedControl.selectedSegmentIndex
// let direction: UIPageViewController.NavigationDirection = condition ? .forward : .reverse
// let (width, count, selectedIndex) = (
// promiseSegmentedControl.bounds.width,
// promiseSegmentedControl.numberOfSegments,
// promiseSegmentedControl.selectedSegmentIndex
// )
//
// promiseSegmentedControl.selectedUnderLineView.snp.updateConstraints {
// $0.leading.equalToSuperview().offset((width / CGFloat(count)) * CGFloat(selectedIndex))
// }
//
// viewModel.segmentIndexDidChange(
// index: promiseSegmentedControl.selectedSegmentIndex
// )
//
// promisePageViewController.setViewControllers([
// promiseViewControllerList[viewModel.currentPageIndex.value]
// ], direction: direction, animated: false)
}

@objc
func finishMeetingButtonDidTap() {
promiseTardyViewController.viewModel.updatePromiseCompletion {
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)

if let viewController = self.navigationController?.viewControllers.last {
let toast = Toast()
toast.show(message: "약속 마치기 성공!", view: viewController.view, position: .bottom, inset: 100)
}
}
}

}

@objc
func moreButtonDidTap() {
let bottomSheetViewController = BottomSheetViewController(
contentViewController: removePromiseViewContoller,
defaultHeight: Screen.height(232)
defaultHeight: Screen.height(
232
)
)

present(bottomSheetViewController, animated: true)
present(
bottomSheetViewController,
animated: true
)
}

@objc
func exitButtonDidTap() {
dismiss(animated: false)
present(exitViewController, animated: true)
dismiss(
animated: false
)
present(
exitViewController,
animated: true
)
}

@objc
func deleteButtonDidTap() {
dismiss(animated: false)
present(deleteViewController, animated: true)
dismiss(
animated: false
)
present(
deleteViewController,
animated: true
)
}
}


// MARK: - CustomActionSheetDelegate

extension PromiseViewController: CustomActionSheetDelegate {
func actionButtonDidTap(for kind: ActionSheetKind) {
func actionButtonDidTap(
for kind: ActionSheetKind
) {
if kind == .deletePromise {
dismiss(animated: false)

viewModel.deletePromise() {
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)
}
}
dismiss(
animated: false
)
}
else {
dismiss(animated: false)

viewModel.exitPromise() {
DispatchQueue.main.async {
self.navigationController?.popViewController(animated: true)
}
}
dismiss(
animated: false
)
}
}
}
Expand Down
Loading

0 comments on commit 4c0b042

Please sign in to comment.