Skip to content

Commit

Permalink
Replace LicenseVC with a table view displaying the licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrpb committed Oct 2, 2019
1 parent 9d2561f commit 4fce65c
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 136 deletions.
6 changes: 5 additions & 1 deletion AltStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 50;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -216,6 +216,7 @@
BFF0B696232242D3007A79E1 /* LicensesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0B695232242D3007A79E1 /* LicensesViewController.swift */; };
BFF0B6982322CAB8007A79E1 /* InstructionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0B6972322CAB8007A79E1 /* InstructionsViewController.swift */; };
BFF0B69A2322D7D0007A79E1 /* UIScreen+CompactHeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF0B6992322D7D0007A79E1 /* UIScreen+CompactHeight.swift */; };
D703E93423448AFD00D793A1 /* LicenseTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D703E93323448AFD00D793A1 /* LicenseTableViewCell.swift */; };
D7220EBB23436669000CAE4C /* licenses.json in Resources */ = {isa = PBXBuildFile; fileRef = D7220EBA23436669000CAE4C /* licenses.json */; };
DBAC68F8EC03F4A41D62EDE1 /* Pods_AltStore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1039C07E517311FC499A0B64 /* Pods_AltStore.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -502,6 +503,7 @@
BFF0B695232242D3007A79E1 /* LicensesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicensesViewController.swift; sourceTree = "<group>"; };
BFF0B6972322CAB8007A79E1 /* InstructionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstructionsViewController.swift; sourceTree = "<group>"; };
BFF0B6992322D7D0007A79E1 /* UIScreen+CompactHeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScreen+CompactHeight.swift"; sourceTree = "<group>"; };
D703E93323448AFD00D793A1 /* LicenseTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LicenseTableViewCell.swift; sourceTree = "<group>"; };
D7220EBA23436669000CAE4C /* licenses.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = licenses.json; sourceTree = "<group>"; };
EA79A60285C6AF5848AA16E9 /* Pods-AltStore.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AltStore.debug.xcconfig"; path = "Target Support Files/Pods-AltStore/Pods-AltStore.debug.xcconfig"; sourceTree = "<group>"; };
FC3822AB1C4CF1D4CDF7445D /* Pods_AltServer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AltServer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1032,6 +1034,7 @@
BFF0B68F23219C6D007A79E1 /* PatreonComponents.swift */,
BFF0B6912321A305007A79E1 /* AboutPatreonHeaderView.xib */,
BFF0B695232242D3007A79E1 /* LicensesViewController.swift */,
D703E93323448AFD00D793A1 /* LicenseTableViewCell.swift */,
);
path = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -1529,6 +1532,7 @@
BFF0B69023219C6D007A79E1 /* PatreonComponents.swift in Sources */,
BF770E5622BC3C03002A40FE /* Server.swift in Sources */,
BF43003022A71C960051E2BC /* UserDefaults+AltStore.swift in Sources */,
D703E93423448AFD00D793A1 /* LicenseTableViewCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 15 additions & 0 deletions AltStore/Settings/LicenseTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// LicenseTableViewCell.swift
// AltStore
//
// Created by Kevin Romero Peces-Barba on 02/10/2019.
// Copyright © 2019 Riley Testut. All rights reserved.
//

import UIKit

class LicenseTableViewCell: InsetGroupTableViewCell
{
@IBOutlet var productLabel: UILabel!
@IBOutlet var authorLabel: UILabel!
}
84 changes: 55 additions & 29 deletions AltStore/Settings/LicensesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,68 @@

import UIKit

class LicensesViewController: UIViewController
fileprivate let PRODUCT_TAG = 10
fileprivate let AUTHOR_TAG = 20

class LicensesViewController: UITableViewController
{
private var _didAppear = false

@IBOutlet private var textView: UITextView!

override func viewWillAppear(_ animated: Bool)
private var licenses: [[String: String]] = []

override func viewDidLoad()
{
super.viewWillAppear(animated)

self.view.setNeedsLayout()
self.view.layoutIfNeeded()

// Fix incorrect initial offset on iPhone SE.
self.textView.contentOffset.y = 0
super.viewDidLoad()
loadLicenses()
}
override func viewDidAppear(_ animated: Bool)

private func loadLicenses()
{
super.viewDidAppear(animated)

_didAppear = true
guard let path = Bundle.main.path(forResource: "licenses", ofType: "json") else {
dismiss(animated: true)
return
}

let url = URL(fileURLWithPath: path)

guard let data = try? Data(contentsOf: url), let json = try? JSONSerialization.jsonObject(with: data) as? [[String: String]] else {
dismiss(animated: true)
return
}

licenses = json
}
}

override func viewDidLayoutSubviews()
extension LicensesViewController
{
override func numberOfSections(in tableView: UITableView) -> Int
{
super.viewDidLayoutSubviews()

self.textView.textContainerInset.left = self.view.layoutMargins.left
self.textView.textContainerInset.right = self.view.layoutMargins.right
self.textView.textContainer.lineFragmentPadding = 0

if !_didAppear
{
// Fix incorrect initial offset on iPhone SE.
self.textView.contentOffset.y = 0
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return licenses.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "licenseListCell", for: indexPath) as! LicenseTableViewCell
let license = licenses[indexPath.row]

switch indexPath.row {
case 0:
cell.style = .top
break
case licenses.count - 1:
cell.style = .bottom
break
default:
cell.style = .middle
}

cell.productLabel.text = license["product"]
cell.authorLabel.text = license["author"]

return cell
}
}
Loading

0 comments on commit 4fce65c

Please sign in to comment.