Skip to content

Instantly share code, notes, and snippets.

@vadimsmirnovnsk
Created February 17, 2018 14:09
Show Gist options
  • Save vadimsmirnovnsk/c7ed3bee0956d78fbfe8c6c8dc25529a to your computer and use it in GitHub Desktop.
Save vadimsmirnovnsk/c7ed3bee0956d78fbfe8c6c8dc25529a to your computer and use it in GitHub Desktop.
import VNCommon
import VNServices
internal protocol IHaveReport {
associatedtype TReportType
}
internal class FlowTableVM<TReport>: FlowSimpleTableVM, IHaveReport {
typealias TReportType = TReport
internal let report: TReport
internal init(title: String? = nil,
tableVM: BaseTableViewVM,
report: TReport,
router: Router,
analytics: ISideAnalyticsSender? = nil,
selectPhotoService: ISelectPhotoProtocol? = nil,
reportErrorService: IReportErrorService? = nil) {
self.report = report
super.init(
title: title,
tableVM: tableVM,
router: router,
analytics: analytics,
selectPhotoService: selectPhotoService,
reportErrorService: reportErrorService
)
}
}
internal class FlowSimpleTableVM: BaseTableVM {
internal let selectPhotoService: ISelectPhotoProtocol?
internal let reportErrorService: IReportErrorService?
internal let analytics: ISideAnalyticsSender?
internal var shouldShowSendButton: Bool = true
internal var shouldHandleBackButton: Bool = true
internal var haveAnyChanges: Bool = false
internal var canSendReport: Bool = false {
didSet {
self.viewModelChanged?()
}
}
private let router: Router
internal init(title: String? = nil,
tableVM: BaseTableViewVM,
router: Router,
analytics: ISideAnalyticsSender? = nil,
selectPhotoService: ISelectPhotoProtocol? = nil,
reportErrorService: IReportErrorService? = nil) {
self.selectPhotoService = selectPhotoService
self.reportErrorService = reportErrorService
self.router = router
self.analytics = analytics
super.init(title: title, tableVM: tableVM)
}
internal func sendReport() { }
internal func back() {
guard self.haveAnyChanges || self.canSendReport else {
self.router.pop()
return
}
let cancel = UIAlertAction.cancel(withTitle: L10N("report.error.back.cancel"))
let ok = UIAlertAction(title: L10N("report.error.back.ok"), style: .default) {
[weak self] _ in
self?.router.pop()
}
self.router.showAlert(
title: nil,
message: L10N("report.error.back.message"),
actions: [ok, cancel]
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment