Panagiotis Triantafyllou

pacing fixes, new empty wallet ui

...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
7 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 7 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
8 <uses-permission android:name="android.permission.BLUETOOTH" /> 8 <uses-permission android:name="android.permission.BLUETOOTH" />
9 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 9 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
10 + <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
10 11
11 <application> 12 <application>
12 <meta-data 13 <meta-data
......
...@@ -48,7 +48,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener { ...@@ -48,7 +48,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
48 mTvActiveTitle, mTvActiveCouponsHeader; 48 mTvActiveTitle, mTvActiveCouponsHeader;
49 private ConstraintLayout mClDealsBanner, mClDealsView, 49 private ConstraintLayout mClDealsBanner, mClDealsView,
50 mClGiftsBanner; 50 mClGiftsBanner;
51 - private LinearLayout mLlQuestionnaire, mLlUserBadge; 51 + private LinearLayout mLlQuestionnaire, mLlUserBadge, mLlEmptyWallet;
52 private float couponDfyValue = 0.0f; 52 private float couponDfyValue = 0.0f;
53 private RecyclerView mRecyclerCoupons; 53 private RecyclerView mRecyclerCoupons;
54 private ActiveCouponAdapter mAdapterCoupons; 54 private ActiveCouponAdapter mAdapterCoupons;
...@@ -80,6 +80,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener { ...@@ -80,6 +80,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
80 mIvProfilePhoto = findViewById(R.id.iv_profile_photo); 80 mIvProfilePhoto = findViewById(R.id.iv_profile_photo);
81 mTvActiveTitle = findViewById(R.id.tv_active_gifts); 81 mTvActiveTitle = findViewById(R.id.tv_active_gifts);
82 mTvActiveCouponsHeader = findViewById(R.id.tv_active_coupons_header); 82 mTvActiveCouponsHeader = findViewById(R.id.tv_active_coupons_header);
83 + mLlEmptyWallet = findViewById(R.id.ll_empty_wallet);
83 84
84 if (WarplyManagerHelper.getActiveDFYCoupons() != null) { 85 if (WarplyManagerHelper.getActiveDFYCoupons() != null) {
85 Collections.sort(WarplyManagerHelper.getActiveDFYCoupons(), new Comparator<ActiveDFYCouponModel>() { 86 Collections.sort(WarplyManagerHelper.getActiveDFYCoupons(), new Comparator<ActiveDFYCouponModel>() {
...@@ -117,7 +118,6 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener { ...@@ -117,7 +118,6 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
117 } 118 }
118 if (view.getId() == R.id.ll_user_questionnaire || view.getId() == R.id.ll_user_badge) { 119 if (view.getId() == R.id.ll_user_questionnaire || view.getId() == R.id.ll_user_badge) {
119 startActivityForResult(WarpViewActivity.createIntentFromURL(LoyaltyWallet.this, WarplyManagerHelper.openQuestionnaire()), 1000); 120 startActivityForResult(WarpViewActivity.createIntentFromURL(LoyaltyWallet.this, WarplyManagerHelper.openQuestionnaire()), 1000);
120 -// startActivity(WarpViewActivity.createIntentFromURL(LoyaltyWallet.this, WarplyManagerHelper.openPacing()));
121 return; 121 return;
122 } 122 }
123 if (view.getId() == R.id.cl_deals_cos) { 123 if (view.getId() == R.id.cl_deals_cos) {
...@@ -249,6 +249,10 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener { ...@@ -249,6 +249,10 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
249 } 249 }
250 } 250 }
251 251
252 + if (mClDealsBanner.getVisibility() == View.GONE && mClGiftsBanner.getVisibility() == View.GONE && mClDealsView.getVisibility() == View.GONE) {
253 + mLlEmptyWallet.setVisibility(View.VISIBLE);
254 + }
255 +
252 mIvBack.setOnClickListener(this); 256 mIvBack.setOnClickListener(this);
253 mLlQuestionnaire.setOnClickListener(this); 257 mLlQuestionnaire.setOnClickListener(this);
254 mLlUserBadge.setOnClickListener(this); 258 mLlUserBadge.setOnClickListener(this);
......
...@@ -147,7 +147,7 @@ public class WarpViewActivity extends WarpBaseActivity { ...@@ -147,7 +147,7 @@ public class WarpViewActivity extends WarpBaseActivity {
147 // finish(); 147 // finish();
148 // if (event.getPacingService() != null) 148 // if (event.getPacingService() != null)
149 // finish(); 149 // finish();
150 - if (event.getPacing() != null) 150 + if (event.getPacing() != null && !event.getPacing().isVisible())
151 finish(); 151 finish();
152 } 152 }
153 153
......
1 package ly.warp.sdk.services; 1 package ly.warp.sdk.services;
2 2
3 +import android.app.Notification;
4 +import android.app.NotificationChannel;
5 +import android.app.NotificationManager;
6 +import android.app.PendingIntent;
3 import android.app.Service; 7 import android.app.Service;
4 import android.content.Context; 8 import android.content.Context;
5 import android.content.Intent; 9 import android.content.Intent;
10 +import android.content.pm.PackageManager;
6 import android.hardware.Sensor; 11 import android.hardware.Sensor;
7 import android.hardware.SensorEvent; 12 import android.hardware.SensorEvent;
8 import android.hardware.SensorEventListener; 13 import android.hardware.SensorEventListener;
9 import android.hardware.SensorManager; 14 import android.hardware.SensorManager;
15 +import android.os.Build;
10 import android.os.IBinder; 16 import android.os.IBinder;
11 17
12 -import androidx.annotation.NonNull;
13 import androidx.annotation.Nullable; 18 import androidx.annotation.Nullable;
14 -import androidx.work.Worker; 19 +import androidx.annotation.RequiresApi;
15 -import androidx.work.WorkerParameters; 20 +import androidx.core.app.NotificationCompat;
16 21
17 -import org.greenrobot.eventbus.EventBus;
18 import org.json.JSONObject; 22 import org.json.JSONObject;
19 23
20 -import java.text.ParseException;
21 import java.text.SimpleDateFormat; 24 import java.text.SimpleDateFormat;
22 import java.util.Date; 25 import java.util.Date;
23 import java.util.Locale; 26 import java.util.Locale;
24 27
28 +import ly.warp.sdk.R;
29 +import ly.warp.sdk.activities.BaseFragmentActivity;
25 import ly.warp.sdk.io.callbacks.CallbackReceiver; 30 import ly.warp.sdk.io.callbacks.CallbackReceiver;
26 -import ly.warp.sdk.io.callbacks.WarplyHealthCallback;
27 -import ly.warp.sdk.io.models.ContexualEventModel;
28 import ly.warp.sdk.io.request.PacingCalculateRequest; 31 import ly.warp.sdk.io.request.PacingCalculateRequest;
29 import ly.warp.sdk.utils.WarpUtils; 32 import ly.warp.sdk.utils.WarpUtils;
30 -import ly.warp.sdk.utils.managers.WarplyEventBusManager;
31 -import ly.warp.sdk.utils.managers.WarplyHealthManager;
32 import ly.warp.sdk.utils.managers.WarplyManager; 33 import ly.warp.sdk.utils.managers.WarplyManager;
33 34
34 /** 35 /**
35 * Created by Panagiotis Triantafyllou on 03/Aug/2022. 36 * Created by Panagiotis Triantafyllou on 03/Aug/2022.
36 */ 37 */
37 -public class WarplyHealthService extends /*Worker*/ Service implements SensorEventListener { 38 +public class WarplyHealthService extends Service implements SensorEventListener {
38 39
39 // =========================================================== 40 // ===========================================================
40 // Constants 41 // Constants
41 // =========================================================== 42 // ===========================================================
42 43
44 + private static final String STEPS_CHANNEL_ID = "stepschannel";
45 +
43 // =========================================================== 46 // ===========================================================
44 // Fields 47 // Fields
45 // =========================================================== 48 // ===========================================================
46 49
47 - private Context mContext;
48 private SensorManager mSensorManager; 50 private SensorManager mSensorManager;
49 private Sensor mSensor; 51 private Sensor mSensor;
50 private int mSteps = 0; 52 private int mSteps = 0;
...@@ -61,22 +63,11 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -61,22 +63,11 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
61 private float[] velRing = new float[VEL_RING_SIZE]; 63 private float[] velRing = new float[VEL_RING_SIZE];
62 private long lastStepTimeNs = 0; 64 private long lastStepTimeNs = 0;
63 private float oldVelocityEstimate = 0; 65 private float oldVelocityEstimate = 0;
64 - // if we want to send the steps back to an activity/fragment/service etc
65 -// private static WarplyHealthCallback mHealthCallback;
66 66
67 // =========================================================== 67 // ===========================================================
68 // Contructors 68 // Contructors
69 // =========================================================== 69 // ===========================================================
70 70
71 -// public WarplyHealthService(@NonNull Context context, @NonNull WorkerParameters workerParams) {
72 -// super(context, workerParams);
73 -//
74 -// mContext = context;
75 -// mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
76 -// mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
77 -// registerStepSensor();
78 -// }
79 -
80 // =========================================================== 71 // ===========================================================
81 // Methods for/from SuperClass/Interfaces 72 // Methods for/from SuperClass/Interfaces
82 // =========================================================== 73 // ===========================================================
...@@ -91,14 +82,39 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -91,14 +82,39 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
91 registerStepSensor(); 82 registerStepSensor();
92 } 83 }
93 84
85 + @RequiresApi(api = Build.VERSION_CODES.O)
94 @Override 86 @Override
95 public int onStartCommand(Intent intent, int flags, int startId) { 87 public int onStartCommand(Intent intent, int flags, int startId) {
88 + NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
89 + PackageManager pm = getPackageManager();
90 + Intent bIntent = pm.getLaunchIntentForPackage(getPackageName());
91 + PendingIntent pbIntent = PendingIntent.getActivity(this, 2001, bIntent, PendingIntent.FLAG_IMMUTABLE);
92 +
93 + NotificationCompat.Builder b = new NotificationCompat.Builder(this, STEPS_CHANNEL_ID);
94 + b.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
95 + b.setChannelId(STEPS_CHANNEL_ID);
96 + b.setContentTitle(getString(R.string.cos_steps_for_good_notification_title));
97 + b.setContentText("Subtitle");
98 + b.setContentIntent(pbIntent);
99 + b.setAutoCancel(true);
100 + b.setOngoing(true);
101 + b.setSmallIcon(R.drawable.ic_launcher);
102 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notificationManager != null) {
103 + NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID, "steps_notification_channel", NotificationManager.IMPORTANCE_DEFAULT);
104 + notificationManager.createNotificationChannel(notificationChannel);
105 + Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
106 + this.startForeground(2001, notification_build);
107 + } else {
108 + Notification notification_build = b.build();
109 + this.startForeground(2001, notification_build);
110 + }
111 +
96 new Thread( 112 new Thread(
97 () -> { 113 () -> {
98 while (true) { 114 while (true) {
99 sendSteps(); 115 sendSteps();
100 try { 116 try {
101 - Thread.sleep(10000); 117 + Thread.sleep(900000);
102 } catch (InterruptedException e) { 118 } catch (InterruptedException e) {
103 e.printStackTrace(); 119 e.printStackTrace();
104 } 120 }
...@@ -106,7 +122,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -106,7 +122,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
106 } 122 }
107 ).start(); 123 ).start();
108 124
109 - return super.onStartCommand(intent, flags, startId); 125 +// return super.onStartCommand(intent, flags, startId);
126 + return Service.START_STICKY;
110 } 127 }
111 128
112 @Override 129 @Override
...@@ -122,24 +139,6 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -122,24 +139,6 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
122 return null; 139 return null;
123 } 140 }
124 141
125 -// @NonNull
126 -// @Override
127 -// public Result doWork() {
128 -// sendSteps();
129 -// return Result.success();
130 -// }
131 -
132 -// @Override
133 -// public void onStopped() {
134 -// super.onStopped();
135 -//
136 -// unregisterStepSensor();
137 -//
138 -// if (WarpUtils.getStepsCounter(mContext) > 0) {
139 -// sendSteps();
140 -// }
141 -// }
142 -
143 @Override 142 @Override
144 public void onSensorChanged(SensorEvent sensorEvent) { 143 public void onSensorChanged(SensorEvent sensorEvent) {
145 if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { 144 if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
...@@ -201,10 +200,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -201,10 +200,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
201 && oldVelocityEstimate <= STEP_THRESHOLD 200 && oldVelocityEstimate <= STEP_THRESHOLD
202 && (timeNs - lastStepTimeNs > STEP_DELAY_NS)) { 201 && (timeNs - lastStepTimeNs > STEP_DELAY_NS)) {
203 mSteps++; 202 mSteps++;
204 - WarpUtils.setStepsCounter(mContext, mSteps); 203 + WarpUtils.setStepsCounter(this, mSteps);
205 204
206 - // if we want to send the steps back to an activity/fragment/service etc
207 -// mHealthCallback.onStepCount(mSteps);
208 lastStepTimeNs = timeNs; 205 lastStepTimeNs = timeNs;
209 } 206 }
210 oldVelocityEstimate = velocityEstimate; 207 oldVelocityEstimate = velocityEstimate;
...@@ -251,16 +248,15 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve ...@@ -251,16 +248,15 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
251 String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).format(new Date()); 248 String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).format(new Date());
252 249
253 WarplyManager.setPacingDetails(new PacingCalculateRequest() 250 WarplyManager.setPacingDetails(new PacingCalculateRequest()
254 - .setCounter(WarpUtils.getStepsCounter(mContext)) 251 + .setCounter(WarpUtils.getStepsCounter(this))
255 .setDate(date), 252 .setDate(date),
256 new CallbackReceiver<JSONObject>() { 253 new CallbackReceiver<JSONObject>() {
257 @Override 254 @Override
258 public void onSuccess(JSONObject result) { 255 public void onSuccess(JSONObject result) {
259 - WarpUtils.log("Warply Health Service success");
260 int status = result.optInt("status", 2); 256 int status = result.optInt("status", 2);
261 if (status == 1) { 257 if (status == 1) {
262 mSteps = 0; 258 mSteps = 0;
263 - WarpUtils.setStepsCounter(mContext, 0); 259 + WarpUtils.setStepsCounter(WarplyHealthService.this, 0);
264 } 260 }
265 } 261 }
266 262
......
...@@ -137,8 +137,8 @@ ...@@ -137,8 +137,8 @@
137 android:id="@+id/ll_user_questionnaire" 137 android:id="@+id/ll_user_questionnaire"
138 android:layout_width="wrap_content" 138 android:layout_width="wrap_content"
139 android:layout_height="wrap_content" 139 android:layout_height="wrap_content"
140 - android:gravity="center"
141 android:background="@drawable/shape_cos_grey5" 140 android:background="@drawable/shape_cos_grey5"
141 + android:gravity="center"
142 android:paddingHorizontal="8dp" 142 android:paddingHorizontal="8dp"
143 android:paddingVertical="4dp" 143 android:paddingVertical="4dp"
144 android:visibility="gone" 144 android:visibility="gone"
...@@ -340,8 +340,8 @@ ...@@ -340,8 +340,8 @@
340 android:layout_height="wrap_content" 340 android:layout_height="wrap_content"
341 android:layout_marginHorizontal="24dp" 341 android:layout_marginHorizontal="24dp"
342 android:orientation="vertical" 342 android:orientation="vertical"
343 - app:layout_constraintEnd_toStartOf="@+id/iv_deals_circle"
344 app:layout_constraintBottom_toBottomOf="parent" 343 app:layout_constraintBottom_toBottomOf="parent"
344 + app:layout_constraintEnd_toStartOf="@+id/iv_deals_circle"
345 app:layout_constraintStart_toStartOf="parent" 345 app:layout_constraintStart_toStartOf="parent"
346 app:layout_constraintTop_toTopOf="parent"> 346 app:layout_constraintTop_toTopOf="parent">
347 347
...@@ -349,28 +349,28 @@ ...@@ -349,28 +349,28 @@
349 android:id="@+id/tv_active_gifts" 349 android:id="@+id/tv_active_gifts"
350 android:layout_width="wrap_content" 350 android:layout_width="wrap_content"
351 android:layout_height="wrap_content" 351 android:layout_height="wrap_content"
352 - tools:text="@string/cos_active_deals"
353 android:textColor="@color/blue_dark" 352 android:textColor="@color/blue_dark"
354 android:textFontWeight="600" 353 android:textFontWeight="600"
355 - android:textSize="18sp" /> 354 + android:textSize="18sp"
355 + tools:text="@string/cos_active_deals" />
356 356
357 <TextView 357 <TextView
358 android:id="@+id/tv_active_deals_text" 358 android:id="@+id/tv_active_deals_text"
359 android:layout_width="wrap_content" 359 android:layout_width="wrap_content"
360 android:layout_height="wrap_content" 360 android:layout_height="wrap_content"
361 + android:ellipsize="end"
362 + android:maxLines="2"
361 android:textColor="@color/blue_dark" 363 android:textColor="@color/blue_dark"
362 android:textSize="18sp" 364 android:textSize="18sp"
363 - android:maxLines="2"
364 - android:ellipsize="end"
365 android:textStyle="bold" 365 android:textStyle="bold"
366 tools:text="961544809" /> 366 tools:text="961544809" />
367 367
368 -<!-- <TextView--> 368 + <!-- <TextView-->
369 -<!-- android:id="@+id/tv_active_deals_date_text"--> 369 + <!-- android:id="@+id/tv_active_deals_date_text"-->
370 -<!-- android:layout_width="wrap_content"--> 370 + <!-- android:layout_width="wrap_content"-->
371 -<!-- android:layout_height="wrap_content"--> 371 + <!-- android:layout_height="wrap_content"-->
372 -<!-- tools:text="@string/cos_active_coupon_date"--> 372 + <!-- tools:text="@string/cos_active_coupon_date"-->
373 -<!-- android:textColor="@color/blue_dark" />--> 373 + <!-- android:textColor="@color/blue_dark" />-->
374 </LinearLayout> 374 </LinearLayout>
375 375
376 <ImageView 376 <ImageView
...@@ -404,6 +404,29 @@ ...@@ -404,6 +404,29 @@
404 android:layout_height="wrap_content" 404 android:layout_height="wrap_content"
405 android:layout_marginHorizontal="2dp" 405 android:layout_marginHorizontal="2dp"
406 android:paddingBottom="40dp" /> 406 android:paddingBottom="40dp" />
407 +
408 + <LinearLayout
409 + android:id="@+id/ll_empty_wallet"
410 + android:layout_width="match_parent"
411 + android:layout_height="wrap_content"
412 + android:layout_marginHorizontal="32dp"
413 + android:gravity="center"
414 + android:visibility="gone"
415 + android:orientation="vertical">
416 +
417 + <ImageView
418 + android:layout_width="64dp"
419 + android:layout_height="64dp"
420 + android:src="@drawable/ic_empty_wallet" />
421 +
422 + <TextView
423 + android:layout_width="wrap_content"
424 + android:layout_height="wrap_content"
425 + android:layout_marginTop="8dp"
426 + android:gravity="center"
427 + android:text="@string/cos_empty_wallet"
428 + android:textColor="@color/cos_white_tr" />
429 + </LinearLayout>
407 </LinearLayout> 430 </LinearLayout>
408 </RelativeLayout> 431 </RelativeLayout>
409 </ScrollView> 432 </ScrollView>
......
...@@ -55,4 +55,5 @@ ...@@ -55,4 +55,5 @@
55 <color name="cos_light_grey2">#8B97A3</color> 55 <color name="cos_light_grey2">#8B97A3</color>
56 <color name="cos_cyan4">#2EAFB9</color> 56 <color name="cos_cyan4">#2EAFB9</color>
57 <color name="cos_dark_grey">#394A5B</color> 57 <color name="cos_dark_grey">#394A5B</color>
58 + <color name="cos_white_tr">#9CFFFFFF</color>
58 </resources> 59 </resources>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -113,6 +113,8 @@ ...@@ -113,6 +113,8 @@
113 <string name="cos_shared_gifts_tab">Μοιρασμένα δώρα</string> 113 <string name="cos_shared_gifts_tab">Μοιρασμένα δώρα</string>
114 <string name="cos_shared_coupon_receiver">Εκπτωτικό κουπόνι προς</string> 114 <string name="cos_shared_coupon_receiver">Εκπτωτικό κουπόνι προς</string>
115 <string name="cos_shared_coupon_sender">Έκπτωτικό κουπόνι από</string> 115 <string name="cos_shared_coupon_sender">Έκπτωτικό κουπόνι από</string>
116 + <string name="cos_steps_for_good_notification_title">Steps for Good</string>
117 + <string name="cos_empty_wallet">Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For YOU και βρες αποκλειστικές προσφορές!</string>
116 118
117 <string-array name="coupons_array"> 119 <string-array name="coupons_array">
118 <item>Κουπόνια</item> 120 <item>Κουπόνια</item>
......