Add PDF support (#1596)

* Add string extension for searching pdf files (#1552)

* Create RepositoryWebViewController (#1552)

* Initial presenting of the pdf files (#1552)

* refactor: Rename String+Resource -> String+BinaryFile (#1552)

* Build destination URL (#1552)

* Configure title (#1552)

* Encode file path

* Use EmptyView for errors

* Replace UIWebView with WKWebView

* Review fixes

* refactor: Make binarySuffix computed property

* Unify if-else path

* Group guard statements
This commit is contained in:
Ivan Magda
2018-03-11 22:59:51 +03:00
committed by Ryan Nystrom
parent 50a4c9bdc6
commit 6c3c451677
4 changed files with 272 additions and 6 deletions

View File

@@ -130,23 +130,50 @@ ListSingleSectionControllerDelegate {
func didSelect(_ sectionController: ListSingleSectionController, with object: Any) {
guard let file = object as? RepositoryFile else { return }
let next = path.appending(file.name)
let controller: UIViewController
let nextPath = path.appending(file.name)
if file.isDirectory {
controller = RepositoryCodeDirectoryViewController(
client: client,
showDirectory(at: nextPath)
} else {
showFile(at: nextPath)
}
}
}
// MARK: - RepositoryCodeDirectoryViewController (Navigation) -
extension RepositoryCodeDirectoryViewController {
private func showDirectory(at path: FilePath) {
let controller = RepositoryCodeDirectoryViewController(
client: client,
repo: repo,
branch: branch,
path: path
)
navigationController?.pushViewController(controller, animated: trueUnlessReduceMotionEnabled)
}
private func showFile(at path: FilePath) {
let controller: UIViewController
if path.hasBinarySuffix {
controller = RepositoryWebViewController(
repo: repo,
branch: branch,
path: next
path: path
)
} else {
controller = RepositoryCodeBlobViewController(
client: client,
repo: repo,
branch: branch,
path: next
path: path
)
}
navigationController?.pushViewController(controller, animated: trueUnlessReduceMotionEnabled)
}