Panagiotis Triantafyllou

more fixes

...@@ -4,6 +4,7 @@ import android.app.Activity; ...@@ -4,6 +4,7 @@ import android.app.Activity;
4 import android.content.Context; 4 import android.content.Context;
5 import android.os.Bundle; 5 import android.os.Bundle;
6 import android.text.TextUtils; 6 import android.text.TextUtils;
7 +import android.text.method.LinkMovementMethod;
7 import android.util.Log; 8 import android.util.Log;
8 import android.view.LayoutInflater; 9 import android.view.LayoutInflater;
9 import android.view.View; 10 import android.view.View;
...@@ -13,6 +14,9 @@ import android.widget.LinearLayout; ...@@ -13,6 +14,9 @@ import android.widget.LinearLayout;
13 import android.widget.TextView; 14 import android.widget.TextView;
14 15
15 import androidx.appcompat.app.AlertDialog; 16 import androidx.appcompat.app.AlertDialog;
17 +import androidx.core.text.HtmlCompat;
18 +import androidx.work.OneTimeWorkRequest;
19 +import androidx.work.WorkManager;
16 20
17 import com.bumptech.glide.Glide; 21 import com.bumptech.glide.Glide;
18 import com.bumptech.glide.load.engine.DiskCacheStrategy; 22 import com.bumptech.glide.load.engine.DiskCacheStrategy;
...@@ -23,14 +27,20 @@ import org.json.JSONArray; ...@@ -23,14 +27,20 @@ import org.json.JSONArray;
23 import org.json.JSONException; 27 import org.json.JSONException;
24 import org.json.JSONObject; 28 import org.json.JSONObject;
25 29
30 +import java.util.ArrayList;
31 +
26 import ly.warp.sdk.R; 32 import ly.warp.sdk.R;
27 import ly.warp.sdk.io.callbacks.CallbackReceiver; 33 import ly.warp.sdk.io.callbacks.CallbackReceiver;
34 +import ly.warp.sdk.io.models.Campaign;
28 import ly.warp.sdk.io.models.Consumer; 35 import ly.warp.sdk.io.models.Consumer;
36 +import ly.warp.sdk.io.models.CouponList;
29 import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; 37 import ly.warp.sdk.io.models.LoyaltyContextualOfferModel;
30 import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel; 38 import ly.warp.sdk.io.models.LoyaltySDKFirebaseEventModel;
31 import ly.warp.sdk.io.models.WarplyCCMSEnabledModel; 39 import ly.warp.sdk.io.models.WarplyCCMSEnabledModel;
40 +import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel;
32 import ly.warp.sdk.io.request.CosmoteSubmitOrderRequest; 41 import ly.warp.sdk.io.request.CosmoteSubmitOrderRequest;
33 import ly.warp.sdk.io.request.WarplyConsumerRequest; 42 import ly.warp.sdk.io.request.WarplyConsumerRequest;
43 +import ly.warp.sdk.services.EventCampaignService;
34 import ly.warp.sdk.utils.managers.WarplyAnalyticsManager; 44 import ly.warp.sdk.utils.managers.WarplyAnalyticsManager;
35 import ly.warp.sdk.utils.managers.WarplyEventBusManager; 45 import ly.warp.sdk.utils.managers.WarplyEventBusManager;
36 import ly.warp.sdk.utils.managers.WarplyManager; 46 import ly.warp.sdk.utils.managers.WarplyManager;
...@@ -48,11 +58,12 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -48,11 +58,12 @@ public class ContextualActivity extends Activity implements View.OnClickListener
48 // Fields 58 // Fields
49 // =========================================================== 59 // ===========================================================
50 60
51 - private ImageView mIvBack, mIvCampaignPhoto; 61 + private ImageView mIvBack, mIvCampaignPhoto, mIvTermsArrow;
52 - private TextView mTvCampaignTitle, mTvCampaignSubtitle; 62 + private TextView mTvCampaignTitle, mTvCampaignSubtitle, mTvTerms, mTvTermsValue;
53 private LoyaltyContextualOfferModel mCCMS = new LoyaltyContextualOfferModel(); 63 private LoyaltyContextualOfferModel mCCMS = new LoyaltyContextualOfferModel();
54 - private LinearLayout mLlActivateOffer; 64 + private LinearLayout mLlActivateOffer, mLlTerms;
55 private Consumer mConsumer; 65 private Consumer mConsumer;
66 + private boolean mIsTermsPressed = false;
56 private String mSender = ""; 67 private String mSender = "";
57 private AlertDialog mAlertDialogAskActivate, mAlertDialogErrorActivating, mAlertDialogSuccessActivating; 68 private AlertDialog mAlertDialogAskActivate, mAlertDialogErrorActivating, mAlertDialogSuccessActivating;
58 69
...@@ -72,6 +83,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -72,6 +83,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener
72 mIvCampaignPhoto = findViewById(R.id.imageView6); 83 mIvCampaignPhoto = findViewById(R.id.imageView6);
73 mTvCampaignSubtitle = findViewById(R.id.textView14); 84 mTvCampaignSubtitle = findViewById(R.id.textView14);
74 mLlActivateOffer = findViewById(R.id.ll_activate_button); 85 mLlActivateOffer = findViewById(R.id.ll_activate_button);
86 + mTvTerms = findViewById(R.id.tv_terms);
87 + mLlTerms = findViewById(R.id.ll_terms_inner);
88 + mIvTermsArrow = findViewById(R.id.iv_terms_arrow);
89 + mTvTermsValue = findViewById(R.id.tv_terms_value);
75 90
76 initViews(); 91 initViews();
77 } 92 }
...@@ -98,6 +113,18 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -98,6 +113,18 @@ public class ContextualActivity extends Activity implements View.OnClickListener
98 } 113 }
99 if (view.getId() == R.id.ll_activate_button) { 114 if (view.getId() == R.id.ll_activate_button) {
100 showActivationDialog(); 115 showActivationDialog();
116 + return;
117 + }
118 + if (view.getId() == R.id.ll_terms_inner) {
119 + if (mIsTermsPressed) {
120 + mIsTermsPressed = false;
121 + mTvTermsValue.setVisibility(View.GONE);
122 + mIvTermsArrow.setImageDrawable(getDrawable(R.drawable.ic_down_dark_new));
123 + } else {
124 + mIsTermsPressed = true;
125 + mTvTermsValue.setVisibility(View.VISIBLE);
126 + mIvTermsArrow.setImageDrawable(getDrawable(R.drawable.ic_up_dark_new));
127 + }
101 } 128 }
102 } 129 }
103 130
...@@ -108,6 +135,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -108,6 +135,10 @@ public class ContextualActivity extends Activity implements View.OnClickListener
108 private void initViews() { 135 private void initViews() {
109 mTvCampaignTitle.setText(mCCMS.getTitleOffer()); 136 mTvCampaignTitle.setText(mCCMS.getTitleOffer());
110 mTvCampaignSubtitle.setText(mCCMS.getDescription()); 137 mTvCampaignSubtitle.setText(mCCMS.getDescription());
138 + mLlTerms.setOnClickListener(this);
139 +// mTvTermsValue.setText(HtmlCompat.fromHtml(mCCMS.getTermsAndConditions(), HtmlCompat.FROM_HTML_MODE_COMPACT));
140 +// mTvTermsValue.setMovementMethod(LinkMovementMethod.getInstance());
141 + mTvTermsValue.setText(mCCMS.getTermsAndConditions());
111 142
112 if (!TextUtils.isEmpty(mCCMS.getImageUrl())) { 143 if (!TextUtils.isEmpty(mCCMS.getImageUrl())) {
113 Glide.with(this) 144 Glide.with(this)
...@@ -277,6 +308,7 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -277,6 +308,7 @@ public class ContextualActivity extends Activity implements View.OnClickListener
277 .setMessage(R.string.cos_dlg_activate_success_subtitle) 308 .setMessage(R.string.cos_dlg_activate_success_subtitle)
278 .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { 309 .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> {
279 dialogPositive.dismiss(); 310 dialogPositive.dismiss();
311 + onBackPressed();
280 }) 312 })
281 .show(); 313 .show();
282 } 314 }
...@@ -303,9 +335,11 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -303,9 +335,11 @@ public class ContextualActivity extends Activity implements View.OnClickListener
303 public void onSuccess(JSONObject result) { 335 public void onSuccess(JSONObject result) {
304 int status = result.optInt("status", 2); 336 int status = result.optInt("status", 2);
305 // runOnUiThread(() -> { 337 // runOnUiThread(() -> {
306 - if (status == 1) 338 + if (status == 1) {
307 successActivatingDialog(); 339 successActivatingDialog();
308 - else 340 + WarplyManager.getUserCouponsWithCouponsets(mUserCouponsReceiver);
341 + WarplyManager.getCampaigns(mCampaignsCallback);
342 + } else
309 errorActivatingDialog(); 343 errorActivatingDialog();
310 // }); 344 // });
311 } 345 }
...@@ -316,4 +350,31 @@ public class ContextualActivity extends Activity implements View.OnClickListener ...@@ -316,4 +350,31 @@ public class ContextualActivity extends Activity implements View.OnClickListener
316 errorActivatingDialog(); 350 errorActivatingDialog();
317 } 351 }
318 }; 352 };
353 +
354 + private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() {
355 + @Override
356 + public void onSuccess(CouponList result) {
357 + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel();
358 + couponsChanged.setChanged(true);
359 + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged));
360 + }
361 +
362 + @Override
363 + public void onFailure(int errorCode) {
364 +
365 + }
366 + };
367 +
368 + private CallbackReceiver<ArrayList<Campaign>> mCampaignsCallback = new CallbackReceiver<ArrayList<Campaign>>() {
369 + @Override
370 + public void onSuccess(ArrayList<Campaign> result) {
371 + OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignService.class).build();
372 + WorkManager.getInstance(ContextualActivity.this).enqueue(mywork);
373 + }
374 +
375 + @Override
376 + public void onFailure(int errorCode) {
377 +
378 + }
379 + };
319 } 380 }
......
...@@ -139,7 +139,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -139,7 +139,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
139 private Activity WarpActivity; 139 private Activity WarpActivity;
140 private String geolocationOrigin = ""; 140 private String geolocationOrigin = "";
141 private Callback geolocationCallback; 141 private Callback geolocationCallback;
142 - private static boolean mWebviewLoaded = false; 142 + private static boolean mWebviewLoaded = false, mWebviewSupermarket = false;
143 143
144 // =========================================================== 144 // ===========================================================
145 // Constructors 145 // Constructors
...@@ -159,6 +159,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -159,6 +159,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
159 ProcessLifecycleOwner.get().getLifecycle().addObserver(this); 159 ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
160 WarpActivity = activity; 160 WarpActivity = activity;
161 mWebviewLoaded = false; 161 mWebviewLoaded = false;
162 + mWebviewSupermarket = false;
162 init(); 163 init();
163 } 164 }
164 165
...@@ -436,6 +437,13 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -436,6 +437,13 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
436 437
437 }); 438 });
438 } 439 }
440 + if (mWebviewSupermarket) {
441 + String scriptSourceInit = "webviewDidFocusRefresh(" + String.valueOf(mWebviewSupermarket) + ");";
442 + WarpView.this.evaluateJavascript(scriptSourceInit, s -> {
443 +
444 + });
445 + mWebviewSupermarket = false;
446 + }
439 } 447 }
440 448
441 @Override 449 @Override
...@@ -472,7 +480,10 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { ...@@ -472,7 +480,10 @@ public class WarpView extends WebView implements DefaultLifecycleObserver {
472 public void sendMessage(String message) { 480 public void sendMessage(String message) {
473 if (message.contains("event")) { 481 if (message.contains("event")) {
474 String[] parts = message.split(":"); 482 String[] parts = message.split(":");
475 - if (parts[1].equals("closeArtwork")) { 483 + if (parts[1].equals("webviewRefresh")) {
484 + mWebviewSupermarket = true;
485 + } else if (parts[1].equals("closeArtwork")) {
486 + mWebviewSupermarket = false;
476 QuestionnaireEventModel questionnaireEvent = new QuestionnaireEventModel(); 487 QuestionnaireEventModel questionnaireEvent = new QuestionnaireEventModel();
477 questionnaireEvent.setName(parts[1]); 488 questionnaireEvent.setName(parts[1]);
478 EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent)); 489 EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent));
......
...@@ -101,10 +101,11 @@ ...@@ -101,10 +101,11 @@
101 android:id="@+id/ll_activate_button" 101 android:id="@+id/ll_activate_button"
102 android:layout_width="160dp" 102 android:layout_width="160dp"
103 android:layout_height="55dp" 103 android:layout_height="55dp"
104 + android:layout_marginTop="27dp"
104 android:background="@drawable/selector_button_green" 105 android:background="@drawable/selector_button_green"
105 android:gravity="center" 106 android:gravity="center"
106 android:orientation="horizontal" 107 android:orientation="horizontal"
107 - app:layout_constraintBottom_toBottomOf="parent" 108 + app:layout_constraintTop_toBottomOf="@+id/textView14"
108 app:layout_constraintEnd_toEndOf="parent" 109 app:layout_constraintEnd_toEndOf="parent"
109 app:layout_constraintStart_toStartOf="parent"> 110 app:layout_constraintStart_toStartOf="parent">
110 111
...@@ -119,6 +120,56 @@ ...@@ -119,6 +120,56 @@
119 android:textSize="16sp" /> 120 android:textSize="16sp" />
120 </LinearLayout> 121 </LinearLayout>
121 122
123 + <RelativeLayout
124 + android:id="@+id/rl_terms"
125 + android:layout_width="wrap_content"
126 + android:layout_height="wrap_content"
127 + android:layout_marginTop="32dp"
128 + android:gravity="center"
129 + app:layout_constraintTop_toBottomOf="@+id/ll_activate_button"
130 + app:layout_constraintStart_toStartOf="parent"
131 + app:layout_constraintEnd_toEndOf="parent">
132 +
133 + <LinearLayout
134 + android:id="@+id/ll_terms_inner"
135 + android:layout_width="wrap_content"
136 + android:layout_height="wrap_content"
137 + android:layout_centerHorizontal="true"
138 + android:gravity="center"
139 + android:orientation="horizontal">
140 +
141 + <TextView
142 + android:id="@+id/tv_terms"
143 + fontPath="fonts/PeridotPE-Bold.ttf"
144 + android:layout_width="wrap_content"
145 + android:layout_height="wrap_content"
146 + android:text="@string/cos_coupon_terms_title"
147 + android:textColor="@color/cos_light_black"
148 + android:textSize="15sp" />
149 +
150 + <ImageView
151 + android:id="@+id/iv_terms_arrow"
152 + android:layout_width="14dp"
153 + android:layout_height="14dp"
154 + android:layout_marginTop="3dp"
155 + android:layout_marginStart="6dp"
156 + android:src="@drawable/ic_down_dark_new" />
157 + </LinearLayout>
158 +
159 + <TextView
160 + android:id="@+id/tv_terms_value"
161 + fontPath="fonts/PeridotPE-Regular.ttf"
162 + android:layout_width="wrap_content"
163 + android:layout_height="wrap_content"
164 + android:layout_below="@+id/ll_terms_inner"
165 + android:layout_marginHorizontal="32dp"
166 + android:layout_marginTop="16dp"
167 + android:textColor="@color/cos_light_black"
168 + android:textSize="14sp"
169 + android:visibility="gone"
170 + tools:text="@string/cos_coupon_date"
171 + tools:visibility="visible" />
172 + </RelativeLayout>
122 </androidx.constraintlayout.widget.ConstraintLayout> 173 </androidx.constraintlayout.widget.ConstraintLayout>
123 </androidx.constraintlayout.widget.ConstraintLayout> 174 </androidx.constraintlayout.widget.ConstraintLayout>
124 </ScrollView> 175 </ScrollView>
......