Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions sources/ComicDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
// Created: 2019-09-21
//


import UIKit

class ComicDetailsViewController: UIViewController {

var comicId:Int?
var comicImage:UIImage?
var tags:[String]?
var comicId: Int?
var comicImage: UIImage?
var tags: [String]?

//Mark: UI Elements
// MARK: UI Elements
let comicImageView: UIImageView = {
let imageView = UIImageView(frame: CGRect(x: 0,y: 0,width: 150,height: 150))
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))
imageView.contentMode = UIView.ContentMode.scaleAspectFill
imageView.clipsToBounds = true
return imageView
Expand Down Expand Up @@ -47,7 +46,7 @@ class ComicDetailsViewController: UIViewController {
return addTagButton
}()

//Mark: Methods
// MARK: Methods
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
Expand All @@ -61,7 +60,7 @@ class ComicDetailsViewController: UIViewController {
setupTagCollectionView()
}

fileprivate static func createHorizontalRowStack() -> UIStackView{
fileprivate static func createHorizontalRowStack() -> UIStackView {
let horizontalStackView = UIStackView(frame: CGRect.zero)
horizontalStackView.axis = .horizontal
horizontalStackView.translatesAutoresizingMaskIntoConstraints = false
Expand All @@ -74,7 +73,7 @@ class ComicDetailsViewController: UIViewController {
fileprivate static func createColumnStack() -> UIStackView {
let verticalStackView = UIStackView(frame: CGRect.zero)
verticalStackView.axis = .vertical
verticalStackView.translatesAutoresizingMaskIntoConstraints = false;
verticalStackView.translatesAutoresizingMaskIntoConstraints = false
return verticalStackView
}

Expand Down Expand Up @@ -107,8 +106,17 @@ class ComicDetailsViewController: UIViewController {
}

fileprivate func setupNavigationBar() {
navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(onCancel))
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(onSave))

navigationItem.leftBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .cancel,
target: self,
action: #selector(onCancel))

navigationItem.rightBarButtonItem =
UIBarButtonItem(barButtonSystemItem: .save,
target: self,
action: #selector(onSave))

navigationController?.navigationBar.isTranslucent = false
}

Expand All @@ -119,10 +127,10 @@ class ComicDetailsViewController: UIViewController {
}

fileprivate func loadTags() {
tags = ["Astronomy", "Discovery", "Futility", "Survival", "Scientist"].sorted()
tags = ["Astronomy", "Discovery", "Futility", "Survival", "Scientist"].sorted()
}

//Mark: Navigation Actions
// MARK: Navigation Actions
@objc func onSave() {
//To do callback
}
Expand All @@ -138,9 +146,12 @@ extension ComicDetailsViewController: UICollectionViewDataSource {
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let tagCell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCell", for: indexPath) as? TagCell else {
return UICollectionViewCell()
}

let tagCell = collectionView
.dequeueReusableCell(withReuseIdentifier: "TagCell",
for: indexPath)
as! TagCell // swiftlint:disable:this force_cast

tagCell.textLabel.text = tags?[indexPath.row]
return tagCell
}
Expand All @@ -151,10 +162,9 @@ extension ComicDetailsViewController: UICollectionViewDelegate {

}


class TagCell: UICollectionViewCell {

var textLabel:UILabel = {
var textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.preferredFont(forTextStyle: .subheadline)
Expand Down
8 changes: 1 addition & 7 deletions sources/ComicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class ComicViewController: UIViewController {
}

private func addConstraints() {
// TODO - Added by Arun
// commenting the next line because we are still loading this view fro the storyboard
// view.translatesAutoresizingMaskIntoConstraints = false
comicImageView.translatesAutoresizingMaskIntoConstraints = false

view.centerXAnchor.constraint(equalTo: comicImageView.centerXAnchor).isActive = true
Expand All @@ -72,7 +69,6 @@ class ComicViewController: UIViewController {
comicImageView.addGestureRecognizer(tapGestureRecognizer)
}


// MARK: UTILITIES

private func nextComic() {
Expand All @@ -93,11 +89,10 @@ class ComicViewController: UIViewController {
currentComic = previousComic
}


private func showDetails() {
let comicDetailsViewController = ComicDetailsViewController()
comicDetailsViewController.comicId = currentComic?.id
comicDetailsViewController.comicImage = currentComic?.image
comicDetailsViewController.comicImage = comicImageView.image
let navigationController = UINavigationController(rootViewController: comicDetailsViewController)
present(navigationController, animated: false)
}
Expand All @@ -106,7 +101,6 @@ class ComicViewController: UIViewController {
return Int.random(in: 0 ... 2198)
}


// MARK: ACTIONS

@objc func handleBackGesture(_ sender: UISwipeGestureRecognizer) {
Expand Down