You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4 KiB

  1. //
  2. // DetailNotificationViewController.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 2020/02/11.
  6. //Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. import RxSwift
  10. import RxCocoa
  11. class DetailNotificationViewController: UIViewController {
  12. // MARK: Properties
  13. var presenter: DetailNotificationPresenter!
  14. private let disposeBag = DisposeBag()
  15. // MARK: Computed Properties
  16. // MARK: IBOutlets
  17. @IBOutlet private weak var imageView: UIImageView!
  18. @IBOutlet private weak var titleLabel: UILabel!
  19. @IBOutlet private weak var contentLabel: UILabel!
  20. @IBOutlet private weak var dateLabel: UILabel!
  21. @IBOutlet private weak var contentView: UIView!
  22. // MARK: VC's Life cycle
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. setup()
  26. }
  27. override func viewWillAppear(_ animated: Bool) {
  28. super.viewWillAppear(animated)
  29. title = "Notice"
  30. }
  31. override func viewWillDisappear(_ animated: Bool) {
  32. super.viewWillDisappear(animated)
  33. }
  34. // MARK: IBActions
  35. }
  36. // MARK: Other Functions
  37. extension DetailNotificationViewController {
  38. private func setup() {
  39. setUI()
  40. setBinding()
  41. setUIBinding()
  42. }
  43. private func setUI() {
  44. }
  45. private func setUIBinding() {
  46. }
  47. private func setBinding() {
  48. let viewWillAppear = rx
  49. .sentMessage(#selector(UIViewController.viewWillAppear(_:))).mapToVoid().asDriverOnErrorJustComplete()
  50. let input = DetailNotificationPresenter.Input(
  51. viewWillAppear: viewWillAppear
  52. )
  53. let output = presenter.transform(input: input)
  54. output.isError
  55. .drive(
  56. onNext: { self.alert(type: .error, message: $0.localizedDescription) }
  57. ).disposed(by: disposeBag)
  58. output.isProgress
  59. .drive(
  60. onNext: { $0 ? self.showProgressHud() : self.hideProgressHud() }
  61. ).disposed(by: disposeBag)
  62. output.model.map {$0.body}.drive(contentLabel.rx.text).disposed(by: disposeBag)
  63. output.model.map {$0.date}.drive(dateLabel.rx.text).disposed(by: disposeBag)
  64. output.model.map {$0.title ?? ""}.drive(titleLabel.rx.text).disposed(by: disposeBag)
  65. output.model.map {$0.imageURL}.drive(onNext: {[weak self] in
  66. guard let imageURL = $0, let url = URL(string: imageURL) else {
  67. self?.imageView.isHidden = true
  68. return
  69. }
  70. self?.showProgressHud()
  71. self?.imageView.kf.setImage(with: url) { _ in
  72. self?.hideProgressHud()
  73. }
  74. }).disposed(by: disposeBag)
  75. }
  76. }