[Framework] Feed framework setup (#2)
This PR contains the work done to set the Feed framework into the project, and then integrate it to the App target. Reviewed-on: rock-n-code/app-reviews#2 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #2.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// Copyright © 2020 ING. All rights reserved.
|
||||
//
|
||||
|
||||
import ReviewsFeed
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// AppStoreReviews
|
||||
//
|
||||
// Created by Dmitrii Ivanov on 21/07/2020.
|
||||
// Copyright © 2020 ING. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class DetailsViewController: UIViewController {
|
||||
|
||||
private let review: Review
|
||||
|
||||
private var titleLabel = UILabel()
|
||||
private var authorLabel = UILabel()
|
||||
private var contentLabel = UILabel()
|
||||
private var ratingVersionLabel = UILabel()
|
||||
|
||||
init(review: Review) {
|
||||
self.review = review
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
view.backgroundColor = UIColor.white
|
||||
setupViews()
|
||||
}
|
||||
|
||||
func setupViews() {
|
||||
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
authorLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
ratingVersionLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
view.addSubview(ratingVersionLabel)
|
||||
view.addSubview(authorLabel)
|
||||
view.addSubview(titleLabel)
|
||||
view.addSubview(contentLabel)
|
||||
|
||||
ratingVersionLabel.text = review.ratingVersionText()
|
||||
ratingVersionLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
||||
|
||||
authorLabel.text = review.author
|
||||
authorLabel.font = UIFont.systemFont(ofSize: 18)
|
||||
|
||||
titleLabel.text = review.title
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.font = UIFont.boldSystemFont(ofSize: 22)
|
||||
|
||||
contentLabel.text = review.content
|
||||
contentLabel.numberOfLines = 0
|
||||
|
||||
ratingVersionLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true
|
||||
ratingVersionLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true
|
||||
ratingVersionLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 8).isActive = true
|
||||
ratingVersionLabel.heightAnchor.constraint(equalToConstant: 24).isActive = true
|
||||
|
||||
authorLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true
|
||||
authorLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true
|
||||
authorLabel.topAnchor.constraint(equalTo: ratingVersionLabel.bottomAnchor, constant: 8).isActive = true
|
||||
authorLabel.heightAnchor.constraint(equalToConstant: 24).isActive = true
|
||||
|
||||
titleLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true
|
||||
titleLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true
|
||||
titleLabel.topAnchor.constraint(equalTo: authorLabel.bottomAnchor, constant: 8).isActive = true
|
||||
titleLabel.heightAnchor.constraint(lessThanOrEqualToConstant: 72).isActive = true
|
||||
|
||||
contentLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true
|
||||
contentLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true
|
||||
contentLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 8).isActive = true
|
||||
contentLabel.heightAnchor.constraint(greaterThanOrEqualToConstant: 24).isActive = true
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// AppStoreReviews
|
||||
//
|
||||
// Created by Dmitrii Ivanov on 21/07/2020.
|
||||
// Copyright © 2020 ING. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class FeedViewController: UITableViewController {
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
tableView.register(ReviewCell.self, forCellReuseIdentifier: "cellId")
|
||||
tableView.rowHeight = 160
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return 100
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let c = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! ReviewCell
|
||||
c.update(item: randomReview())
|
||||
return c
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
let vc = DetailsViewController(review: randomReview())
|
||||
navigationController!.pushViewController(vc, animated: true)
|
||||
}
|
||||
|
||||
func randomReview() -> Review {
|
||||
let author = ["Dan Auerbach", "Bo Diddley", "Otis Rush", "Jimi Hendrix", "Albert King", "Buddy Guy", "Muddy Waters", "Eric Clapton"].randomElement()!
|
||||
let version = ["3.11", "3.12"].randomElement()!
|
||||
let rating = Int.random(in: 1...5)
|
||||
let title = ["Awesome app", "Could be better", "Gimme my money back!!", "Lemme tell you a story..."].randomElement()!
|
||||
let id = UUID().uuidString
|
||||
let content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
||||
return Review(author: author,
|
||||
version: version,
|
||||
rating: rating,
|
||||
title: title,
|
||||
id: id,
|
||||
content: content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// AppStoreReviews
|
||||
//
|
||||
// Created by Dmitrii Ivanov on 21/07/2020.
|
||||
// Copyright © 2020 ING. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Review {
|
||||
let author: String
|
||||
let version: String
|
||||
let rating: Int
|
||||
let title: String
|
||||
let id: String
|
||||
let content: String
|
||||
|
||||
func ratingVersionText() -> String {
|
||||
var stars = ""
|
||||
for _ in 0..<rating {
|
||||
stars += "⭐️"
|
||||
}
|
||||
return "\(stars) (ver: \(version))"
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// AppStoreReviews
|
||||
//
|
||||
// Created by Dmitrii Ivanov on 21/07/2020.
|
||||
// Copyright © 2020 ING. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class ReviewCell: UITableViewCell {
|
||||
|
||||
private var titleLabel = UILabel()
|
||||
private var authorLabel = UILabel()
|
||||
private var textPreviewLabel = UILabel()
|
||||
private var ratingVersionLabel = UILabel()
|
||||
|
||||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||
|
||||
setupLabels()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func update(item: Review) {
|
||||
ratingVersionLabel.text = item.ratingVersionText()
|
||||
authorLabel.text = "from: \(item.author)"
|
||||
titleLabel.text = "\(item.title)"
|
||||
textPreviewLabel.text = "\(item.content)"
|
||||
}
|
||||
|
||||
private func setupLabels() {
|
||||
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
authorLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
textPreviewLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
ratingVersionLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
titleLabel.font = UIFont.boldSystemFont(ofSize: 18)
|
||||
titleLabel.numberOfLines = 2
|
||||
ratingVersionLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
||||
authorLabel.font = UIFont.italicSystemFont(ofSize: 18)
|
||||
textPreviewLabel.font = UIFont.systemFont(ofSize: 14)
|
||||
textPreviewLabel.numberOfLines = 3
|
||||
|
||||
let stack = UIStackView()
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
contentView.addSubview(stack)
|
||||
stack.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 8).isActive = true
|
||||
stack.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -8).isActive = true
|
||||
stack.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8).isActive = true
|
||||
stack.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -8).isActive = true
|
||||
|
||||
stack.axis = .vertical
|
||||
stack.distribution = .equalSpacing
|
||||
stack.alignment = .leading
|
||||
|
||||
stack.addArrangedSubview(ratingVersionLabel)
|
||||
stack.addArrangedSubview(authorLabel)
|
||||
stack.addArrangedSubview(titleLabel)
|
||||
stack.addArrangedSubview(textPreviewLabel)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user