Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

home-view: update homeViewController #49

Open
wants to merge 1 commit into
base: dev-sandra-herrera
Choose a base branch
from

Conversation

SandraMarcelaHerreraArriaga
Copy link
Collaborator

What does this PR do?

Where should the reviewer start?

Code review checklist Code Review Rubric

  1. DRY Principle (Don’t repeat yourself)

    • Excellent
    • Good
    • Adequate
    • Developing
  2. Yagni Principle (You Aren't Gonna Need It)

    • Excellent
    • Good
    • Adequate
    • Developing
  3. KISS Principle (Keep It Simple, St...d)

    • Excellent
    • Good
    • Adequate
    • Developing
  4. Remove unused code

    • Excellent
    • Good
    • Adequate
    • Developing
  5. Hard-coded values

    • Excellent
    • Good
    • Adequate
    • Developing
  6. Language style guide & coding conventions

  1. Architecture / Design Pattern

    • MVC
    • MVP
    • MVVM
    • VIPER
  2. Architecture Implementation

    • Excellent
    • Good
    • Adequate
    • Developing
  3. SOLID

  • Single Responsibility Principle

    • Excellent
    • Good
    • Adequate
    • Developing
  • Open Closed Principle

    • Excellent
    • Good
    • Adequate
    • Developing
  • Liskov substitutability principle

    • Excellent
    • Good
    • Adequate
    • Developing
  • Interface segregation

    • Excellent
    • Good
    • Adequate
    • Developing
  • Dependency Inversion principle

    • Excellent
    • Good
    • Adequate
    • Developing
  1. Testing

    • Excellent
    • Good
    • Adequate
    • Developing
  2. Force unwrapping !

    • Excellent
    • Good
    • Adequate
    • Developing
  3. Mutable vs immutable property (Right use of let and var)

    • Excellent
    • Good
    • Adequate
    • Developing
  4. Retain cycles (Capture list)

    • Excellent
    • Good
    • Adequate
    • Developing
  5. Code Documentation

    • Excellent
    • Good
    • Adequate
    • Developing

var viewMoreButton = UIButton()
var collectionView: UICollectionView!

let service = NetworkManager(urlSession: URLSession.shared)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it private since it's a dependency and inject over init to allow dependency injection

let service = NetworkManager(urlSession: URLSession.shared)
static let categoryHeaderUpcoming = "Upcoming"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a struct of constants or enums

var movies: [Movie] = [] {
didSet {
collectionView.reloadData()
}
}

init() {
super.init(collectionViewLayout: HomeViewController.createLayout())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call a method instead of creating static or Factory pattern can be used here, this just to avoid exposing static elements

static func createLayout() -> UICollectionViewCompositionalLayout {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .fractionalHeight(1)))
return UICollectionViewCompositionalLayout { (sectionNumber, env) -> NSCollectionLayoutSection in
if sectionNumber == 0 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic numbers, this is risky what if by any reason order change ? wouldn't it be better to use an enum or constant instead ?

Comment on lines +30 to +46
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(200)), subitems: [item])
item.contentInsets.trailing = 10
item.contentInsets.leading = 10
item.contentInsets.bottom = 16
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .paging
return section
} else {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: .fractionalWidth(0.33), heightDimension: .absolute(150)))
item.contentInsets.trailing = 10
item.contentInsets.bottom = 5
let group = NSCollectionLayoutGroup.horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .estimated(500)), subitems: [item])

let section = NSCollectionLayoutSection(group: group)
section.contentInsets.leading = 10
section.boundarySupplementaryItems = [
.init(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: .absolute(50)), elementKind: categoryHeaderUpcoming, alignment: .topLeading)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this into a function

Comment on lines +60 to +63
collectionView.register(MovieCell.self, forCellWithReuseIdentifier: "cell")
collectionView.register(HeaderOfSection.self, forSupplementaryViewOfKind: HomeViewController.categoryHeaderUpcoming, withReuseIdentifier: categoryHeaderUpcomingId)
navigationItem.title = "Movies"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this into a method called prepareLayout or setupLayout

