Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2022-09-28 17:24:47 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4e3bd0e8a04263af33f960ec7875e975073ed58e
4e3bd0e8
1 parent
b83a7165
fix pacing on user logout, add oldDayMeters
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
50 deletions
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
SwiftWarplyFramework/SwiftWarplyFramework/swiftApi.swift
View file @
4e3bd0e
...
...
@@ -121,71 +121,91 @@ public class swiftApi {
public
func
startTrackingSteps
(
_
getStepsCallback
:
@escaping
(
_
steps
:
Int
)
->
Void
)
->
Void
{
if
(
GlobalVariables
.
trackingStepsEnabled
==
false
)
{
GlobalVariables
.
trackingStepsEnabled
=
true
// First get meters day value from database
swiftApi
()
.
getPacingDetailsAsync
(
getPacingCallback
)
// Check if there are persistedSteps from previous app kill and save them
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
func
getPacingCallback
(
_
pacingData
:
swiftApi
.
PacingDetails
?)
->
Void
{
if
(
pacingData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
let
oldDayMeters
:
Double
=
pacingData
?
.
_meters
.
_day
.
_value
??
0.0
let
currentDateTime
=
Date
()
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
let
dateString
=
dateFormatter
.
string
(
from
:
currentDateTime
)
print
(
"=== oldDayMeters ==="
)
print
(
oldDayMeters
)
swiftApi
()
.
setPacingDetailsAsync
(
persistedSteps
,
dateString
,
setPacingDetailsAsyncCallback
)
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
GlobalVariables
.
savedSteps
=
0
GlobalVariables
.
trackingStepsEnabled
=
true
// Check if there are persistedSteps from previous app kill and save them
let
persistedSteps
=
swiftApi
()
.
getSteps
()
if
(
persistedSteps
>
0
)
{
let
currentDateTime
=
Date
()
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
let
dateString
=
dateFormatter
.
string
(
from
:
currentDateTime
)
swiftApi
()
.
setPacingDetailsAsync
(
persistedSteps
,
dateString
,
setPacingDetailsAsyncCallback
)
}
func
setPacingDetailsAsyncCallback
(
_
responseData
:
swiftApi
.
GenericResponseModel
?)
->
Void
{
if
(
responseData
!=
nil
)
{
DispatchQueue
.
main
.
async
{
if
(
responseData
?
.
getStatus
==
1
)
{
GlobalVariables
.
savedSteps
=
0
}
}
}
else
{
}
}
}
}
else
{
}
}
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
startTrackingSteps
(
startTrackingCallback
)
let
instanceOfMyApi
=
MyApi
()
instanceOfMyApi
.
startTrackingSteps
(
startTrackingCallback
)
swiftApi
()
.
startTimer
()
func
startTrackingCallback
(
_
steps
:
NSNumber
?)
->
Void
{
print
(
"=== steps ==="
)
print
(
steps
as?
Int
??
0
)
swiftApi
()
.
startTimer
()
func
startTrackingCallback
(
_
steps
:
NSNumber
?)
->
Void
{
print
(
"=== steps ==="
)
print
(
steps
as?
Int
??
0
)
if
(
steps
!=
nil
)
{
print
(
"=== steps to save ==="
)
if
(
steps
!=
nil
)
{
print
(
"=== steps to save ==="
)
print
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
swiftApi
()
.
setSteps
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
print
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
swiftApi
()
.
setSteps
((
steps
as!
Int
)
-
GlobalVariables
.
savedSteps
)
let
metersCount
=
(
steps
as?
Double
??
0.0
)
*
0.762
swiftApi
()
.
setMetersCount
(
metersCount
)
let
metersCount
=
(
steps
as?
Double
??
0.0
)
*
0.762
swiftApi
()
.
setMetersCount
(
metersCount
)
let
pacingEvent
=
swiftApi
.
HealthEventModel
()
pacingEvent
.
_meters
=
metersCount
SwiftEventBus
.
post
(
"meters_sent"
,
sender
:
pacingEvent
)
let
pacingEvent
=
swiftApi
.
HealthEventModel
()
pacingEvent
.
_meters
=
metersCount
+
oldDayMeters
//
SwiftEventBus.post("meters_sent", sender: pacingEvent)
print
(
"=== MetersCount ==="
)
print
(
metersCount
)
print
(
"=== MetersCount ==="
)
print
(
metersCount
)
let
newStepsWebview
=
(
steps
as!
Int
)
-
GlobalVariables
.
savedStepsWebview
swiftApi
()
.
setStepsWebview
(
newStepsWebview
)
let
newMetersWebview
=
Double
(
newStepsWebview
)
*
0.762
swiftApi
()
.
setMetersWebview
(
newMetersWebview
)
print
(
"=== Widget MetersCount ==="
)
print
(
metersCount
+
oldDayMeters
)
print
(
"=== StepsWebview ==="
)
print
(
newStepsWebview
)
print
(
"=== MetersWebview ==="
)
print
(
newMetersWebview
)
}
let
newStepsWebview
=
(
steps
as!
Int
)
-
GlobalVariables
.
savedStepsWebview
swiftApi
()
.
setStepsWebview
(
newStepsWebview
)
let
newMetersWebview
=
Double
(
newStepsWebview
)
*
0.762
swiftApi
()
.
setMetersWebview
(
newMetersWebview
)
getStepsCallback
(
steps
as?
Int
??
0
)
print
(
"=== StepsWebview ==="
)
print
(
newStepsWebview
)
print
(
"=== MetersWebview ==="
)
print
(
newMetersWebview
)
}
getStepsCallback
(
steps
as?
Int
??
0
)
}
}
}
}
}
}
...
...
@@ -5746,4 +5766,11 @@ public class swiftApi {
}
public
func
logoutUser
()
->
Void
{
if
(
GlobalVariables
.
trackingStepsEnabled
==
true
)
{
swiftApi
()
.
stopTrackingSteps
()
}
}
}
...
...
Please
register
or
login
to post a comment