Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
225a049
Fix swift lint build errors
NSMutableString Jul 8, 2020
f2d6664
Fix swift lint build warnings
NSMutableString Jul 8, 2020
ce8a8e6
fixup! Fix swift lint build warnings
NSMutableString Jul 8, 2020
c3d85a7
fixup! Fix swift lint build warnings
NSMutableString Jul 8, 2020
943cb76
Refactor importFromGPXRoot to reduce complexity
NSMutableString Jul 9, 2020
83336da
fixup! Fix swift lint build warnings
NSMutableString Jul 9, 2020
2428c47
smarter way to verify validity of date format
vincentneo Jul 20, 2020
21b36a9
reduce to 39 swiftlint issues
vincentneo Jul 20, 2020
f5ea49c
one more...
vincentneo Jul 20, 2020
3133cb0
solving more line over character limit
vincentneo Jul 21, 2020
ea692fc
down to 25
vincentneo Jul 21, 2020
ac46091
Combine batch delete functions
vincentneo Jul 28, 2020
2b6f673
incl CDRoot
vincentneo Jul 29, 2020
eba2e07
minor changes
vincentneo Jul 30, 2020
cf4c99d
Fix #168, pre ios10 batch delete
vincentneo Aug 1, 2020
851e070
Fix #178
vincentneo Aug 1, 2020
8b15769
Move Batch Delete functions out
vincentneo Aug 1, 2020
4717a6c
Fix #177
vincentneo Aug 1, 2020
2921100
Update project.pbxproj
vincentneo Aug 1, 2020
8fb99c4
Merge branch 'refactor/CoreDataHelper' into pr/174
vincentneo Aug 1, 2020
dfb9d7f
Further core data helper splits
vincentneo Aug 1, 2020
2e1d30b
Further lint changes
vincentneo Aug 1, 2020
ae9fc93
Split addConstraints()
vincentneo Aug 1, 2020
8c359ed
reduce character in same line
vincentneo Aug 1, 2020
764e384
down to 12 swiftlint issues
vincentneo Aug 1, 2020
6d0cf34
Merge branch 'master' into feature/fix-swiftlint-errors
vincentneo Aug 1, 2020
11d5228
Merge branch 'master' into feature/fix-swiftlint-errors
merlos Sep 28, 2020
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
10 changes: 6 additions & 4 deletions OpenGpxTracker-Watch Extension/ComplicationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import ClockKit


class ComplicationController: NSObject, CLKComplicationDataSource {

// MARK: - Timeline Configuration

func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
func getSupportedTimeTravelDirections(for complication: CLKComplication,
withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
handler([.forward, .backward])
}

Expand All @@ -36,12 +36,14 @@ class ComplicationController: NSObject, CLKComplicationDataSource {
handler(nil)
}

func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
func getTimelineEntries(for complication: CLKComplication, before date: Date, limit: Int,
withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries prior to the given date
handler(nil)
}

func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int, withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
func getTimelineEntries(for complication: CLKComplication, after date: Date, limit: Int,
withHandler handler: @escaping ([CLKComplicationTimelineEntry]?) -> Void) {
// Call the handler with the timeline entries after to the given date
handler(nil)
}
Expand Down
10 changes: 7 additions & 3 deletions OpenGpxTracker-Watch Extension/ExtensionDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
}

func applicationDidBecomeActive() {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// Restart any tasks that were paused (or not yet started) while the application was inactive.
// If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillResignActive() {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Sent when the application is about to move from active to inactive state.
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
// or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, etc.
}

func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
// Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.
// Sent when the system needs to launch the application in the background to process tasks.
// Tasks arrive in a set, so loop through and process each one.
for task in backgroundTasks {
// Use a switch statement to check the task type
switch task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,21 @@ class GPXFileTableInterfaceController: WKInterfaceController {
var fileList: NSMutableArray = [kNoFiles]

/// Is there any GPX file in the directory?
var gpxFilesFound = false;
var gpxFilesFound = false

/// Temporary variable to manage
var selectedRowIndex = -1

/// true if a gpx file will be sent.
var willSendFile: Bool {
get {
return session?.outstandingFileTransfers.count != 0
}
return session?.outstandingFileTransfers.count != 0
}

/// To ensure hide animation properly timed.
var time = DispatchTime.now()

/// Watch communication session
private let session : WCSession? = WCSession.isSupported() ? WCSession.default : nil
private let session: WCSession? = WCSession.isSupported() ? WCSession.default: nil

override func awake(withContext context: Any?) {
super.awake(withContext: context)
Expand All @@ -64,7 +62,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
// MARK: Progress Indicators

/// States of sending files
enum sendingStatus {
enum SendingStatus {
/// represents current state as sending
case sending
/// represents current state as successful
Expand All @@ -88,7 +86,8 @@ class GPXFileTableInterfaceController: WKInterfaceController {
self.progressGroup.setHeight(0)
})
}
// imageview do not have to be set with stop animating, as image indicator should already have been set as successful or failure image, which is static.
// imageview do not have to be set with stop animating,
// as image indicator should already have been set as successful or failure image, which is static.
}

/// Displays progress indicators.
Expand All @@ -98,13 +97,13 @@ class GPXFileTableInterfaceController: WKInterfaceController {
self.progressGroup.setHeight(30)
self.progressGroup.setHidden(false)
progressImageView.setImageNamed("Progress-")
progressImageView.startAnimatingWithImages(in: NSMakeRange(0, 12), duration: 1, repeatCount: 0)
progressImageView.startAnimatingWithImages(in: NSRange(location: 0, length: 12), duration: 1, repeatCount: 0)
}

/// Updates progress indicators according to status when sending.
///
/// If status is success or failure, method will hide and animate progress indicators when done
func updateProgressIndicators(status: sendingStatus, fileName: String?) {
func updateProgressIndicators(status: SendingStatus, fileName: String?) {
switch status {
case .sending:
progressTitle.setText(NSLocalizedString("SENDING", comment: "no comment"))
Expand All @@ -115,8 +114,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {
// if there are files pending for sending, filename will not be displayed with the name of file.
if fileTransfersCount >= 1 {
progressFileName.setText(String(format: NSLocalizedString("X_FILES", comment: "no comment"), fileTransfersCount + 1))
}
else {
} else {
progressFileName.setText(fileName)
}

Expand Down Expand Up @@ -144,8 +142,7 @@ class GPXFileTableInterfaceController: WKInterfaceController {

if willSendFile == true {
self.showProgressIndicators()
}
else {
} else {
self.hideProgressIndicators()
}

Expand Down Expand Up @@ -179,11 +176,11 @@ class GPXFileTableInterfaceController: WKInterfaceController {
if gpxFilesFound {
for index in 0..<fileTable.numberOfRows {
guard let cell = fileTable.rowController(at: index) as? GPXFileTableRowController else { continue }
// swiftlint:disable force_cast
let gpxFileInfo = fileList.object(at: index) as! GPXFileInfo
cell.fileLabel.setText(gpxFileInfo.fileName)
}
}
else {
} else {
guard let cell = fileTable.rowController(at: 0) as? GPXFileTableRowController else { return }
cell.fileLabel.setText(kNoFiles)
}
Expand Down Expand Up @@ -217,15 +214,16 @@ class GPXFileTableInterfaceController: WKInterfaceController {
/// Array of all available options
let options = [shareOption, cancelOption, deleteOption]

presentAlert(withTitle: NSLocalizedString("FILE_SELECTED_TITLE", comment: "no comment"), message: NSLocalizedString("FILE_SELECTED_MESSAGE", comment: "no comment"), preferredStyle: .actionSheet, actions: options)
presentAlert(withTitle: NSLocalizedString("FILE_SELECTED_TITLE", comment: "no comment"),
message: NSLocalizedString("FILE_SELECTED_MESSAGE", comment: "no comment"),
preferredStyle: .actionSheet, actions: options)
}
}

//
// MARK: Action Sheet - Actions
//



/// Attempts to transfer file to iOS app
func actionTransferFileAtIndex(_ rowIndex: Int) {
session?.activate()
Expand All @@ -234,11 +232,12 @@ class GPXFileTableInterfaceController: WKInterfaceController {
self.hideProgressIndicators()
return
}
// swiftlint:disable force_cast
let gpxFileInfo = fileList.object(at: rowIndex) as! GPXFileInfo
self.scroll(to: progressGroup, at: .top, animated: true) // scrolls to top when indicator is shown.
self.updateProgressIndicators(status: .sending, fileName: gpxFileInfo.fileName)
DispatchQueue.global().async {
self.session?.transferFile(fileURL, metadata: ["fileName" : "\(gpxFileInfo.fileName).gpx"])
self.session?.transferFile(fileURL, metadata: ["fileName": "\(gpxFileInfo.fileName).gpx"])
}
}

Expand All @@ -262,7 +261,6 @@ class GPXFileTableInterfaceController: WKInterfaceController {
fileList.removeObject(at: rowIndex)

}


override func didDeactivate() {
// This method is called when watch view controller is no longer visible
Expand All @@ -271,26 +269,25 @@ class GPXFileTableInterfaceController: WKInterfaceController {

}


// MARK:- WCSessionDelegate
// MARK: WCSessionDelegate

///
/// Handles all the file transfer to iOS app processes
///
extension GPXFileTableInterfaceController: WCSessionDelegate {

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
let prefixText = "GPXFileTableInterfaceController:: activationDidCompleteWithActivationState:"
switch activationState {
case .activated:
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session activated")
print("\(prefixText) session activated")
case .inactive:
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session inactive")
print("\(prefixText) session inactive")
case .notActivated:
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: session not activated, error:\(String(describing: error))")
print("\(prefixText) session not activated, error:\(String(describing: error))")

default:
print("GPXFileTableInterfaceController:: activationDidCompleteWithActivationState: default, error:\(String(describing: error))")
break
print("\(prefixText) default, error:\(String(describing: error))")
}
}

Expand All @@ -312,7 +309,9 @@ extension GPXFileTableInterfaceController: WCSessionDelegate {
// presents alert after 1.5s, with error message
// MARK: "as CVarArg" was suggested by XCode and my intruduce a bug...
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
self.presentAlert(withTitle: NSLocalizedString("ERROR_OCCURED_TITLE", comment: "no comment"), message: String(format: NSLocalizedString("ERROR_OCCURED_MESSAGE", comment: "no comment"), error as CVarArg), preferredStyle: .alert, actions: [doneAction])
self.presentAlert(withTitle: NSLocalizedString("ERROR_OCCURED_TITLE", comment: "no comment"),
message: String(format: NSLocalizedString("ERROR_OCCURED_MESSAGE", comment: "no comment"), error as CVarArg),
preferredStyle: .alert, actions: [doneAction])
}
}

Expand Down
42 changes: 17 additions & 25 deletions OpenGpxTracker-Watch Extension/InterfaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ let kSignalAccuracy3 = 51.0
let kSignalAccuracy2 = 101.0
let kSignalAccuracy1 = 201.0


///
/// Main View Controller of the Watch Application. It is loaded when the application is launched
///
Expand All @@ -64,8 +63,7 @@ class InterfaceController: WKInterfaceController {
@IBOutlet var coordinatesLabel: WKInterfaceLabel!
@IBOutlet var altitudeLabel: WKInterfaceLabel!
@IBOutlet var speedLabel: WKInterfaceLabel!



/// Location Manager
let locationManager: CLLocationManager = {
let manager = CLLocationManager()
Expand Down Expand Up @@ -185,13 +183,11 @@ class InterfaceController: WKInterfaceController {

/// Editing Waypoint Temporal Reference
var lastLocation: CLLocation? //Last point of current segment.



override func awake(withContext context: Any?) {
print("InterfaceController:: awake")
super.awake(withContext: context)



totalTrackedDistanceLabel.setText( 0.00.toDistance(useImperial: preferences.useImperial))

if gpxTrackingStatus == .notStarted {
Expand All @@ -207,8 +203,7 @@ class InterfaceController: WKInterfaceController {
signalImageView.setImage(signalImage0)
}
}



override func willActivate() {
// This method is called when watch view controller is about to be visible to user
print("InterfaceController:: willActivate")
Expand All @@ -233,9 +228,7 @@ class InterfaceController: WKInterfaceController {
locationManager.stopUpdatingLocation()
}
}




///
/// Main Start/Pause Button was tapped.
///
Expand Down Expand Up @@ -292,7 +285,7 @@ class InterfaceController: WKInterfaceController {
let action = WKAlertAction(title: "Done", style: .default) {}

presentAlert(withTitle: NSLocalizedString("FILE_SAVED_TITLE", comment: "no comment"),
message: "\(filename).gpx", preferredStyle: .alert, actions: [action])
message: "\(filename).gpx", preferredStyle: .alert, actions: [action])

}

Expand All @@ -304,8 +297,7 @@ class InterfaceController: WKInterfaceController {
@IBAction func resetButtonTapped() {
self.gpxTrackingStatus = .notStarted
}



/// returns a string with the format of current date dd-MMM-yyyy-HHmm' (20-Jun-2018-1133)
///
func defaultFilename() -> String {
Expand All @@ -314,8 +306,7 @@ class InterfaceController: WKInterfaceController {
print("fileName:" + dateFormatter.string(from: Date()))
return dateFormatter.string(from: Date())
}



///
/// Checks the location services status
/// - Are location services enabled (access to location device wide)? If not => displays an alert
Expand Down Expand Up @@ -346,10 +337,11 @@ class InterfaceController: WKInterfaceController {
print("LocationServicesDisabledAlert: cancel pressed")
}

presentAlert(withTitle: NSLocalizedString("LOCATION_SERVICES_DISABLED", comment: "no comment"), message: NSLocalizedString("ENABLE_LOCATION_SERVICES", comment: "no comment"), preferredStyle: .alert, actions: [button])
presentAlert(withTitle: NSLocalizedString("LOCATION_SERVICES_DISABLED", comment: "no comment"),
message: NSLocalizedString("ENABLE_LOCATION_SERVICES", comment: "no comment"),
preferredStyle: .alert, actions: [button])
}


///
/// Displays an alert that informs the user that access to location was denied for this app (other apps may have access).
/// It also dispays a button allows the user to go to settings to activate the location.
Expand All @@ -362,7 +354,9 @@ class InterfaceController: WKInterfaceController {
print("LocationServicesDeniedAlert: cancel pressed")
}

presentAlert(withTitle: NSLocalizedString("ACCESS_TO_LOCATION_DENIED", comment: "no comment"), message: NSLocalizedString("ALLOW_LOCATION", comment: "no comment"), preferredStyle: .alert, actions: [button])
presentAlert(withTitle: NSLocalizedString("ACCESS_TO_LOCATION_DENIED", comment: "no comment"),
message: NSLocalizedString("ALLOW_LOCATION", comment: "no comment"),
preferredStyle: .alert, actions: [button])
}

}
Expand All @@ -383,7 +377,6 @@ extension InterfaceController: StopWatchDelegate {

// MARK: CLLocationManagerDelegate


extension InterfaceController: CLLocationManagerDelegate {

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
Expand Down Expand Up @@ -417,9 +410,10 @@ extension InterfaceController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
//updates signal image accuracy
let newLocation = locations.first!
print("didUpdateLocation: received \(newLocation.coordinate) hAcc: \(newLocation.horizontalAccuracy) vAcc: \(newLocation.verticalAccuracy) floor: \(newLocation.floor?.description ?? "''")")

let hAcc = newLocation.horizontalAccuracy
let vAcc = newLocation.verticalAccuracy
print("didUpdateLocation: received \(newLocation.coordinate) hAcc: \(hAcc) vAcc: \(vAcc) floor: \(newLocation.floor?.description ?? "''")")

signalAccuracyLabel.setText(hAcc.toAccuracy(useImperial: preferences.useImperial))
if hAcc < kSignalAccuracy6 {
Expand All @@ -434,7 +428,7 @@ extension InterfaceController: CLLocationManagerDelegate {
self.signalImageView.setImage(signalImage2)
} else if hAcc < kSignalAccuracy1 {
self.signalImageView.setImage(signalImage1)
} else{
} else {
self.signalImageView.setImage(signalImage0)
}

Expand All @@ -455,6 +449,4 @@ extension InterfaceController: CLLocationManagerDelegate {
//currentSegmentDistanceLabel.distance = map.currentSegmentDistance
}
}

}

Loading