Comment on lines +84 to +86
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MovieCell
cell.label?.text = movies[indexPath.row].title
return cell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid forcewrapping use a guard instead

return cell
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
2
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a magic number, we should know from something how many sections are present sorta like movies var

}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: categoryHeaderUpcomingId, for: indexPath) as! HeaderOfSection
header.label.text = "Upcoming"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we create a static element on top and not using it here ?

//

import Foundation
class MakeRequest {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

self?.handleResponse(response)
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single space per line

}
let service = NetworkManager(urlSession: URLSession.shared)


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single space per line


import Foundation

class GetLatestMoviesRepositoryImpl: GetLatestMoviesRepository{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final


import Foundation

class GetLatestMoviesRepositoryImpl: GetLatestMoviesRepository{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GetLatestMoviesRepositoryImpl: GetLatestMoviesRepository{
class GetLatestMoviesRepositoryImpl: GetLatestMoviesRepository {

private let basePath: String = URLRequestType.popular.basePath
let service = NetworkManager(urlSession: URLSession.shared)

func handleResponse(_ response: MovieList) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it private

Suggested change
func handleResponse(_ response: MovieList) {
private func handleResponse(_ response: MovieList) {


import Foundation

class GetNowPlayingMoviesRepositoryImpl: GetNowPlayingMoviesRepository {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fianl

Suggested change
class GetNowPlayingMoviesRepositoryImpl: GetNowPlayingMoviesRepository {
final class GetNowPlayingMoviesRepositoryImpl: GetNowPlayingMoviesRepository {

Comment on lines +21 to +22

func handleResponse(_ response: MovieList) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func handleResponse(_ response: MovieList) {
private func handleResponse(_ response: MovieList) {


import Foundation

class GetPopularMoviesRepositoryImpl: GetPopularMoviesRepository {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GetPopularMoviesRepositoryImpl: GetPopularMoviesRepository {
final class GetPopularMoviesRepositoryImpl: GetPopularMoviesRepository {

class GetPopularMoviesRepositoryImpl: GetPopularMoviesRepository {
var movies: [Movie] = []
private let basePath: String = URLRequestType.popular.basePath
let service = NetworkManager(urlSession: URLSession.shared)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let service = NetworkManager(urlSession: URLSession.shared)
let service = NetworkManager(urlSession: URLSession.shared) // No singleton should be called here directly


import Foundation

class GetTopRatedMoviesRepositoryImpl: GetListMoviesRepository {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GetTopRatedMoviesRepositoryImpl: GetListMoviesRepository {
final class GetTopRatedMoviesRepositoryImpl: GetListMoviesRepository {

//

import Foundation
class GetUpcomingMoviesRepositoryImpl: GetUpcomingMoviesRepository {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class GetUpcomingMoviesRepositoryImpl: GetUpcomingMoviesRepository {
final class GetUpcomingMoviesRepositoryImpl: GetUpcomingMoviesRepository {

}
}

func handleResponse(_ response: MovieList) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func handleResponse(_ response: MovieList) {
private func handleResponse(_ response: MovieList) {

//

import Foundation
class MoviesRepositoryImpl {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class MoviesRepositoryImpl {
final class MoviesRepositoryImpl {


func requestMovies() {
service.get(path: basePath) { [weak self] response in
_ = self?.handleResponse(response)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can bring a race condition since you are returning values

Comment on lines +26 to +28
movies = response.results
}
return movies
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compeltion or return ?

import Foundation
import UIKit

class HeaderOfSection: UICollectionReusableView {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

Comment on lines +12 to +14
let label = UILabel()
var title: String?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need this cell what about using a default one ?


override func layoutSubviews() {
super.layoutSubviews()
label.frame = bounds
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this line doing ?

Copy link

@Kros-s Kros-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's focus on some comments related to final, private and accesory levels, we also need to look at DRY principle to avoid repeating code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants