mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-14 17:23:25 +01:00
Adds basic AppDetailViewController implementation
This commit is contained in:
110
AltStore/Apps/AppDetailViewController.swift
Normal file
110
AltStore/Apps/AppDetailViewController.swift
Normal file
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// AppDetailViewController.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/9/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Roxas
|
||||
|
||||
@objc(ScreenshotCollectionViewCell)
|
||||
private class ScreenshotCollectionViewCell: UICollectionViewCell
|
||||
{
|
||||
@IBOutlet var imageView: UIImageView!
|
||||
}
|
||||
|
||||
extension AppDetailViewController
|
||||
{
|
||||
private enum Row: Int
|
||||
{
|
||||
case general
|
||||
case screenshots
|
||||
case description
|
||||
}
|
||||
}
|
||||
|
||||
class AppDetailViewController: UITableViewController
|
||||
{
|
||||
var app: App!
|
||||
|
||||
private lazy var screenshotsDataSource = self.makeScreenshotsDataSource()
|
||||
|
||||
@IBOutlet private var nameLabel: UILabel!
|
||||
@IBOutlet private var subtitleLabel: UILabel!
|
||||
@IBOutlet private var developerButton: UIButton!
|
||||
@IBOutlet private var appIconImageView: UIImageView!
|
||||
|
||||
@IBOutlet private var downloadButton: UIButton!
|
||||
|
||||
@IBOutlet private var screenshotsCollectionView: UICollectionView!
|
||||
|
||||
@IBOutlet private var descriptionLabel: UILabel!
|
||||
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
self.tableView.delegate = self
|
||||
self.screenshotsCollectionView.dataSource = self.screenshotsDataSource
|
||||
|
||||
self.update()
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews()
|
||||
{
|
||||
super.viewDidLayoutSubviews()
|
||||
|
||||
guard let image = self.screenshotsDataSource.items.first else { return }
|
||||
|
||||
let aspectRatio = image.size.width / image.size.height
|
||||
|
||||
let height = self.screenshotsCollectionView.bounds.height
|
||||
let width = self.screenshotsCollectionView.bounds.height * aspectRatio
|
||||
|
||||
let layout = self.screenshotsCollectionView.collectionViewLayout as! UICollectionViewFlowLayout
|
||||
layout.itemSize = CGSize(width: width, height: height)
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppDetailViewController
|
||||
{
|
||||
func update()
|
||||
{
|
||||
self.nameLabel.text = self.app.name
|
||||
self.subtitleLabel.text = self.app.subtitle
|
||||
self.developerButton.setTitle(self.app.developer, for: .normal)
|
||||
self.appIconImageView.image = UIImage(named: self.app.iconName)
|
||||
|
||||
let text = String(format: NSLocalizedString("Download %@", comment: ""), self.app.name)
|
||||
self.downloadButton.setTitle(text, for: .normal)
|
||||
|
||||
self.descriptionLabel.text = self.app.localizedDescription
|
||||
}
|
||||
|
||||
func makeScreenshotsDataSource() -> RSTArrayCollectionViewDataSource<UIImage>
|
||||
{
|
||||
let screenshots = self.app.screenshotNames.compactMap(UIImage.init(named:))
|
||||
|
||||
let dataSource = RSTArrayCollectionViewDataSource(items: screenshots)
|
||||
dataSource.cellConfigurationHandler = { (cell, screenshot, indexPath) in
|
||||
let cell = cell as! ScreenshotCollectionViewCell
|
||||
cell.imageView.image = screenshot
|
||||
}
|
||||
|
||||
return dataSource
|
||||
}
|
||||
}
|
||||
|
||||
extension AppDetailViewController
|
||||
{
|
||||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
|
||||
{
|
||||
guard indexPath.row == Row.screenshots.rawValue else { return super.tableView(tableView, heightForRowAt: indexPath) }
|
||||
guard !self.screenshotsDataSource.items.isEmpty else { return 0.0 }
|
||||
|
||||
let height = self.view.bounds.height * 0.67
|
||||
return height
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,18 @@ class AppsViewController: UITableViewController
|
||||
// Hide trailing row separators.
|
||||
self.tableView.tableFooterView = UIView()
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
|
||||
{
|
||||
guard segue.identifier == "showAppDetail" else { return }
|
||||
|
||||
guard let cell = sender as? UITableViewCell, let indexPath = self.tableView.indexPath(for: cell) else { return }
|
||||
|
||||
let app = self.dataSource.item(at: indexPath)
|
||||
|
||||
let appDetailViewController = segue.destination as! AppDetailViewController
|
||||
appDetailViewController.app = app
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppsViewController
|
||||
|
||||
Reference in New Issue
Block a user