Commit 6f8a842f authored by domenicw's avatar domenicw
Browse files

JobOffer PDFs are now shown

JobOffers and Events is now localized
parent c9d655b9
......@@ -93,7 +93,6 @@
B0FE2F1221550C0100F3D073 /* JobsViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F1121550C0100F3D073 /* JobsViewControllerDelegate.swift */; };
B0FE2F1421550C4400F3D073 /* EventsViewControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F1321550C4400F3D073 /* EventsViewControllerDelegate.swift */; };
B0FE2F16215514E600F3D073 /* QuickLookDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F15215514E600F3D073 /* QuickLookDataSource.swift */; };
B0FE2F182155167F00F3D073 /* Dienstverschiebungsgesuch.pdf in Resources */ = {isa = PBXBuildFile; fileRef = B0FE2F172155167F00F3D073 /* Dienstverschiebungsgesuch.pdf */; };
B0FE2F1B21552A9D00F3D073 /* KeychainSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F1A21552A9D00F3D073 /* KeychainSwift.swift */; };
B0FE2F1D21552AC800F3D073 /* KeychainSwiftAccessOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F1C21552AC800F3D073 /* KeychainSwiftAccessOptions.swift */; };
B0FE2F1F21552AF700F3D073 /* KeychainSwiftConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0FE2F1E21552AF700F3D073 /* KeychainSwiftConstants.swift */; };
......@@ -203,7 +202,6 @@
B0FE2F1121550C0100F3D073 /* JobsViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JobsViewControllerDelegate.swift; sourceTree = "<group>"; };
B0FE2F1321550C4400F3D073 /* EventsViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventsViewControllerDelegate.swift; sourceTree = "<group>"; };
B0FE2F15215514E600F3D073 /* QuickLookDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickLookDataSource.swift; sourceTree = "<group>"; };
B0FE2F172155167F00F3D073 /* Dienstverschiebungsgesuch.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Dienstverschiebungsgesuch.pdf; sourceTree = "<group>"; };
B0FE2F1A21552A9D00F3D073 /* KeychainSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainSwift.swift; sourceTree = "<group>"; };
B0FE2F1C21552AC800F3D073 /* KeychainSwiftAccessOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainSwiftAccessOptions.swift; sourceTree = "<group>"; };
B0FE2F1E21552AF700F3D073 /* KeychainSwiftConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainSwiftConstants.swift; sourceTree = "<group>"; };
......@@ -284,7 +282,6 @@
B050E13F2151695A0090CB79 /* Base */ = {
isa = PBXGroup;
children = (
B0FE2F172155167F00F3D073 /* Dienstverschiebungsgesuch.pdf */,
B050E11F215169230090CB79 /* AppDelegate.swift */,
B050E126215169250090CB79 /* Assets.xcassets */,
B050E128215169250090CB79 /* LaunchScreen.storyboard */,
......@@ -826,7 +823,6 @@
files = (
B050E12A215169250090CB79 /* LaunchScreen.storyboard in Resources */,
B050E127215169250090CB79 /* Assets.xcassets in Resources */,
B0FE2F182155167F00F3D073 /* Dienstverschiebungsgesuch.pdf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
......@@ -10,13 +10,13 @@ import Foundation
public extension Locale {
public enum AppLanguage {
case german
case english
public enum AppLanguage: String {
case german = "de"
case english = "en"
}
public static func current() -> AppLanguage {
if ["de-DE", "de-CH", "de-AT", "de-LI", "de-LU"].contains(Locale.current.languageCode) {
if let language = Locale.preferredLanguages.first, language == AppLanguage.german.rawValue {
return .german
} else {
return .english
......
......@@ -95,11 +95,11 @@ extension JobsNavigator: GenericInfoViewControllerDelegate {
// TODO: - Show job description pdf using QLPreviewController
// https://www.hackingwithswift.com/example-code/libraries/how-to-preview-files-using-quick-look-and-qlpreviewcontroller
guard case .openPDF(let path) = action else {
guard case .openMedia(let media) = action else {
return
}
self.manager.getMedia(for: path) { (url, error) in
self.manager.getMedia(for: media.filePath, named: media.name) { (url, error) in
guard error == nil, let url = url else {
return
}
......@@ -112,14 +112,6 @@ extension JobsNavigator: GenericInfoViewControllerDelegate {
self.navigationController.present(quickLook, animated: true, completion: nil)
}
}
/*
let url = Bundle.main.url(forResource: "Dienstverschiebungsgesuch", withExtension: "pdf")!
let quickLook = QLPreviewController()
let dataSource = QuickLookDataSource(urls: [url])
self.quickLookDataSource = dataSource
quickLook.dataSource = dataSource
self.navigationController.present(quickLook, animated: true, completion: nil)
*/
}
}
......@@ -133,8 +133,8 @@ extension NetworkManager where EndPoint == AMIVApiJobs {
}
}
public func getMedia(for path: String, _ completion: @escaping (_ url: URL?, _ error: String?) -> Void) {
router.download(.media(path)) { (url, response, error) in
public func getMedia(for path: String, named: String, _ completion: @escaping (_ url: URL?, _ error: String?) -> Void) {
router.download(.media(path), named) { (url, response, error) in
guard error == nil else {
completion(nil, error?.localizedDescription)
return
......
......@@ -18,6 +18,6 @@ public protocol NetworkRouter: class {
func request(_ route: EndPoint, completion: @escaping NetworkRouterRequestCompletion)
func download(_ route: EndPoint, completion: @escaping NetworkRouterDownloadCompletion)
func download(_ route: EndPoint, _ named: String, completion: @escaping NetworkRouterDownloadCompletion)
}
......@@ -26,26 +26,28 @@ public class Router<EndPoint: EndPointType>: NetworkRouter {
}
}
public func download(_ route: EndPoint, completion: @escaping NetworkRouterDownloadCompletion) {
public func download(_ route: EndPoint, _ fileName: String, completion: @escaping NetworkRouterDownloadCompletion) {
let session = URLSession.shared
do {
let request = try self.buildRequest(from: route)
let task = session.downloadTask(with: request) { (tempURL, response, error) in
guard let url = tempURL else {
completion(tempURL, response, error)
guard let tempURL = tempURL else {
completion(nil, response, error)
return
}
let documentsURL:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationURL = documentsURL.appendingPathComponent(fileName)
do {
let data = try Data(contentsOf: url)
let documentsURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let savedURL = documentsURL.appendingPathComponent("jobApplication.pdf")
FileManager.default.createFile(atPath: savedURL.path, contents: data, attributes: nil)
completion(savedURL, response, error)
if FileManager.default.fileExists(atPath: destinationURL.path) {
try FileManager.default.removeItem(at: destinationURL)
}
try FileManager.default.copyItem(at: tempURL, to: destinationURL)
completion(destinationURL, response, error)
} catch {
debugPrint(error.localizedDescription)
completion(nil, response, error)
}
completion(url, response, error)
}
self.tasks.append(task)
task.resume()
......
......@@ -93,6 +93,7 @@ extension EventsViewController {
}()
cell.textLabel?.text = self.model.events[indexPath.row].title
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.text = self.model.events[indexPath.row].catchPhrase
return cell
......
......@@ -11,7 +11,7 @@ import Foundation
public enum GenericInfoViewControllerAction {
case `default`
case openPDF(String)
case signup(_ eventID: String)
case openMedia(AMIVMedia)
case signup(String)
}
......@@ -38,7 +38,7 @@ public struct GenericInfoViewControllerModel {
self.image = image
self.text = jobOffer.description
self.titleButton = "View Job Offer (PDF)"
self.action = .openPDF(jobOffer.pdf.filePath)
self.action = .openMedia(jobOffer.pdf)
}
public init(event: AMIVEvent, image: UIImage?) {
self.title = event.title
......
......@@ -96,6 +96,7 @@ extension JobsViewController {
}()
cell.textLabel?.text = model.title
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.text = model.company
return cell
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment