mirror of
https://github.com/SideStore/SideStore.git
synced 2026-04-05 02:05:40 +02:00
Adds basic AppsViewController implementation
This commit is contained in:
53
AltStore/Apps/AppTableViewCell.swift
Normal file
53
AltStore/Apps/AppTableViewCell.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// AppTableViewCell.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/9/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@objc class AppTableViewCell: UITableViewCell
|
||||
{
|
||||
@IBOutlet var nameLabel: UILabel!
|
||||
@IBOutlet var subtitleLabel: UILabel!
|
||||
@IBOutlet var appIconImageView: UIImageView!
|
||||
@IBOutlet var button: UIButton!
|
||||
|
||||
override func awakeFromNib()
|
||||
{
|
||||
super.awakeFromNib()
|
||||
|
||||
self.selectionStyle = .none
|
||||
}
|
||||
|
||||
override func setHighlighted(_ highlighted: Bool, animated: Bool)
|
||||
{
|
||||
super.setHighlighted(highlighted, animated: animated)
|
||||
|
||||
self.update()
|
||||
}
|
||||
|
||||
override func setSelected(_ selected: Bool, animated: Bool)
|
||||
{
|
||||
super.setSelected(selected, animated: animated)
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppTableViewCell
|
||||
{
|
||||
func update()
|
||||
{
|
||||
if self.isHighlighted || self.isSelected
|
||||
{
|
||||
self.contentView.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
|
||||
}
|
||||
else
|
||||
{
|
||||
self.contentView.backgroundColor = .white
|
||||
}
|
||||
}
|
||||
}
|
||||
52
AltStore/Apps/AppsViewController.swift
Normal file
52
AltStore/Apps/AppsViewController.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// AppsViewController.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/9/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Roxas
|
||||
|
||||
class AppsViewController: UITableViewController
|
||||
{
|
||||
private lazy var dataSource = self.makeDataSource()
|
||||
|
||||
override func viewDidLoad()
|
||||
{
|
||||
super.viewDidLoad()
|
||||
|
||||
self.tableView.dataSource = self.dataSource
|
||||
|
||||
// Hide trailing row separators.
|
||||
self.tableView.tableFooterView = UIView()
|
||||
}
|
||||
}
|
||||
|
||||
private extension AppsViewController
|
||||
{
|
||||
func makeDataSource() -> RSTArrayTableViewDataSource<App>
|
||||
{
|
||||
let appsFileURL = Bundle.main.url(forResource: "Apps", withExtension: "plist")!
|
||||
|
||||
do
|
||||
{
|
||||
let data = try Data(contentsOf: appsFileURL)
|
||||
let apps = try PropertyListDecoder().decode([App].self, from: data)
|
||||
|
||||
let dataSource = RSTArrayTableViewDataSource(items: apps)
|
||||
dataSource.cellConfigurationHandler = { (cell, app, indexPath) in
|
||||
let cell = cell as! AppTableViewCell
|
||||
cell.nameLabel.text = app.name
|
||||
cell.subtitleLabel.text = app.subtitle
|
||||
cell.appIconImageView.image = UIImage(named: app.iconName)
|
||||
}
|
||||
return dataSource
|
||||
}
|
||||
catch
|
||||
{
|
||||
fatalError("Failed to load apps. \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user