Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created May 26, 2018 13:00
Show Gist options
  • Save vialyx/1f00676576d317e822cab640939cc93c to your computer and use it in GitHub Desktop.
Save vialyx/1f00676576d317e822cab640939cc93c to your computer and use it in GitHub Desktop.
import UIKit
final class TaskListViewController: UIViewController, InfoPresenterProtocol, ActivityIndicatorProtocol {
@IBOutlet weak var collectionView: UICollectionView!
var model: TaskListModelInput!
var imagePicker: ImagePickerInput!
private var collectionDataSource: TaskListCollectionViewDataSource!
private var selectedTask: TaskDataType?
override func viewDidLoad() {
super.viewDidLoad()
collectionDataSource = TaskListCollectionViewDataSource(view: collectionView, controller: self, card: model.card)
collectionView.collectionViewLayout = TaskListCollectionViewFlowLayout()
collectionView.reloadData()
}
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {}
@IBAction func unwind(segue: UIStoryboardSegue) {}
}
// MARK: - TaskListModelOutput
extension TaskListViewController: TaskListModelOutput {
func didUpdate(task: TaskDataType) {
selectedTask = nil
hideActivityIndicator()
show(title: "Task did update", message: "\(task)")
}
}
// MARK: - TaskListViewControllerInput
extension TaskListViewController: TaskListViewControllerInput {
func imagePickerDidFinish(with image: UIImage?) {
guard let `image` = image,
let data = UIImageJPEGRepresentation(image, 1.0),
let task = selectedTask else { return }
showActivityIndicator()
model.upload(image: data, for: task)
}
func startTask() {
show(error: "Start task")
}
func doLaterTask() {
collectionDataSource.showTask = false
collectionView.performBatchUpdates({
collectionView.deleteItems(at: [IndexPath(item: 0, section: TaskListSection.description.rawValue)])
}, completion: nil)
}
func didSelect(task: TaskDataType) {
selectedTask = task
imagePicker.show(on: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment