Panagiotis Triantafyllou

steps fixes

......@@ -4,18 +4,18 @@
<value>
<entry key="app">
<State>
<targetSelectedWithDropDown>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_7_v13.avd" />
<type value="SERIAL_NUMBER" />
<value value="R58M42EM7YT" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-07-09T11:41:15.263632Z" />
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2024-07-26T13:26:33.140020Z" />
</State>
</entry>
</value>
......
......@@ -17,7 +17,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" />
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />-->
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
<application android:largeHeap="true">
<!-- <meta-data-->
......@@ -291,8 +292,8 @@
android:name=".receivers.RestartHealthServiceReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
<!-- <action android:name="android.intent.action.BOOT_COMPLETED" />-->
<action android:name="android.intent.action.RESTART" />
</intent-filter>
</receiver>
......
......@@ -28,6 +28,8 @@ package ly.warp.sdk.activities;
import static ly.warp.sdk.utils.constants.WarpConstants.RANDOM_MAX;
import static ly.warp.sdk.utils.constants.WarpConstants.RANDOM_MIN;
import android.Manifest;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
......@@ -35,6 +37,8 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
......@@ -44,6 +48,8 @@ import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.work.Constraints;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
......@@ -62,11 +68,14 @@ import ly.warp.sdk.Warply;
import ly.warp.sdk.db.WarplyDBHelper;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.CouponList;
import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
import ly.warp.sdk.io.models.WarplyPacingEventModel;
import ly.warp.sdk.io.models.WarplyWebviewActivityCallbackEventModel;
import ly.warp.sdk.io.models.WarplyWebviewCallbackEventModel;
import ly.warp.sdk.services.EventCampaignCouponService;
import ly.warp.sdk.services.EventQuestionnaireService;
import ly.warp.sdk.services.PushEventsClickedWorkerService;
import ly.warp.sdk.services.WarplyHealthService;
import ly.warp.sdk.utils.WarpJSONParser;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyPreferences;
......@@ -164,6 +173,24 @@ public class WarpViewActivity extends WarpBaseActivity {
webviewCallbackEventModel.setResponseCode(grantResults[0] == PackageManager.PERMISSION_GRANTED ? "allow" : "deny");
EventBus.getDefault().post(new WarplyEventBusManager(webviewCallbackEventModel));
}
if (requestCode == 5001 && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (!isMyServiceRunning(WarplyHealthService.class)) {
LoyaltySDKFirebaseEventModel analyticsEvent = new LoyaltySDKFirebaseEventModel();
analyticsEvent.setEventName("loyalty_steps_activation");
EventBus.getDefault().post(new WarplyEventBusManager(analyticsEvent));
Intent stepsServiceIntent = new Intent(this, WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(stepsServiceIntent);
} else {
startService(stepsServiceIntent);
}
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
}
}
@Override
......@@ -195,6 +222,60 @@ public class WarpViewActivity extends WarpBaseActivity {
// if (event.getPacingService() != null)
// finish();
if (event.getPacing() != null && !event.getPacing().isVisible()) finish();
if (event.getHealth() != null) {
if (event.getHealth().isActivated()) {
WarpUtils.setIsStepsManuallyStopped(this, false);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACTIVITY_RECOGNITION) != PackageManager.PERMISSION_GRANTED) {
// ActivityCompat.requestPermissions(this, new String[]{
// Manifest.permission.ACTIVITY_RECOGNITION
// }, 5001);
// } else {
// if (!isMyServiceRunning(WarplyHealthService.class)) {
// LoyaltySDKFirebaseEventModel analyticsEvent = new LoyaltySDKFirebaseEventModel();
// analyticsEvent.setEventName("loyalty_steps_activation");
// EventBus.getDefault().post(new WarplyEventBusManager(analyticsEvent));
//
// Intent stepsServiceIntent = new Intent(this, WarplyHealthService.class);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// startForegroundService(stepsServiceIntent);
// } else {
// startService(stepsServiceIntent);
// }
//
// WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
// pacingVisible.setVisible(true);
// EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
// }
// }
// } else {
if (!isMyServiceRunning(WarplyHealthService.class)) {
LoyaltySDKFirebaseEventModel analyticsEvent = new LoyaltySDKFirebaseEventModel();
analyticsEvent.setEventName("loyalty_steps_activation");
EventBus.getDefault().post(new WarplyEventBusManager(analyticsEvent));
Intent stepsServiceIntent = new Intent(this, WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(stepsServiceIntent);
} else {
startService(stepsServiceIntent);
}
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
// }
} else {
WarpUtils.setIsStepsManuallyStopped(this, true);
Intent stepsServiceIntent = new Intent(this, WarplyHealthService.class);
stopService(stepsServiceIntent);
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(false);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
}
}
// ===========================================================
......@@ -251,19 +332,19 @@ public class WarpViewActivity extends WarpBaseActivity {
if (intent.hasExtra("source") && intent.getStringExtra("source").equalsIgnoreCase("from_notification_status")) {
JSONObject params = new JSONObject();
try {
params.putOpt("web_id", WarpUtils.getWebId(Warply.getWarplyContext()));
params.putOpt("app_uuid", WarplyProperty.getAppUuid(Warply.getWarplyContext()));
params.putOpt("api_key", WarpUtils.getApiKey(Warply.getWarplyContext()));
params.putOpt("web_id", WarpUtils.getWebId(this));
params.putOpt("app_uuid", WarplyProperty.getAppUuid(this));
params.putOpt("api_key", WarpUtils.getApiKey(this));
params.putOpt("session_uuid", sessionUUID);
params.putOpt("access_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("access_token"));
params.putOpt("refresh_token", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getAuthValue("refresh_token"));
params.putOpt("client_id", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_id"));
params.putOpt("client_secret", WarplyDBHelper.getInstance(Warply.getWarplyContext()).getClientValue("client_secret"));
params.putOpt("access_token", WarplyDBHelper.getInstance(this).getAuthValue("access_token"));
params.putOpt("refresh_token", WarplyDBHelper.getInstance(this).getAuthValue("refresh_token"));
params.putOpt("client_id", WarplyDBHelper.getInstance(this).getClientValue("client_id"));
params.putOpt("client_secret", WarplyDBHelper.getInstance(this).getClientValue("client_secret"));
} catch (JSONException e) {
e.printStackTrace();
}
WarpUtils.setWebviewParams(Warply.getWarplyContext(), params);
WarpUtils.setWebviewParams(this, params);
setUpPushEvents(sessionUUID);
}
......@@ -341,4 +422,24 @@ public class WarpViewActivity extends WarpBaseActivity {
public static void setWebviewSupermarket(boolean isLoaded) {
mWebviewSupermarket = isLoaded;
}
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
private void checkBatteryOptimizationForWarplyHealth() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!pm.isIgnoringBatteryOptimizations(getPackageName())) {
Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivityForResult(intent, 6001);
}
}
}
}
\ No newline at end of file
......
/*
* Copyright 2010-2013 Warply Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE WARPLY LTD ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL WARPLY LTD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package ly.warp.sdk.io.models;
/**
* Created by Panagiotis Triantafyllou on 25-July-24.
*/
public class WarplyHealthEventModel {
private boolean activated;
public WarplyHealthEventModel() {
this.activated = true;
}
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
}
package ly.warp.sdk.receivers;
import static ly.warp.sdk.services.WarplyHealthService.ACTION_RESTART_SERVICE;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import ly.warp.sdk.services.WarplyHealthService;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import java.util.concurrent.TimeUnit;
import ly.warp.sdk.services.WarplyHealthWorker;
public class RestartHealthServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())) {
Intent stepsRestartServiceIntent = new Intent(context, WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(stepsRestartServiceIntent);
} else {
context.startService(stepsRestartServiceIntent);
if (intent != null && intent.getAction() != null && ACTION_RESTART_SERVICE.equals(intent.getAction())) {
scheduleWork(context);
}
}
private void scheduleWork(Context context) {
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WarplyHealthWorker.class)
.setInitialDelay(2, TimeUnit.SECONDS)
.build();
WorkManager.getInstance(context).enqueue(workRequest);
}
}
\ No newline at end of file
......
......@@ -7,7 +7,6 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
......@@ -16,6 +15,7 @@ import android.hardware.SensorManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
......@@ -24,6 +24,7 @@ import ly.warp.sdk.R;
import ly.warp.sdk.Warply;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.models.PacingDetails;
import ly.warp.sdk.receivers.RestartHealthServiceReceiver;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.WarplyManagerHelper;
import ly.warp.sdk.utils.managers.WarplyManager;
......@@ -60,6 +61,10 @@ public class WarplyHealthService extends Service implements SensorEventListener
private float oldVelocityEstimate = 0;
private double eventMeters = 0.0d, pacingMeters = 0.0d;
private int sumSteps = 0;
private Handler notificationHandler, saveHandler;
private Runnable notificationRunnable, saveRunnable;
private static int mNotificationSteps = 0;
public static final String ACTION_RESTART_SERVICE = "ly.warp.sdk.services.ACTION_RESTART_SERVICE";
// ===========================================================
// Contructors
......@@ -95,52 +100,39 @@ public class WarplyHealthService extends Service implements SensorEventListener
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());
PendingIntent pbIntent = PendingIntent.getActivity(this, 2001, bIntent, PendingIntent.FLAG_IMMUTABLE);
createNotificationChannel();
NotificationCompat.Builder b = new NotificationCompat.Builder(this, STEPS_CHANNEL_ID);
b.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
b.setChannelId(STEPS_CHANNEL_ID);
b.setContentTitle(getString(R.string.cos_steps_for_good_notification_title));
b.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.cos_steps_for_good_notification_subtitle)));
b.setContentIntent(pbIntent);
b.setAutoCancel(false); //it was true
b.setOngoing(true);
b.setPriority(NotificationCompat.PRIORITY_HIGH);
b.setSmallIcon(R.drawable.ic_launcher);
if (notificationManager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID, "steps_notification_channel", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
this.startForeground(2001, notification_build, ServiceInfo.FOREGROUND_SERVICE_TYPE_HEALTH);
this.startForeground(2001, createNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_HEALTH);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID, "steps_notification_channel", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
this.startForeground(2001, notification_build);
this.startForeground(2001, createNotification());
} else {
Notification notification_build = b.build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
this.startForeground(2001, notification_build);
this.startForeground(2001, createNotification());
}
/** We update the notification */
notificationHandler = new Handler(Looper.getMainLooper());
notificationRunnable = new Runnable() {
@Override
public void run() {
Notification notification = createNotification();
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(2001, notification);
notificationHandler.postDelayed(this, 1000);
}
};
notificationHandler.post(notificationRunnable);
/** We save all the steps every 15 minutes */
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
saveHandler = new Handler();
saveRunnable = new Runnable() {
@Override
public void run() {
WarplyManager.sendSteps(WarplyHealthService.this);
handler.postDelayed(this, 900000);
saveHandler.postDelayed(this, 900000);
}
};
handler.post(runnable);
saveHandler.post(saveRunnable);
return Service.START_STICKY;
}
......@@ -155,7 +147,29 @@ public class WarplyHealthService extends Service implements SensorEventListener
eventMeters = 0.0d;
pacingMeters = 0.0d;
sumSteps = 0;
mNotificationSteps = 0;
if (notificationHandler != null)
notificationHandler.removeCallbacks(notificationRunnable);
if (saveHandler != null)
saveHandler.removeCallbacks(saveRunnable);
WarplyManager.sendSteps(this);
if (!WarpUtils.getIsStepsManuallyStopped(this)) {
Intent broadcastIntent = new Intent(this, RestartHealthServiceReceiver.class);
broadcastIntent.setAction(ACTION_RESTART_SERVICE);
sendBroadcast(broadcastIntent);
}
}
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
stopSelf();
if (!WarpUtils.getIsStepsManuallyStopped(this)) {
Intent broadcastIntent = new Intent(this, RestartHealthServiceReceiver.class);
broadcastIntent.setAction(ACTION_RESTART_SERVICE);
sendBroadcast(broadcastIntent);
}
}
@Nullable
......@@ -229,6 +243,7 @@ public class WarplyHealthService extends Service implements SensorEventListener
// WarplyManagerHelper.mSteps++;
// WarpUtils.setStepsCounter(this, WarplyManagerHelper.mSteps);
mNotificationSteps++;
WarplyManagerHelper.mStepsWebview++;
WarpUtils.log("WEBVIEW_STEPS: " + String.valueOf(WarplyManagerHelper.mStepsWebview));
WarplyManagerHelper.mMetersWebview = (WarplyManagerHelper.mStepsWebview * 0.762);
......@@ -300,4 +315,76 @@ public class WarplyHealthService extends Service implements SensorEventListener
}
};
private void createNotificationChannel() {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (notificationManager != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID,
"steps_notification_channel",
NotificationManager.IMPORTANCE_HIGH); //IMPORTANCE_HIGH if we want heads up notification, IMPORTANCE_DEFAULT otherwise
notificationManager.createNotificationChannel(notificationChannel);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID,
"steps_notification_channel",
NotificationManager.IMPORTANCE_HIGH); //IMPORTANCE_HIGH if we want heads up notification, IMPORTANCE_DEFAULT otherwise
notificationManager.createNotificationChannel(notificationChannel);
}
}
}
private Notification createNotification() {
Intent bIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
PendingIntent pbIntent = PendingIntent.getActivity(this, 2001, bIntent, PendingIntent.FLAG_IMMUTABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this, STEPS_CHANNEL_ID);
b.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
b.setChannelId(STEPS_CHANNEL_ID);
b.setContentTitle(getString(R.string.cos_steps_for_good_notification_title) + " " + String.valueOf(mNotificationSteps + " /10000"));
b.setContentText(String.valueOf(mNotificationSteps + " βήματα"));
b.setProgress(10000, mNotificationSteps, false);
b.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.cos_steps_for_good_notification_subtitle)));
b.setContentIntent(pbIntent);
b.setAutoCancel(false); //it was true
b.setOngoing(true);
b.setPriority(NotificationCompat.PRIORITY_HIGH);
b.setSmallIcon(R.drawable.ic_launcher);
Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
return notification_build;
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationCompat.Builder b = new NotificationCompat.Builder(this, STEPS_CHANNEL_ID);
b.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
b.setChannelId(STEPS_CHANNEL_ID);
b.setContentTitle(getString(R.string.cos_steps_for_good_notification_title) + " " + String.valueOf(mNotificationSteps + " /10000"));
b.setContentText(String.valueOf(mNotificationSteps + " βήματα"));
b.setProgress(10000, mNotificationSteps, false);
b.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.cos_steps_for_good_notification_subtitle)));
b.setContentIntent(pbIntent);
b.setAutoCancel(false); //it was true
b.setOngoing(true);
b.setPriority(NotificationCompat.PRIORITY_HIGH);
b.setSmallIcon(R.drawable.ic_launcher);
Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
return notification_build;
} else {
NotificationCompat.Builder b = new NotificationCompat.Builder(this, STEPS_CHANNEL_ID);
b.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
b.setChannelId(STEPS_CHANNEL_ID);
b.setContentTitle(getString(R.string.cos_steps_for_good_notification_title) + " " + String.valueOf(mNotificationSteps + " /10000"));
b.setContentText(String.valueOf(mNotificationSteps + " βήματα"));
b.setProgress(10000, mNotificationSteps, false);
b.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.cos_steps_for_good_notification_subtitle)));
b.setContentIntent(pbIntent);
b.setAutoCancel(false); //it was true
b.setOngoing(true);
b.setPriority(NotificationCompat.PRIORITY_HIGH);
b.setSmallIcon(R.drawable.ic_launcher);
Notification notification_build = b.build();
notification_build.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
return notification_build;
}
}
}
......
package ly.warp.sdk.services;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
/**
* Created by Panagiotis Triantafyllou on 26/Ιουλ/2024.
*/
public class WarplyHealthWorker extends Worker {
public WarplyHealthWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {
Context context = getApplicationContext();
Intent stepsRestartServiceIntent = new Intent(context, WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(stepsRestartServiceIntent);
} else {
context.startService(stepsRestartServiceIntent);
}
return Result.success();
}
}
......@@ -157,6 +157,8 @@ public class WarpUtils {
+ "language";
private static final String PREFERENCES_KEY_STEPS = PREFERENCES_PREFIX
+ "steps";
private static final String PREFERENCES_KEY_STEPS_MANUALLY_STOPPED = PREFERENCES_PREFIX
+ "steps_manually_stopped";
private static SharedPreferences _prefs;
......@@ -166,9 +168,19 @@ public class WarpUtils {
return getPreferences(context).getBoolean(PREFERENCES_KEY_STEPS, false);
}
public static void setIsSteps(Context context, boolean isSupermarket) {
public static void setIsSteps(Context context, boolean isSteps) {
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putBoolean(PREFERENCES_KEY_STEPS, isSupermarket);
editor.putBoolean(PREFERENCES_KEY_STEPS, isSteps);
editor.apply();
}
public static boolean getIsStepsManuallyStopped(Context context) {
return getPreferences(context).getBoolean(PREFERENCES_KEY_STEPS_MANUALLY_STOPPED, false);
}
public static void setIsStepsManuallyStopped(Context context, boolean isManuallyStopped) {
SharedPreferences.Editor editor = getPreferences(context).edit();
editor.putBoolean(PREFERENCES_KEY_STEPS_MANUALLY_STOPPED, isManuallyStopped);
editor.apply();
}
......
......@@ -27,6 +27,7 @@ import ly.warp.sdk.io.models.WarplyBoxAnalysisEventModel;
import ly.warp.sdk.io.models.WarplyCCMSEnabledModel;
import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
import ly.warp.sdk.io.models.WarplyDealsAnalysisEventModel;
import ly.warp.sdk.io.models.WarplyHealthEventModel;
import ly.warp.sdk.io.models.WarplyNavigateBackEventModel;
import ly.warp.sdk.io.models.WarplyPacingCardEventModel;
import ly.warp.sdk.io.models.WarplyPacingCardServiceEnabledModel;
......@@ -51,6 +52,7 @@ public class WarplyEventBusManager {
private WarplyCCMSEnabledModel ccmsActivated;
private LoyaltyGiftsForYouOfferClickEvent giftsYou;
private QuestionnaireEventModel questionnaire;
private WarplyHealthEventModel health;
private OpenMyRewardsEventModel openRewards;
private RewardsCouponsEventModel rewardsCoupons;
private VouchersActivityEventModel vouchersActivity;
......@@ -91,6 +93,10 @@ public class WarplyEventBusManager {
this.questionnaire = questionnaire;
}
public WarplyEventBusManager(WarplyHealthEventModel health) {
this.health = health;
}
public WarplyEventBusManager(OpenMyRewardsEventModel openRewards) {
this.openRewards = openRewards;
}
......@@ -276,6 +282,10 @@ public class WarplyEventBusManager {
return questionnaire;
}
public WarplyHealthEventModel getHealth() {
return health;
}
public VouchersActivityEventModel getVouchersActivity() {
return vouchersActivity;
}
......
......@@ -103,6 +103,7 @@ import ly.warp.sdk.io.models.RefreshVouchersEventModel;
import ly.warp.sdk.io.models.UnifiedCoupon;
import ly.warp.sdk.io.models.WarplyCCMSEnabledModel;
import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
import ly.warp.sdk.io.models.WarplyHealthEventModel;
import ly.warp.sdk.io.models.WarplyPacingCardEventModel;
import ly.warp.sdk.io.models.WarplyPacingEventModel;
import ly.warp.sdk.io.models.WarplyUnifiedActivatedEventModel;
......@@ -543,29 +544,37 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
pacingWidgetVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingWidgetVisible));
} else if (parts[1].equals("steps") && parts[2].equals("shortcutEnabled")) { // This is for the pacing service
if (!isMyServiceRunning(WarplyHealthService.class)) {
LoyaltySDKFirebaseEventModel analyticsEvent = new LoyaltySDKFirebaseEventModel();
analyticsEvent.setEventName("loyalty_steps_activation");
EventBus.getDefault().post(new WarplyEventBusManager(analyticsEvent));
Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Warply.getWarplyContext().startForegroundService(stepsServiceIntent);
} else {
Warply.getWarplyContext().startService(stepsServiceIntent);
}
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(true);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
}
// if (!isMyServiceRunning(WarplyHealthService.class)) {
// LoyaltySDKFirebaseEventModel analyticsEvent = new LoyaltySDKFirebaseEventModel();
// analyticsEvent.setEventName("loyalty_steps_activation");
// EventBus.getDefault().post(new WarplyEventBusManager(analyticsEvent));
//
// Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Warply.getWarplyContext().startForegroundService(stepsServiceIntent);
// } else {
// Warply.getWarplyContext().startService(stepsServiceIntent);
// }
//
// WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
// pacingVisible.setVisible(true);
// EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
// }
WarplyHealthEventModel healthActive = new WarplyHealthEventModel();
healthActive.setActivated(true);
EventBus.getDefault().post(new WarplyEventBusManager(healthActive));
} else if (parts[1].equals("steps") && parts[2].equals("shortcutDisabled")) { // This is for the pacing service
Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
Warply.getWarplyContext().stopService(stepsServiceIntent);
WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
pacingVisible.setVisible(false);
EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
// Intent stepsServiceIntent = new Intent(Warply.getWarplyContext(), WarplyHealthService.class);
// Warply.getWarplyContext().stopService(stepsServiceIntent);
//
// WarplyPacingEventModel pacingVisible = new WarplyPacingEventModel();
// pacingVisible.setVisible(false);
// EventBus.getDefault().post(new WarplyEventBusManager(pacingVisible));
WarplyHealthEventModel healthActive = new WarplyHealthEventModel();
healthActive.setActivated(false);
EventBus.getDefault().post(new WarplyEventBusManager(healthActive));
} else if (parts[1].equals("request") || parts[1].equals("response")) {
WarpUtils.log("**************** WARPLY Webview Log START *****************");
WarpUtils.log(message);
......