Skip to content

Commit 548e8ff

Browse files
authored
Merge pull request #249 from merlos/enhancement/auto-recover-last-track
Auto recover last track instead of making a question upon launching the app.
2 parents b63c510 + ad594e3 commit 548e8ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+631
-397
lines changed

Diff for: .swiftlint.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
disabled_rules:
22
- trailing_whitespace
33
- nesting
4-
- variable_name
4+
- identifier_name
55

66
excluded:
77
- Pods
@@ -12,7 +12,7 @@ line_length: 150
1212
# try and remove these after we refactor some concerns out of the main view controller
1313
type_body_length:
1414
- 300 # warning
15-
- 665 # error
15+
- 800 # error
1616
function_body_length:
17-
- 40
18-
- 246
17+
- 50
18+
- 250

Diff for: OpenGpxTracker-Watch Extension/GPXFileTableInterfaceController.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
176176
if gpxFilesFound {
177177
for index in 0..<fileTable.numberOfRows {
178178
guard let cell = fileTable.rowController(at: index) as? GPXFileTableRowController else { continue }
179-
// swiftlint:disable force_cast
179+
// swiftlint:disable:next force_cast
180180
let gpxFileInfo = fileList.object(at: index) as! GPXFileInfo
181181
cell.fileLabel.setText(gpxFileInfo.fileName)
182182
}
@@ -232,7 +232,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
232232
self.hideProgressIndicators()
233233
return
234234
}
235-
// swiftlint:disable force_cast
235+
// swiftlint:disable:next force_cast
236236
let gpxFileInfo = fileList.object(at: rowIndex) as! GPXFileInfo
237237
self.scroll(to: progressGroup, at: .top, animated: true) // scrolls to top when indicator is shown.
238238
self.updateProgressIndicators(status: .sending, fileName: gpxFileInfo.fileName)
@@ -257,7 +257,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
257257
}
258258
GPXFileManager.removeFileFromURL(fileURL)
259259

260-
//Delete from list and Table
260+
// Delete from list and Table
261261
fileList.removeObject(at: rowIndex)
262262

263263
}

Diff for: OpenGpxTracker-Watch Extension/InterfaceController.swift

+21-36
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import MapKit
1111
import CoreLocation
1212
import CoreGPX
1313

