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

laurentian1 - 🐧 🐧 🚀 (Penguin-Penguin-Rocket) Mirego Submission #14

Open
wants to merge 3 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
35 changes: 35 additions & 0 deletions SOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Team

**Team Name:** {🐧 🐧 🚀 (Penguin-Penguin-Rocket)}
**Team Code:** {laurentian1}
**University:** {Laurentian University}

**Authors:**
- {Nicholas Mercier}
- {Kaitlynn Anderson-Butcher}

## Solution

**Platform:** {iOS}

**Features:**
1. {A really good part list is up and ready for action! Displays the name, description, and location, like the example provided}
2. {Changed the views to be UITableView/UITableViewCell as it felt more appropriate for the task.}
3. {Ability to access the mapping from AWS, and parse the JSON directly into a list of NSDictionary, which is nice to quickly get information from.}

**Build Steps:**
- {We did not touch anything with the pod file, etc. So just run and go to see the part list!}

**What went well or wrong:**
- {The base project was helpful to get our feet off the ground and get a handle of what was going on.}
- {The rubric and outline were great, you knew exactly what you had to do. }
- {Some minor problems in trying to get the data to populate our table set us back a little}
- {Using iOS simulator made getting the current location difficult}

**What you are proud or disappointed of:**
- {We really liked the fact that we could implement the part list dynamically }
- {We were really disappointed we could not make it to the AR, that looked really cool.}
- {Implementing table views, since we think that is how it should be done on iOS}

- {The map got away from us unfortunately }
- {We could not get the location simulator to work so we could test our solution. Theoretically it should though}
4 changes: 4 additions & 0 deletions ios/MapPing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
67233D2E2067178D00855EFA /* URLService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67233D2D2067178D00855EFA /* URLService.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 +39,7 @@
/* 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>"; };
67233D2D2067178D00855EFA /* URLService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLService.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 @@ -125,6 +127,7 @@
isa = PBXGroup;
children = (
F1196A872065357A0084672D /* Observable.swift */,
67233D2D2067178D00855EFA /* URLService.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -430,6 +433,7 @@
F1196A782064857D0084672D /* PartAnnotation.swift in Sources */,
F1196A7A2064928E0084672D /* NavigationViewController.swift in Sources */,
F19EA0A72061C58400FE9A5E /* RootViewController.swift in Sources */,
67233D2E2067178D00855EFA /* URLService.swift in Sources */,
F1196A76206481B60084672D /* PartAnnotationView.swift in Sources */,
F19EA0B72061C6C100FE9A5E /* ListViewController.swift in Sources */,
F19EA0BB2061C6DC00FE9A5E /* MapView.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion ios/MapPing/Classes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window!.tintColor = .primary
window!.rootViewController = viewControllerFactory.rootViewController()
window!.makeKeyAndVisible()

return true
}

Expand Down
39 changes: 39 additions & 0 deletions ios/MapPing/Classes/Helpers/URLService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// URLService.swift
// MapPing
//
// Created by Nicholas Mercier on 2018-03-24.
// Copyright © 2018 Mirego. All rights reserved.
//

import Foundation

open class URLService {

/*
* Get the JSON file from the server, and callback with an
* array of NSDictionary(s).
*/
open class func getData(completion: @escaping (_ data:Array<NSDictionary>)->()){

guard let url = URL(string: "https://s3.amazonaws.com/shared.ws.mirego.com/competition/mapping.json") else { return }

URLSession.shared.dataTask(with: url){ data, response, error in

guard let data = data else {
print("Error 1")
return
}

do {
let arr = try JSONSerialization.jsonObject(with: data) as! Array<NSDictionary>
DispatchQueue.main.async { completion(arr) }
} catch let error as NSError {
print(error)
}

}.resume()

}

}
60 changes: 55 additions & 5 deletions ios/MapPing/Classes/UI/List/ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@

import UIKit

