Panagiotis Triantafyllou

pacing fixes, new empty wallet ui

......@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application>
<meta-data
......
......@@ -48,7 +48,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
mTvActiveTitle, mTvActiveCouponsHeader;
private ConstraintLayout mClDealsBanner, mClDealsView,
mClGiftsBanner;
private LinearLayout mLlQuestionnaire, mLlUserBadge;
private LinearLayout mLlQuestionnaire, mLlUserBadge, mLlEmptyWallet;
private float couponDfyValue = 0.0f;
private RecyclerView mRecyclerCoupons;
private ActiveCouponAdapter mAdapterCoupons;
......@@ -80,6 +80,7 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
mIvProfilePhoto = findViewById(R.id.iv_profile_photo);
mTvActiveTitle = findViewById(R.id.tv_active_gifts);
mTvActiveCouponsHeader = findViewById(R.id.tv_active_coupons_header);
mLlEmptyWallet = findViewById(R.id.ll_empty_wallet);
if (WarplyManagerHelper.getActiveDFYCoupons() != null) {
Collections.sort(WarplyManagerHelper.getActiveDFYCoupons(), new Comparator<ActiveDFYCouponModel>() {
......@@ -117,7 +118,6 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
}
if (view.getId() == R.id.ll_user_questionnaire || view.getId() == R.id.ll_user_badge) {
startActivityForResult(WarpViewActivity.createIntentFromURL(LoyaltyWallet.this, WarplyManagerHelper.openQuestionnaire()), 1000);
// startActivity(WarpViewActivity.createIntentFromURL(LoyaltyWallet.this, WarplyManagerHelper.openPacing()));
return;
}
if (view.getId() == R.id.cl_deals_cos) {
......@@ -249,6 +249,10 @@ public class LoyaltyWallet extends Activity implements View.OnClickListener {
}
}
if (mClDealsBanner.getVisibility() == View.GONE && mClGiftsBanner.getVisibility() == View.GONE && mClDealsView.getVisibility() == View.GONE) {
mLlEmptyWallet.setVisibility(View.VISIBLE);
}
mIvBack.setOnClickListener(this);
mLlQuestionnaire.setOnClickListener(this);
mLlUserBadge.setOnClickListener(this);
......
......@@ -147,7 +147,7 @@ public class WarpViewActivity extends WarpBaseActivity {
// finish();
// if (event.getPacingService() != null)
// finish();
if (event.getPacing() != null)
if (event.getPacing() != null && !event.getPacing().isVisible())
finish();
}
......
package ly.warp.sdk.services;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.IBinder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import org.greenrobot.eventbus.EventBus;
import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import ly.warp.sdk.R;
import ly.warp.sdk.activities.BaseFragmentActivity;
import ly.warp.sdk.io.callbacks.CallbackReceiver;
import ly.warp.sdk.io.callbacks.WarplyHealthCallback;
import ly.warp.sdk.io.models.ContexualEventModel;
import ly.warp.sdk.io.request.PacingCalculateRequest;
import ly.warp.sdk.utils.WarpUtils;
import ly.warp.sdk.utils.managers.WarplyEventBusManager;
import ly.warp.sdk.utils.managers.WarplyHealthManager;
import ly.warp.sdk.utils.managers.WarplyManager;
/**
* Created by Panagiotis Triantafyllou on 03/Aug/2022.
*/
public class WarplyHealthService extends /*Worker*/ Service implements SensorEventListener {
public class WarplyHealthService extends Service implements SensorEventListener {
// ===========================================================
// Constants
// ===========================================================
private static final String STEPS_CHANNEL_ID = "stepschannel";
// ===========================================================
// Fields
// ===========================================================
private Context mContext;
private SensorManager mSensorManager;
private Sensor mSensor;
private int mSteps = 0;
......@@ -61,22 +63,11 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
private float[] velRing = new float[VEL_RING_SIZE];
private long lastStepTimeNs = 0;
private float oldVelocityEstimate = 0;
// if we want to send the steps back to an activity/fragment/service etc
// private static WarplyHealthCallback mHealthCallback;
// ===========================================================
// Contructors
// ===========================================================
// public WarplyHealthService(@NonNull Context context, @NonNull WorkerParameters workerParams) {
// super(context, workerParams);
//
// mContext = context;
// mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
// mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
// registerStepSensor();
// }
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
......@@ -91,14 +82,39 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
registerStepSensor();
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
PackageManager pm = getPackageManager();
Intent bIntent = pm.getLaunchIntentForPackage(getPackageName());
PendingIntent pbIntent = PendingIntent.getActivity(this, 2001, bIntent, PendingIntent.FLAG_IMMUTABLE);
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.setContentText("Subtitle");
b.setContentIntent(pbIntent);
b.setAutoCancel(true);
b.setOngoing(true);
b.setSmallIcon(R.drawable.ic_launcher);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notificationManager != null) {
NotificationChannel notificationChannel = new NotificationChannel(STEPS_CHANNEL_ID, "steps_notification_channel", NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(notificationChannel);
Notification notification_build = b.setChannelId(STEPS_CHANNEL_ID).build();
this.startForeground(2001, notification_build);
} else {
Notification notification_build = b.build();
this.startForeground(2001, notification_build);
}
new Thread(
() -> {
while (true) {
sendSteps();
try {
Thread.sleep(10000);
Thread.sleep(900000);
} catch (InterruptedException e) {
e.printStackTrace();
}
......@@ -106,7 +122,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
}
).start();
return super.onStartCommand(intent, flags, startId);
// return super.onStartCommand(intent, flags, startId);
return Service.START_STICKY;
}
@Override
......@@ -122,24 +139,6 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
return null;
}
// @NonNull
// @Override
// public Result doWork() {
// sendSteps();
// return Result.success();
// }
// @Override
// public void onStopped() {
// super.onStopped();
//
// unregisterStepSensor();
//
// if (WarpUtils.getStepsCounter(mContext) > 0) {
// sendSteps();
// }
// }
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
......@@ -201,10 +200,8 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
&& oldVelocityEstimate <= STEP_THRESHOLD
&& (timeNs - lastStepTimeNs > STEP_DELAY_NS)) {
mSteps++;
WarpUtils.setStepsCounter(mContext, mSteps);
WarpUtils.setStepsCounter(this, mSteps);
// if we want to send the steps back to an activity/fragment/service etc
// mHealthCallback.onStepCount(mSteps);
lastStepTimeNs = timeNs;
}
oldVelocityEstimate = velocityEstimate;
......@@ -251,16 +248,15 @@ public class WarplyHealthService extends /*Worker*/ Service implements SensorEve
String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.getDefault()).format(new Date());
WarplyManager.setPacingDetails(new PacingCalculateRequest()
.setCounter(WarpUtils.getStepsCounter(mContext))
.setCounter(WarpUtils.getStepsCounter(this))
.setDate(date),
new CallbackReceiver<JSONObject>() {
@Override
public void onSuccess(JSONObject result) {
WarpUtils.log("Warply Health Service success");
int status = result.optInt("status", 2);
if (status == 1) {
mSteps = 0;
WarpUtils.setStepsCounter(mContext, 0);
WarpUtils.setStepsCounter(WarplyHealthService.this, 0);
}
}
......
......@@ -137,8 +137,8 @@
android:id="@+id/ll_user_questionnaire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/shape_cos_grey5"
android:gravity="center"
android:paddingHorizontal="8dp"
android:paddingVertical="4dp"
android:visibility="gone"
......@@ -340,8 +340,8 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="@+id/iv_deals_circle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_deals_circle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
......@@ -349,28 +349,28 @@
android:id="@+id/tv_active_gifts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="@string/cos_active_deals"
android:textColor="@color/blue_dark"
android:textFontWeight="600"
android:textSize="18sp" />
android:textSize="18sp"
tools:text="@string/cos_active_deals" />
<TextView
android:id="@+id/tv_active_deals_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/blue_dark"
android:textSize="18sp"
android:maxLines="2"
android:ellipsize="end"
android:textStyle="bold"
tools:text="961544809" />
<!-- <TextView-->
<!-- android:id="@+id/tv_active_deals_date_text"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- tools:text="@string/cos_active_coupon_date"-->
<!-- android:textColor="@color/blue_dark" />-->
<!-- <TextView-->
<!-- android:id="@+id/tv_active_deals_date_text"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- tools:text="@string/cos_active_coupon_date"-->
<!-- android:textColor="@color/blue_dark" />-->
</LinearLayout>
<ImageView
......@@ -404,6 +404,29 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="2dp"
android:paddingBottom="40dp" />
<LinearLayout
android:id="@+id/ll_empty_wallet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="32dp"
android:gravity="center"
android:visibility="gone"
android:orientation="vertical">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@drawable/ic_empty_wallet" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/cos_empty_wallet"
android:textColor="@color/cos_white_tr" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
......
......@@ -55,4 +55,5 @@
<color name="cos_light_grey2">#8B97A3</color>
<color name="cos_cyan4">#2EAFB9</color>
<color name="cos_dark_grey">#394A5B</color>
<color name="cos_white_tr">#9CFFFFFF</color>
</resources>
\ No newline at end of file
......
......@@ -113,6 +113,8 @@
<string name="cos_shared_gifts_tab">Μοιρασμένα δώρα</string>
<string name="cos_shared_coupon_receiver">Εκπτωτικό κουπόνι προς</string>
<string name="cos_shared_coupon_sender">Έκπτωτικό κουπόνι από</string>
<string name="cos_steps_for_good_notification_title">Steps for Good</string>
<string name="cos_empty_wallet">Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For YOU και βρες αποκλειστικές προσφορές!</string>
<string-array name="coupons_array">
<item>Κουπόνια</item>
......