14-
//Button colors
14+
// Button colors
1515
let kPurpleButtonBackgroundColor: UIColor = UIColor(red: 146.0/255.0, green: 166.0/255.0, blue: 218.0/255.0, alpha: 0.90)
1616
let kGreenButtonBackgroundColor: UIColor = UIColor(red: 142.0/255.0, green: 224.0/255.0, blue: 102.0/255.0, alpha: 0.90)
1717
let kRedButtonBackgroundColor: UIColor = UIColor(red: 244.0/255.0, green: 94.0/255.0, blue: 94.0/255.0, alpha: 0.90)
@@ -20,7 +20,7 @@ let kDisabledBlueButtonBackgroundColor: UIColor = UIColor(red: 74.0/255.0, green
2020
let kDisabledRedButtonBackgroundColor: UIColor = UIColor(red: 244.0/255.0, green: 94.0/255.0, blue: 94.0/255.0, alpha: 0.10)
2121
let kWhiteBackgroundColor: UIColor = UIColor(red: 254.0/255.0, green: 254.0/255.0, blue: 254.0/255.0, alpha: 0.90)
2222

23-
//Accesory View buttons tags
23+
// Accesory View buttons tags
2424
let kDeleteWaypointAccesoryButtonTag = 666
2525
let kEditWaypointAccesoryButtonTag = 333
2626

@@ -70,7 +70,7 @@ class InterfaceController: WKInterfaceController {
7070
manager.requestAlwaysAuthorization()
7171

7272
manager.desiredAccuracy = kCLLocationAccuracyBest
73-
manager.distanceFilter = 2 //meters
73+
manager.distanceFilter = 2 // meters
7474
manager.allowsBackgroundLocationUpdates = true
7575
return manager
7676
}()
@@ -81,10 +81,10 @@ class InterfaceController: WKInterfaceController {
8181
/// Underlying class that handles background stuff
8282
let map = GPXMapView() // not even a map view. Considering renaming
8383

84-
//Status Vars
84+
// Status Vars
8585
var stopWatch = StopWatch()
8686
var lastGpxFilename: String = ""
87-
var wasSentToBackground: Bool = false //Was the app sent to background
87+
var wasSentToBackground: Bool = false // Was the app sent to background
8888
var isDisplayingLocationServicesDenied: Bool = false
8989

9090
/// Does the 'file' have any waypoint?
@@ -130,36 +130,24 @@ class InterfaceController: WKInterfaceController {
130130
// set Tracker button to allow Start
131131
trackerButton.setTitle(NSLocalizedString("START_TRACKING", comment: "no comment"))
132132
trackerButton.setBackgroundColor(kGreenButtonBackgroundColor)
133-
//save & reset button to transparent.
133+
// Save & reset button to transparent.
134134
saveButton.setBackgroundColor(kDisabledBlueButtonBackgroundColor)
135135
resetButton.setBackgroundColor(kDisabledRedButtonBackgroundColor)
136-
//reset clock
136+
// Reset clock
137137
stopWatch.reset()
138138
timeLabel.setText(stopWatch.elapsedTimeString)
139139

140-
map.reset() //reset gpx logging
141-
lastGpxFilename = "" //clear last filename, so when saving it appears an empty field
140+
map.reset() // Reset gpx logging
141+
lastGpxFilename = "" // Clear last filename, so when saving it appears an empty field
142142

143143
totalTrackedDistanceLabel.setText(map.totalTrackedDistance.toDistance(useImperial: preferences.useImperial))
144-
145-
//currentSegmentDistanceLabel.distance = (map.currentSegmentDistance)
146-
147-
/*
148-
// XXX Left here for reference
149-
UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
150-
self.trackerButton.hidden = true
151-
self.pauseButton.hidden = false
152-
}, completion: {(f: Bool) -> Void in
153-
println("finished animation start tracking")
154-
})
155-
*/
156-
144+
157145
case .tracking:
158146
print("switched to tracking mode")
159147
// set trackerButton to allow Pause
160148
trackerButton.setTitle(NSLocalizedString("PAUSE", comment: "no comment"))
161149
trackerButton.setBackgroundColor(kPurpleButtonBackgroundColor)
162-
//activate save & reset buttons
150+
// Activate save & reset buttons
163151
saveButton.setBackgroundColor(kBlueButtonBackgroundColor)
164152
resetButton.setBackgroundColor(kRedButtonBackgroundColor)
165153
// start clock
@@ -173,7 +161,7 @@ class InterfaceController: WKInterfaceController {
173161
// activate save & reset (just in case switched from .NotStarted)
174162
saveButton.setBackgroundColor(kBlueButtonBackgroundColor)
175163
resetButton.setBackgroundColor(kRedButtonBackgroundColor)
176-
//pause clock
164+
// Pause clock
177165
self.stopWatch.stop()
178166
// start new track segment
179167
self.map.startNewTrackSegment()
@@ -182,7 +170,7 @@ class InterfaceController: WKInterfaceController {
182170
}
183171

184172
/// Editing Waypoint Temporal Reference
185-
var lastLocation: CLLocation? //Last point of current segment.
173+
var lastLocation: CLLocation? // Last point of current segment.
186174

187175
override func awake(withContext context: Any?) {
188176
print("InterfaceController:: awake")
@@ -242,7 +230,7 @@ class InterfaceController: WKInterfaceController {
242230
case .tracking:
243231
gpxTrackingStatus = .paused
244232
case .paused:
245-
//set to tracking
233+
// Set to tracking
246234
gpxTrackingStatus = .tracking
247235
}
248236

@@ -279,7 +267,7 @@ class InterfaceController: WKInterfaceController {
279267
let gpxString = self.map.exportToGPXString()
280268
GPXFileManager.save(filename, gpxContents: gpxString)
281269
self.lastGpxFilename = filename
282-
//print(gpxString)
270+
// print(gpxString)
283271

284272
/// Just a 'done' button, without
285273
let action = WKAlertAction(title: "Done", style: .default) {}
@@ -330,19 +318,19 @@ class InterfaceController: WKInterfaceController {
330318
func checkLocationServicesStatus() {
331319
let authorizationStatus = CLLocationManager.authorizationStatus()
332320

333-
//Has the user already made a permission choice?
321+
// Has the user already made a permission choice?
334322
guard authorizationStatus != .notDetermined else {
335-
//We should take no action until the user has made a choice
323+
// We should take no action until the user has made a choice
336324
return
337325
}
338326

339-
//Does the app have permissions to use the location servies?
327+
// Does the app have permissions to use the location servies?
340328
guard [.authorizedAlways, .authorizedWhenInUse ].contains(authorizationStatus) else {
341329
displayLocationServicesDeniedAlert()
342330
return
343331
}
344332

345-
//Are location services enabled?
333+
// Are location services enabled?
346334
guard CLLocationManager.locationServicesEnabled() else {
347335
displayLocationServicesDisabledAlert()
348336
return
@@ -408,8 +396,6 @@ extension InterfaceController: CLLocationManagerDelegate {
408396
altitudeLabel.setText(kUnknownAltitudeText)
409397
signalImageView.setImage(signalImage0)
410398
speedLabel.setText(kUnknownSpeedText)
411-
//signalAccuracyLabel.text = kUnknownAccuracyText
412-
//signalImageView.image = signalImage0
413399
let locationError = error as? CLError
414400
switch locationError?.code {
415401
case CLError.locationUnknown:
@@ -430,7 +416,7 @@ extension InterfaceController: CLLocationManagerDelegate {
430416
///
431417
///
432418
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
433-
//updates signal image accuracy
419+
// Updates signal image accuracy
434420
let newLocation = locations.first!
435421

436422
let hAcc = newLocation.horizontalAccuracy
@@ -461,14 +447,13 @@ extension InterfaceController: CLLocationManagerDelegate {
461447
coordinatesLabel.setText("\(latFormat),\(lonFormat)")
462448
altitudeLabel.setText(newLocation.altitude.toAltitude(useImperial: preferences.useImperial))
463449

464-
//Update speed (provided in m/s, but displayed in km/h)
450+
// Update speed (provided in m/s, but displayed in km/h)
465451
speedLabel.setText(newLocation.speed.toSpeed(useImperial: preferences.useImperial))
466452

467453
if gpxTrackingStatus == .tracking {
468454
print("didUpdateLocation: adding point to track (\(newLocation.coordinate.latitude),\(newLocation.coordinate.longitude))")
469455
map.addPointToCurrentTrackSegmentAtLocation(newLocation)
470456
totalTrackedDistanceLabel.setText(map.totalTrackedDistance.toDistance(useImperial: preferences.useImperial))
471-
//currentSegmentDistanceLabel.distance = map.currentSegmentDistance
472457
}
473458
}
474459
}

0 commit comments

Comments
 (0)