Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_android_sdk_maven_plugin
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Panagiotis Triantafyllou
2024-07-12 17:19:00 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
979a0cceefdbc5df5336357a59c8ef18efd7e43a
979a0cce
1 parent
67f0067c
steps fixes
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
99 deletions
app/src/main/java/warp/ly/android_sdk/activities/SplashActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/activities/WarpViewActivity.java
warply_android_sdk/src/main/java/ly/warp/sdk/services/WarplyHealthService.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/WarpUtils.java
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
warply_android_sdk/src/main/java/ly/warp/sdk/views/WarpView.java
app/src/main/java/warp/ly/android_sdk/activities/SplashActivity.java
View file @
979a0cc
...
...
@@ -38,7 +38,7 @@ public class SplashActivity extends BaseActivity {
if
(!
WarplyDBHelper
.
getInstance
(
SplashActivity
.
this
).
isTableNotEmpty
(
"auth"
))
{
//6012049321, 6012049322, 6012049323, 7000000831 history, 7000000826, 7000000831 shared coupons
//prod 6006552990, prod 6005892749, live 3000184910,prod 7000070282, live 3000136179
WarplyManager
.
getCosmoteUser
(
"700000083
1
"
,
mLoginReceiver
);
WarplyManager
.
getCosmoteUser
(
"700000083
3
"
,
mLoginReceiver
);
// WarplyManager.verifyTicket("", "7000023699", mLoginReceiver);
}
else
{
startNextActivity
();
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/activities/WarpViewActivity.java
View file @
979a0cc
...
...
@@ -44,7 +44,6 @@ import android.widget.ProgressBar;
import
android.widget.RelativeLayout
;
import
androidx.annotation.NonNull
;
import
androidx.lifecycle.ProcessLifecycleOwner
;
import
androidx.work.Constraints
;
import
androidx.work.NetworkType
;
import
androidx.work.OneTimeWorkRequest
;
...
...
@@ -56,9 +55,6 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
java.security.SecureRandom
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
java.util.concurrent.ThreadLocalRandom
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -68,13 +64,11 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver;
import
ly.warp.sdk.io.models.CouponList
;
import
ly.warp.sdk.io.models.WarplyWebviewActivityCallbackEventModel
;
import
ly.warp.sdk.io.models.WarplyWebviewCallbackEventModel
;
import
ly.warp.sdk.io.request.PacingCalculateRequest
;
import
ly.warp.sdk.services.EventCampaignCouponService
;
import
ly.warp.sdk.services.EventQuestionnaireService
;
import
ly.warp.sdk.services.PushEventsClickedWorkerService
;
import
ly.warp.sdk.utils.WarpJSONParser
;
import
ly.warp.sdk.utils.WarpUtils
;
import
ly.warp.sdk.utils.WarplyManagerHelper
;
import
ly.warp.sdk.utils.WarplyPreferences
;
import
ly.warp.sdk.utils.WarplyProperty
;
import
ly.warp.sdk.utils.managers.WarplyAnalyticsManager
;
...
...
@@ -137,13 +131,14 @@ public class WarpViewActivity extends WarpBaseActivity {
super
.
onStop
();
WarplySessionManager
.
onStopActivity
(
this
);
EventBus
.
getDefault
().
unregister
(
this
);
WarplyManager
.
sendSteps
(
this
);
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
if
(
metersHandler
!=
null
)
metersHandler
.
removeCallbacksAndMessages
(
null
);
sendSteps
(
);
// WarplyManager.sendSteps(this
);
WarpUtils
.
setWebviewParams
(
this
,
new
JSONObject
());
setWebviewSupermarket
(
false
);
}
...
...
@@ -346,26 +341,4 @@ public class WarpViewActivity extends WarpBaseActivity {
public
static
void
setWebviewSupermarket
(
boolean
isLoaded
)
{
mWebviewSupermarket
=
isLoaded
;
}
private
void
sendSteps
()
{
String
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
,
Locale
.
getDefault
()).
format
(
new
Date
());
WarpUtils
.
log
(
"SEND_STEPS: "
+
String
.
valueOf
(
WarpUtils
.
getStepsCounter
(
this
)));
if
(
WarpUtils
.
getStepsCounter
(
this
)
>
0
)
{
WarplyManager
.
setPacingDetails
(
new
PacingCalculateRequest
().
setCounter
(
WarpUtils
.
getStepsCounter
(
this
)).
setDate
(
date
),
new
CallbackReceiver
<
JSONObject
>()
{
@Override
public
void
onSuccess
(
JSONObject
result
)
{
int
status
=
result
.
optInt
(
"status"
,
2
);
if
(
status
==
1
)
{
WarplyManagerHelper
.
mSteps
=
0
;
WarpUtils
.
setStepsCounter
(
WarpViewActivity
.
this
,
0
);
}
}
@Override
public
void
onFailure
(
int
errorCode
)
{
WarpUtils
.
log
(
"Warply Health Service error: "
+
String
.
valueOf
(
errorCode
));
}
});
}
}
}
\ No newline at end of file
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/services/WarplyHealthService.java
View file @
979a0cc
...
...
@@ -20,23 +20,12 @@ import android.os.IBinder;
import
androidx.annotation.Nullable
;
import
androidx.core.app.NotificationCompat
;
import
org.greenrobot.eventbus.EventBus
;
import
org.json.JSONObject
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
ly.warp.sdk.R
;
import
ly.warp.sdk.Warply
;
import
ly.warp.sdk.io.callbacks.CallbackReceiver
;
import
ly.warp.sdk.io.models.HealthEventModel
;
import
ly.warp.sdk.io.models.PacingDetails
;
import
ly.warp.sdk.io.request.PacingCalculateRequest
;
import
ly.warp.sdk.io.request.PacingDetailsRequest
;
import
ly.warp.sdk.utils.WarpUtils
;
import
ly.warp.sdk.utils.WarplyManagerHelper
;
import
ly.warp.sdk.utils.managers.WarplyEventBusManager
;
import
ly.warp.sdk.utils.managers.WarplyManager
;
/**
...
...
@@ -88,11 +77,24 @@ public class WarplyHealthService extends Service implements SensorEventListener
mSensorManager
=
(
SensorManager
)
getSystemService
(
Context
.
SENSOR_SERVICE
);
mSensor
=
mSensorManager
.
getDefaultSensor
(
Sensor
.
TYPE_ACCELEROMETER
);
Warply
.
getInitializer
(
getApplicationContext
()).
init
();
WarplyManager
.
getPacingDetails
(
new
PacingDetailsRequest
(),
mPacingCallback
);
/** 1. We get all daily steps from backend so we
* can send them with event bus to the client app
* and show them on their home card.
* Comment this line if registerStepSensor() below
* is going to be used instead. */
// WarplyManager.getPacingDetails(new PacingDetailsRequest(), mPacingCallback);
/** 2. We register our sensor to start giving data.
* Comment this line if WarplyManager.getPacingDetails()
* above is going to be used instead. */
registerStepSensor
();
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
/** 3. We create a sticky notification so the
* service can run on background */
NotificationManager
notificationManager
=
(
NotificationManager
)
getSystemService
(
NOTIFICATION_SERVICE
);
PackageManager
pm
=
getPackageManager
();
Intent
bIntent
=
pm
.
getLaunchIntentForPackage
(
getPackageName
());
...
...
@@ -129,27 +131,12 @@ public class WarplyHealthService extends Service implements SensorEventListener
}
}
/** Old Implementation */
// new Thread(
// () -> {
// while (true) {
// sendSteps();
// try {
// Thread.sleep(900000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
// ).start();
/** New Implementation */
// Use Handler instead of Thread for periodic tasks
/** We save all the steps every 15 minutes */
final
Handler
handler
=
new
Handler
();
Runnable
runnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
sendSteps
(
);
WarplyManager
.
sendSteps
(
WarplyHealthService
.
this
);
handler
.
postDelayed
(
this
,
900000
);
}
};
...
...
@@ -168,7 +155,7 @@ public class WarplyHealthService extends Service implements SensorEventListener
eventMeters
=
0.0d
;
pacingMeters
=
0.0d
;
sumSteps
=
0
;
sendSteps
(
);
WarplyManager
.
sendSteps
(
this
);
}
@Nullable
...
...
@@ -237,20 +224,25 @@ public class WarplyHealthService extends Service implements SensorEventListener
if
(
velocityEstimate
>
STEP_THRESHOLD
&&
oldVelocityEstimate
<=
STEP_THRESHOLD
&&
(
timeNs
-
lastStepTimeNs
>
STEP_DELAY_NS
))
{
/** These 2 lines have moved inside WarpView passMeters */
// WarplyManagerHelper.mSteps++;
// WarpUtils.setStepsCounter(this, WarplyManagerHelper.mSteps);
WarplyManagerHelper
.
mStepsWebview
++;
sumSteps
++;
WarplyManagerHelper
.
mSteps
++;
WarpUtils
.
log
(
"COUNT_STEPS: "
+
String
.
valueOf
(
WarplyManagerHelper
.
mSteps
));
WarpUtils
.
setStepsCounter
(
this
,
WarplyManagerHelper
.
mSteps
);
WarpUtils
.
log
(
"WEBVIEW_STEPS: "
+
String
.
valueOf
(
WarplyManagerHelper
.
mStepsWebview
));
WarplyManagerHelper
.
mMetersWebview
=
(
WarplyManagerHelper
.
mStepsWebview
*
0.762
);
WarpUtils
.
log
(
"WEBVIEW_METERS: "
+
String
.
valueOf
(
WarplyManagerHelper
.
mMetersWebview
));
HealthEventModel
healthSteps
=
new
HealthEventModel
();
// healthSteps.setMeters((mStepsAll * 0.762)); // 16/09/2022
// healthSteps.setMeters(WarplyManagerHelper.mMetersWebview); // 20/09/2022
eventMeters
=
(
sumSteps
*
0.762
);
WarpUtils
.
log
(
"WIDGET_METERS: "
+
String
.
valueOf
(
pacingMeters
+
eventMeters
));
healthSteps
.
setMeters
(
pacingMeters
+
eventMeters
);
EventBus
.
getDefault
().
post
(
new
WarplyEventBusManager
(
healthSteps
));
/** 5. We send overall steps to the client card.
* Needs step 1. */
// HealthEventModel healthSteps = new HealthEventModel();
// sumSteps++;
// healthSteps.setMeters((mStepsAll * 0.762));
// healthSteps.setMeters(WarplyManagerHelper.mMetersWebview);
// eventMeters = (sumSteps * 0.762);
// healthSteps.setMeters(pacingMeters + eventMeters);
// EventBus.getDefault().post(new WarplyEventBusManager(healthSteps));
lastStepTimeNs
=
timeNs
;
}
...
...
@@ -294,35 +286,12 @@ public class WarplyHealthService extends Service implements SensorEventListener
return
retval
;
}
private
void
sendSteps
()
{
String
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
,
Locale
.
getDefault
()).
format
(
new
Date
());
if
(
WarpUtils
.
getStepsCounter
(
this
)
>
0
)
{
WarplyManager
.
setPacingDetails
(
new
PacingCalculateRequest
()
.
setCounter
(
WarpUtils
.
getStepsCounter
(
this
))
.
setDate
(
date
),
new
CallbackReceiver
<
JSONObject
>()
{
@Override
public
void
onSuccess
(
JSONObject
result
)
{
int
status
=
result
.
optInt
(
"status"
,
2
);
if
(
status
==
1
)
{
WarplyManagerHelper
.
mSteps
=
0
;
WarpUtils
.
setStepsCounter
(
WarplyHealthService
.
this
,
0
);
}
}
@Override
public
void
onFailure
(
int
errorCode
)
{
WarpUtils
.
log
(
"Warply Health Service error: "
+
String
.
valueOf
(
errorCode
));
}
});
}
}
private
CallbackReceiver
<
PacingDetails
>
mPacingCallback
=
new
CallbackReceiver
<
PacingDetails
>()
{
@Override
public
void
onSuccess
(
PacingDetails
result
)
{
pacingMeters
=
result
.
getMeters
().
getDay
().
getValue
();
/** 2. We register our sensor to start giving data */
registerStepSensor
();
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/WarpUtils.java
View file @
979a0cc
...
...
@@ -654,13 +654,13 @@ public class WarpUtils {
return
prefs
.
getString
(
PREFERENCES_KEY_WEBVIEW_PARAMS
,
""
);
}
public
static
void
setStepsCounter
(
Context
context
,
int
counter
)
{
public
static
synchronized
void
setStepsCounter
(
Context
context
,
int
counter
)
{
SharedPreferences
.
Editor
editor
=
getPreferences
(
context
).
edit
();
editor
.
putInt
(
PREFERENCES_STEPS_COUNTER
,
counter
);
editor
.
apply
();
}
public
static
int
getStepsCounter
(
Context
context
)
{
public
static
synchronized
int
getStepsCounter
(
Context
context
)
{
SharedPreferences
prefs
=
getPreferences
(
context
);
return
prefs
.
getInt
(
PREFERENCES_STEPS_COUNTER
,
0
);
}
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/utils/managers/WarplyManager.java
View file @
979a0cc
...
...
@@ -58,6 +58,7 @@ import java.util.Collections;
import
java.util.Date
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ExecutorService
;
...
...
@@ -5117,6 +5118,31 @@ public class WarplyManager {
},
null
);
}
public
static
void
sendSteps
(
Context
context
)
{
String
date
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
,
Locale
.
getDefault
()).
format
(
new
Date
());
if
(
WarpUtils
.
getStepsCounter
(
context
)
>
0
)
{
setPacingDetails
(
new
PacingCalculateRequest
()
.
setCounter
(
WarpUtils
.
getStepsCounter
(
context
))
.
setDate
(
date
),
new
CallbackReceiver
<
JSONObject
>()
{
@Override
public
void
onSuccess
(
JSONObject
result
)
{
int
status
=
result
.
optInt
(
"status"
,
2
);
if
(
status
==
1
)
{
WarplyManagerHelper
.
mSteps
=
0
;
WarpUtils
.
setStepsCounter
(
context
,
0
);
}
}
@Override
public
void
onFailure
(
int
errorCode
)
{
WarpUtils
.
log
(
"Warply Health Service error: "
+
String
.
valueOf
(
errorCode
));
}
});
}
}
private
static
boolean
isMyServiceRunning
(
Class
<?>
serviceClass
)
{
ActivityManager
manager
=
(
ActivityManager
)
Warply
.
getWarplyContext
().
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
for
(
ActivityManager
.
RunningServiceInfo
service
:
manager
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
...
...
warply_android_sdk/src/main/java/ly/warp/sdk/views/WarpView.java
View file @
979a0cc
...
...
@@ -826,11 +826,16 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
WarpView
.
this
.
evaluateJavascript
(
scriptSourceMeters
,
s
->
{
});
/** These 2 lines have moved here from WarplyHealthService */
WarplyManagerHelper
.
mSteps
+=
WarplyManagerHelper
.
mStepsWebview
;
WarpUtils
.
setStepsCounter
(
getContext
(),
WarplyManagerHelper
.
mSteps
);
WarplyManagerHelper
.
mStepsWebview
=
0
;
WarplyManagerHelper
.
mMetersWebview
=
0.0d
;
WarpViewActivity
.
getMetersHandler
().
postDelayed
(
this
,
300
);
}
},
3000
);
//TODO: change it back to 1000
},
1000
);
if
(
url
.
contains
(
"about:blank"
))
{
WarpView
.
this
.
clearHistory
();
...
...
Please
register
or
login
to post a comment