Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uqam2 - PFK - Pingouin Frit Kébec #24

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions ios/MapPing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
665624242067128700F37197 /* HttpService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 665624232067128700F37197 /* HttpService.swift */; };
6656242820671A7900F37197 /* FailableDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6656242720671A7900F37197 /* FailableDecodable.swift */; };
6656242A20671BE300F37197 /* PartType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6656242920671BE300F37197 /* PartType.swift */; };
6656242D20672F4900F37197 /* DetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6656242C20672F4900F37197 /* DetailsView.swift */; };
6656242F20672F5600F37197 /* DetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6656242E20672F5600F37197 /* DetailsViewController.swift */; };
93695A4C20671488007D1410 /* PartClusterAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93695A4B20671488007D1410 /* PartClusterAnnotationView.swift */; };
940F0B61F668AD88441334C2 /* Pods_MapPing.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 16CD00BB887C10CE3E91B52C /* Pods_MapPing.framework */; };
F1196A76206481B60084672D /* PartAnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1196A75206481B60084672D /* PartAnnotationView.swift */; };
F1196A782064857D0084672D /* PartAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1196A772064857D0084672D /* PartAnnotation.swift */; };
Expand Down Expand Up @@ -38,6 +44,12 @@
/* Begin PBXFileReference section */
16CD00BB887C10CE3E91B52C /* Pods_MapPing.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MapPing.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4BFA57CDB381CDA05A7C2162 /* Pods-MapPing.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MapPing.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MapPing/Pods-MapPing.debug.xcconfig"; sourceTree = "<group>"; };
665624232067128700F37197 /* HttpService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpService.swift; sourceTree = "<group>"; };
6656242720671A7900F37197 /* FailableDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FailableDecodable.swift; sourceTree = "<group>"; };
6656242920671BE300F37197 /* PartType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartType.swift; sourceTree = "<group>"; };
6656242C20672F4900F37197 /* DetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsView.swift; sourceTree = "<group>"; };
6656242E20672F5600F37197 /* DetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailsViewController.swift; sourceTree = "<group>"; };
93695A4B20671488007D1410 /* PartClusterAnnotationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartClusterAnnotationView.swift; sourceTree = "<group>"; };
E901EFF955E9ACF4A910DAE7 /* Pods-MapPing.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MapPing.release.xcconfig"; path = "Pods/Target Support Files/Pods-MapPing/Pods-MapPing.release.xcconfig"; sourceTree = "<group>"; };
F1196A75206481B60084672D /* PartAnnotationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartAnnotationView.swift; sourceTree = "<group>"; };
F1196A772064857D0084672D /* PartAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartAnnotation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,6 +101,15 @@
name = Pods;
sourceTree = "<group>";
};
6656242B20672F0000F37197 /* Details */ = {
isa = PBXGroup;
children = (
6656242E20672F5600F37197 /* DetailsViewController.swift */,
6656242C20672F4900F37197 /* DetailsView.swift */,
);
path = Details;
sourceTree = "<group>";
};
6DAB11BEC4EE23ADF3FF7B54 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand All @@ -101,6 +122,7 @@
isa = PBXGroup;
children = (
F1196A75206481B60084672D /* PartAnnotationView.swift */,
93695A4B20671488007D1410 /* PartClusterAnnotationView.swift */,
);
path = Subviews;
sourceTree = "<group>";
Expand Down Expand Up @@ -143,6 +165,8 @@
isa = PBXGroup;
children = (
F1196A8D20653B660084672D /* Part.swift */,
6656242720671A7900F37197 /* FailableDecodable.swift */,
6656242920671BE300F37197 /* PartType.swift */,
);
path = Model;
sourceTree = "<group>";
Expand All @@ -151,6 +175,7 @@
isa = PBXGroup;
children = (
F1196A8F20653D4A0084672D /* PartService.swift */,
665624232067128700F37197 /* HttpService.swift */,
);
path = Service;
sourceTree = "<group>";
Expand Down Expand Up @@ -215,6 +240,7 @@
F19EA0A42061C56600FE9A5E /* UI */ = {
isa = PBXGroup;
children = (
6656242B20672F0000F37197 /* Details */,
F19EA0B12061C68C00FE9A5E /* AugmentedReality */,
F19EA0AA2061C5B400FE9A5E /* Common */,
F19EA0AF2061C66800FE9A5E /* Map */,
Expand Down Expand Up @@ -419,11 +445,16 @@
F19EA0AC2061C5BE00FE9A5E /* BaseViewController.swift in Sources */,
F19EA0AE2061C5E800FE9A5E /* RootView.swift in Sources */,
F19EA0C22061DA7E00FE9A5E /* Stylesheet.swift in Sources */,
6656242820671A7900F37197 /* FailableDecodable.swift in Sources */,
6656242A20671BE300F37197 /* PartType.swift in Sources */,
F1196A92206541700084672D /* ServiceFactory.swift in Sources */,
F1196A8420649D580084672D /* PartCellView.swift in Sources */,
F19EA0A92061C59B00FE9A5E /* ViewControllerFactory.swift in Sources */,
F1196A9020653D4A0084672D /* PartService.swift in Sources */,
F19EA0902061C36000FE9A5E /* AppDelegate.swift in Sources */,
6656242F20672F5600F37197 /* DetailsViewController.swift in Sources */,
6656242D20672F4900F37197 /* DetailsView.swift in Sources */,
93695A4C20671488007D1410 /* PartClusterAnnotationView.swift in Sources */,
F19EA0B32061C6A800FE9A5E /* AugmentedRealityViewController.swift in Sources */,
F1196A8E20653B660084672D /* Part.swift in Sources */,
F19EA0C02061CB7100FE9A5E /* NavigationButtons.swift in Sources */,
Expand All @@ -432,6 +463,7 @@
F19EA0A72061C58400FE9A5E /* RootViewController.swift in Sources */,
F1196A76206481B60084672D /* PartAnnotationView.swift in Sources */,
F19EA0B72061C6C100FE9A5E /* ListViewController.swift in Sources */,
665624242067128700F37197 /* HttpService.swift in Sources */,
F19EA0BB2061C6DC00FE9A5E /* MapView.swift in Sources */,
F19EA0BD2061C6E300FE9A5E /* ListView.swift in Sources */,
F19EA0B52061C6B300FE9A5E /* MapViewController.swift in Sources */,
Expand Down Expand Up @@ -567,7 +599,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 4Q596JWQC5;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/MapPing/SupportingFiles/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mirego.MapPing;
Expand All @@ -583,7 +615,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 4Q596JWQC5;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = "$(SRCROOT)/MapPing/SupportingFiles/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mirego.MapPing;
Expand Down
17 changes: 17 additions & 0 deletions ios/MapPing/Classes/Domain/Model/FailableDecodable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// FailableDecodable.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

struct FailableDecodable<Base : Decodable> : Decodable {

let base: Base?

init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
self.base = try? container.decode(Base.self)
}
}
12 changes: 10 additions & 2 deletions ios/MapPing/Classes/Domain/Model/Part.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
struct Part: Codable {
enum CodingKeys: String, CodingKey {
case name
case component
case notes
case type
case latitude = "lat"
case longitude = "lon"
case address
}

let name: String
let latitude: Float
let longitude: Float
let component: String
let notes: String
let type: PartType
let latitude: Double
let longitude: Double
let address: String
}
40 changes: 40 additions & 0 deletions ios/MapPing/Classes/Domain/Model/PartType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// PartType.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

enum PartType: String, Codable {
case battery
case bulb
case cable
case chain
case clutch
case coil
case dial
case disk
case fan
case filter
case fuel
case gear
case generator
case heads
case hose
case mag
case mount
case piston
case plugs
case radiator
case regulator
case reservoir
case scanner
case sensor
case shaft
case sink
case sparkplug
case turbo
case valve
case wheel
}
12 changes: 12 additions & 0 deletions ios/MapPing/Classes/Domain/Model/Parts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Parts.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

struct Parts: Codable {
let data: [Part]
}

23 changes: 23 additions & 0 deletions ios/MapPing/Classes/Domain/Service/HttpService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// HttpService.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

import Foundation

class HttpService {

static func get(url: String, completion: @escaping (_ data: Data?, _ error: Error?) -> ()) {
guard let queryUrl = URL(string: url) else {
completion(nil, NSError(domain: "HttpService", code: -1, userInfo: ["description" : "Invalid url"]))
return
}

URLSession.shared.dataTask(with: queryUrl) { (data, urlResponse, error) in
DispatchQueue.main.async { completion(data, error) }
}.resume()
}
}
20 changes: 16 additions & 4 deletions ios/MapPing/Classes/Domain/Service/PartService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@
// Copyright © 2018 Mirego. All rights reserved.
//

import Foundation
import UIKit

class PartService {
private let partsUrl = URL(string: "https://s3.amazonaws.com/shared.ws.mirego.com/competition/mapping.json")!
let partsUrl = "https://s3.amazonaws.com/shared.ws.mirego.com/competition/mapping.json"

var partsObservable = Observable<[Part]>()

func refreshParts() {
partsObservable.notify(data: [])
// TODO 🙄
HttpService.get(url: partsUrl) { (data, error) in
guard let data = data else {
return
}
do {
let partsData = try JSONDecoder()
.decode([FailableDecodable<Part>].self, from: data)
.flatMap { $0.base }

self.partsObservable.notify(data:partsData)
} catch {
print("Error trying to convert data to JSON")
}
}
}
}
80 changes: 80 additions & 0 deletions ios/MapPing/Classes/UI/Details/DetailsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// DetailsView.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

import UIKit

class DetailsView: UIView {

private let partImage = UIImageView()
private let title = UILabel()
private let subTitle = UILabel()
private let coordinates = UILabel()
private let distance = UILabel()
private let address = UILabel()
private let notes = UILabel()

init() {
super.init(frame: .zero)
backgroundColor = .white

partImage.backgroundColor = .white
partImage.contentMode = .center
partImage.size = CGSize(width: 66, height: 66)
partImage.layer.cornerRadius = partImage.height / 2
partImage.layer.borderColor = UIColor.copper.cgColor
partImage.layer.borderWidth = 4
addSubview(partImage)

title.setProperties(font: .leagueSpartanBold(14), textColor: .purpleBrown)
addSubview(title)

subTitle.setProperties(font: .systemFont(ofSize: 12), textColor: .purpleBrown)
addSubview(subTitle)

coordinates.setProperties(font: .systemFont(ofSize: 12), textColor: .brownishGrey)
addSubview(coordinates)

distance.setProperties(font: .italicSystemFont(ofSize: 12), textColor: .brownishGrey)
addSubview(distance)

address.setProperties(font: .italicSystemFont(ofSize: 12), textColor: .brownishGrey)
addSubview(address)

notes.setProperties(font: .italicSystemFont(ofSize: 12), textColor: .brownishGrey)
addSubview(notes)
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()

partImage.pin.left(15).vCenter()
title.pin.right(of: partImage, aligned: .top).marginLeft(15).marginTop(8)
subTitle.pin.below(of: title, aligned: .left).marginTop(1)
coordinates.pin.below(of: subTitle, aligned: .left).marginTop(5)
distance.pin.right(of: coordinates, aligned: .center).marginLeft(6)
address.pin.below(of: partImage, aligned: .left).marginTop(8)
notes.pin.below(of: address, aligned: .left).marginTop(8)
}

func configure(part: Part) {
let coordinates = "\(part.latitude)° N, \(part.longitude)° W";

partImage.image = UIImage(named: "part-\(part.type)")
self.title.setProperties(text: part.name, fit: true)
self.subTitle.setProperties(text: part.component, fit: true)
self.coordinates.setProperties(text: coordinates, fit: true)
self.distance.setProperties(text: "(0.62 km)", fit: true)
self.coordinates.setProperties(text: coordinates, fit: true)
self.address.setProperties(text: part.address, fit: true)
self.notes.setProperties(text: part.notes, fit: true)
}
}
42 changes: 42 additions & 0 deletions ios/MapPing/Classes/UI/Details/DetailsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// DetailsViewController.swift
// MapPing
//
// Created by Quentin Nolan on 18-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

import UIKit

class DetailsViewController: BaseViewController {

private var mainView: DetailsView {
return self.view as! DetailsView
}

private let part: Part

init(part: Part) {
self.part = part
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

override func loadView() {
view = DetailsView()
}

override func viewDidLoad() {
super.viewDidLoad()

self.mainView.configure(part: part)
}

}
Loading