app-reviews/Frameworks/Feed/Sources/FeedViewController.swift
Javier Cicchelli 8fc4bb165e [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: #2
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
2024-03-16 00:28:59 +00:00

59 lines
2.4 KiB
Swift

//
// AppDelegate.swift
// AppStoreReviews
//
// Created by Dmitrii Ivanov on 21/07/2020.
// Copyright © 2020 ING. All rights reserved.
//
import UIKit
public class FeedViewController: UITableViewController {
public init() {
super.init(style: .plain)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func viewDidLoad() {
super.viewDidLoad()
tableView.register(ReviewCell.self, forCellReuseIdentifier: "cellId")
tableView.rowHeight = 160
}
public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
public 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
}
public 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)
}
}