class ListView: UIView {

class ListView: UITableView {
private let partCellView = PartCellView()

private let reuse = "item"

var itemData:Array<NSDictionary>?

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

self.delegate = self
self.dataSource = self
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.register(PartCellView.self, forCellReuseIdentifier: reuse)

partCellView.configure(partImageName: "part-sensor", title: "Bougie 4W", subTitle: "Moteur principal", coordinates: "46.7552° N, 71.2265° W", distance: "(0.62 km)")
addSubview(partCellView)
// Use the URLService to retrieve the part data.
URLService.getData(){ json in
self.itemData = json
self.reloadData()
}
}

required init(coder aDecoder: NSCoder) {
Expand All @@ -27,4 +39,42 @@ class ListView: UIView {
super.layoutSubviews()
partCellView.pin.top().horizontally()
}

override func numberOfRows(inSection section: Int) -> Int {
return (itemData == nil) ? 0 : itemData!.count
}

}

extension ListView : UITableViewDelegate, UITableViewDataSource {

/*
* Specify the table cell height.
*/
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100.0
}

/*
* Get number of rows, which corresponds the the number of
* items in the itemData. If itemData is nil, 0 is returned.
*/
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (itemData == nil) ? 0 : itemData!.count
}

/*
* Handle reusing table cells. The PartCellView cells are updated
* with the data the corresponds to the matching index in itemData.
*/
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reuse, for: indexPath as IndexPath)
if let part = cell as? PartCellView {
if let itemData = itemData {
part.configure(dict: itemData[indexPath.row])
}
}
return cell
}

}
23 changes: 23 additions & 0 deletions ios/MapPing/Classes/UI/List/ListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
//

import UIKit
import CoreLocation

class ListViewController: BaseViewController {

// Static member to store any location updates to.
static var location:CLLocation?

var locationManager:CLLocationManager?

private var mainView: ListView {
return self.view as! ListView
}
Expand All @@ -20,6 +26,15 @@ class ListViewController: BaseViewController {
super.init(nibName: nil, bundle: nil)
title = "Map Ping"
navigationIcon = #imageLiteral(resourceName: "icn-list")

// Prepare location manager to get the user's current location.
if CLLocationManager.locationServicesEnabled() {
locationManager = CLLocationManager()
locationManager?.delegate = self
locationManager?.desiredAccuracy = kCLLocationAccuracyBest
locationManager?.startUpdatingLocation()
}

}

required init(coder aDecoder: NSCoder) {
Expand All @@ -42,3 +57,11 @@ class ListViewController: BaseViewController {
}
}
}

// Extension to handle CLLocationManagerDelegate functions.
extension ListViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last! as CLLocation
ListViewController.location = location
}
}
37 changes: 34 additions & 3 deletions ios/MapPing/Classes/UI/List/Subviews/PartCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
//

import UIKit
import CoreLocation

class PartCellView: UIView {
class PartCellView: UITableViewCell {

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

init() {
super.init(frame: .zero)
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: .default, reuseIdentifier: "item")

partImage.backgroundColor = .white
partImage.contentMode = .center
Expand Down Expand Up @@ -63,5 +64,35 @@ class PartCellView: UIView {
self.distance.setProperties(text: distance, fit: true)
setNeedsLayout()
}

/*
* Utility function to take a dictionary retrieved from the
* server, and set the view components to match the information.
*/
func configure(dict:NSDictionary) {
let name = dict["name"] as! String
let type = dict["type"] as! String
let component = dict["component"] as! String
let lat = dict["lat"] as? Double
let lon = dict["lon"] as? Double
let address = dict["address"] as? String

var description = "Unavailable"
var distance = ""
if lat != nil && lon != nil {
description = "\(lat!)°N, \(lon!)°W"
if let location = ListViewController.location {
let here = CLLocation(latitude: lat!, longitude: lon!)
let d = (location.distance(from: here) / 1000 * 10).rounded() / 10
distance = "\(d)km"
}
} else if let address = address {
description = address
}

self.configure(partImageName: "part-\(type)", title: name, subTitle: component, coordinates: description, distance: distance)

setNeedsLayout()
}
}