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