Showing
11 changed files
with
149 additions
and
10 deletions
| ... | @@ -133,6 +133,11 @@ | ... | @@ -133,6 +133,11 @@ | 
| 133 | android:permission="android.permission.BIND_JOB_SERVICE" /> | 133 | android:permission="android.permission.BIND_JOB_SERVICE" /> | 
| 134 | 134 | ||
| 135 | <service | 135 | <service | 
| 136 | + android:name="ly.warp.sdk.services.EventCampaignCouponService" | ||
| 137 | + android:exported="false" | ||
| 138 | + android:permission="android.permission.BIND_JOB_SERVICE" /> | ||
| 139 | + | ||
| 140 | + <service | ||
| 136 | android:name="ly.warp.sdk.services.EventCampaignService" | 141 | android:name="ly.warp.sdk.services.EventCampaignService" | 
| 137 | android:exported="false" | 142 | android:exported="false" | 
| 138 | android:permission="android.permission.BIND_JOB_SERVICE" /> | 143 | android:permission="android.permission.BIND_JOB_SERVICE" /> | ... | ... | 
This diff is collapsed. Click to expand it.
| ... | @@ -102,6 +102,22 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | ... | @@ -102,6 +102,22 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | 
| 102 | super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase)); | 102 | super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase)); | 
| 103 | } | 103 | } | 
| 104 | 104 | ||
| 105 | +// @Override | ||
| 106 | +// public void onRequestPermissionsResult( | ||
| 107 | +// int requestCode, | ||
| 108 | +// String permissions[], | ||
| 109 | +// int[] grantResults) { | ||
| 110 | +// switch (requestCode) { | ||
| 111 | +// case REQUEST_PERMISSION_PHONE_STATE: | ||
| 112 | +// if (grantResults.length > 0 | ||
| 113 | +// && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||
| 114 | +// Toast.makeText(MainActivity.this, "Permission Granted!", Toast.LENGTH_SHORT).show(); | ||
| 115 | +// } else { | ||
| 116 | +// Toast.makeText(MainActivity.this, "Permission Denied!", Toast.LENGTH_SHORT).show(); | ||
| 117 | +// } | ||
| 118 | +// } | ||
| 119 | +// } | ||
| 120 | + | ||
| 105 | @Override | 121 | @Override | 
| 106 | public void onMapReady(@NonNull GoogleMap googleMap) { | 122 | public void onMapReady(@NonNull GoogleMap googleMap) { | 
| 107 | mMap = googleMap; | 123 | mMap = googleMap; | 
| ... | @@ -115,6 +131,9 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | ... | @@ -115,6 +131,9 @@ public class ShopsActivity extends FragmentActivity implements View.OnClickListe | 
| 115 | } | 131 | } | 
| 116 | } else { | 132 | } else { | 
| 117 | mMap.setMyLocationEnabled(false); | 133 | mMap.setMyLocationEnabled(false); | 
| 134 | +// ActivityCompat.requestPermissions(this, | ||
| 135 | +// new String[]{Manifest.permission.ACCESS_FINE_LOCATION, | ||
| 136 | +// Manifest.permission.ACCESS_COARSE_LOCATION}, 501); | ||
| 118 | } | 137 | } | 
| 119 | 138 | ||
| 120 | mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); | 139 | mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); | ... | ... | 
| ... | @@ -64,6 +64,7 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver; | ... | @@ -64,6 +64,7 @@ import ly.warp.sdk.io.callbacks.CallbackReceiver; | 
| 64 | import ly.warp.sdk.io.models.CouponList; | 64 | import ly.warp.sdk.io.models.CouponList; | 
| 65 | import ly.warp.sdk.io.request.PacingCalculateRequest; | 65 | import ly.warp.sdk.io.request.PacingCalculateRequest; | 
| 66 | import ly.warp.sdk.io.request.WarplyUserCouponsRequest; | 66 | import ly.warp.sdk.io.request.WarplyUserCouponsRequest; | 
| 67 | +import ly.warp.sdk.services.EventCampaignCouponService; | ||
| 67 | import ly.warp.sdk.services.EventQuestionnaireService; | 68 | import ly.warp.sdk.services.EventQuestionnaireService; | 
| 68 | import ly.warp.sdk.services.PushEventsClickedWorkerService; | 69 | import ly.warp.sdk.services.PushEventsClickedWorkerService; | 
| 69 | import ly.warp.sdk.services.WarplyHealthService; | 70 | import ly.warp.sdk.services.WarplyHealthService; | 
| ... | @@ -151,9 +152,10 @@ public class WarpViewActivity extends WarpBaseActivity { | ... | @@ -151,9 +152,10 @@ public class WarpViewActivity extends WarpBaseActivity { | 
| 151 | setResult(RESULT_OK, new Intent()); | 152 | setResult(RESULT_OK, new Intent()); | 
| 152 | finish(); | 153 | finish(); | 
| 153 | } | 154 | } | 
| 154 | -// if (event.getCoupon() != null) { | 155 | + if (event.getCoupon() != null) { | 
| 155 | -// WarplyManager.getUserCouponsWithCouponsets(new WarplyUserCouponsRequest(), mUserCouponsReceiver); | 156 | + OneTimeWorkRequest mywork = new OneTimeWorkRequest.Builder(EventCampaignCouponService.class).build(); | 
| 156 | -// } | 157 | + WorkManager.getInstance(WarpViewActivity.this).enqueue(mywork); | 
| 158 | + } | ||
| 157 | // if (event.getPacingCard() != null) | 159 | // if (event.getPacingCard() != null) | 
| 158 | // finish(); | 160 | // finish(); | 
| 159 | // if (event.getPacingService() != null) | 161 | // if (event.getPacingService() != null) | ... | ... | 
| ... | @@ -198,14 +198,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { | ... | @@ -198,14 +198,14 @@ public class Merchant implements Parcelable, Serializable, ClusterItem { | 
| 198 | */ | 198 | */ | 
| 199 | public Merchant(JSONObject json) { | 199 | public Merchant(JSONObject json) { | 
| 200 | if (json != null) { | 200 | if (json != null) { | 
| 201 | - this.address = json.optString(ADDRESS); | 201 | + this.address = json.isNull(ADDRESS) ? "" : json.optString(ADDRESS); | 
| 202 | this.id = json.optString(ID); | 202 | this.id = json.optString(ID); | 
| 203 | this.store_id = json.optString(STORE_ID); | 203 | this.store_id = json.optString(STORE_ID); | 
| 204 | - this.name = json.optString(NAME); | 204 | + this.name = json.isNull(NAME) ? "" : json.optString(NAME); | 
| 205 | this.logo = json.optString(LOGO); | 205 | this.logo = json.optString(LOGO); | 
| 206 | this.website = json.optString(WEBSITE); | 206 | this.website = json.optString(WEBSITE); | 
| 207 | this.email = json.optString(EMAIL); | 207 | this.email = json.optString(EMAIL); | 
| 208 | - this.telephone = json.optString(TELEPHONE); | 208 | + this.telephone = json.isNull(TELEPHONE) ? "" : json.optString(TELEPHONE); | 
| 209 | this.category = json.optString(CATEGORY); | 209 | this.category = json.optString(CATEGORY); | 
| 210 | this.description = json.optString(DESCRIPTION); | 210 | this.description = json.optString(DESCRIPTION); | 
| 211 | this.short_description = json.optString(SHORT_DESCRIPTION); | 211 | this.short_description = json.optString(SHORT_DESCRIPTION); | ... | ... | 
| 1 | +package ly.warp.sdk.services; | ||
| 2 | + | ||
| 3 | +import android.content.Context; | ||
| 4 | + | ||
| 5 | +import androidx.annotation.NonNull; | ||
| 6 | +import androidx.work.OneTimeWorkRequest; | ||
| 7 | +import androidx.work.WorkManager; | ||
| 8 | +import androidx.work.Worker; | ||
| 9 | +import androidx.work.WorkerParameters; | ||
| 10 | + | ||
| 11 | +import org.greenrobot.eventbus.EventBus; | ||
| 12 | + | ||
| 13 | +import ly.warp.sdk.Warply; | ||
| 14 | +import ly.warp.sdk.activities.CouponsetInfoActivity; | ||
| 15 | +import ly.warp.sdk.io.callbacks.CallbackReceiver; | ||
| 16 | +import ly.warp.sdk.io.models.CampaignList; | ||
| 17 | +import ly.warp.sdk.io.models.CouponList; | ||
| 18 | +import ly.warp.sdk.io.models.CouponsEventModel; | ||
| 19 | +import ly.warp.sdk.io.models.LoyaltyEventModel; | ||
| 20 | +import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel; | ||
| 21 | +import ly.warp.sdk.io.request.WarplyGetCampaignsRequest; | ||
| 22 | +import ly.warp.sdk.io.request.WarplyUserCouponsRequest; | ||
| 23 | +import ly.warp.sdk.utils.managers.WarplyEventBusManager; | ||
| 24 | +import ly.warp.sdk.utils.managers.WarplyManager; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Created by Panagiotis Triantafyllou on 05/Sept/2022. | ||
| 28 | + */ | ||
| 29 | +public class EventCampaignCouponService extends Worker { | ||
| 30 | + | ||
| 31 | + public EventCampaignCouponService(@NonNull Context context, @NonNull WorkerParameters workerParams) { | ||
| 32 | + super(context, workerParams); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @NonNull | ||
| 36 | + @Override | ||
| 37 | + public Result doWork() { | ||
| 38 | + WarplyManager.getUserCouponsWithCouponsets(new WarplyUserCouponsRequest(), mUserCouponsReceiver); | ||
| 39 | + WarplyManager.getCampaigns(new WarplyGetCampaignsRequest().setLanguage("en"), mCampaignsCallback); | ||
| 40 | + | ||
| 41 | + return Result.success(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + private final CallbackReceiver<CouponList> mUserCouponsReceiver = new CallbackReceiver<CouponList>() { | ||
| 45 | + @Override | ||
| 46 | + public void onSuccess(CouponList result) { | ||
| 47 | + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); | ||
| 48 | + couponsChanged.setChanged(true); | ||
| 49 | + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public void onFailure(int errorCode) { | ||
| 54 | + Thread.currentThread().interrupt(); | ||
| 55 | + } | ||
| 56 | + }; | ||
| 57 | + | ||
| 58 | + private CallbackReceiver<CampaignList> mCampaignsCallback = new CallbackReceiver<CampaignList>() { | ||
| 59 | + @Override | ||
| 60 | + public void onSuccess(CampaignList result) { | ||
| 61 | + LoyaltyEventModel campaignsAdded = new LoyaltyEventModel(); | ||
| 62 | + EventBus.getDefault().post(new WarplyEventBusManager(campaignsAdded)); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + @Override | ||
| 66 | + public void onFailure(int errorCode) { | ||
| 67 | + Thread.currentThread().interrupt(); | ||
| 68 | + } | ||
| 69 | + }; | ||
| 70 | +} | 
| ... | @@ -346,7 +346,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | ... | @@ -346,7 +346,7 @@ public class FCMBaseMessagingService extends FirebaseMessagingService { | 
| 346 | nm.notify(tag, uid, notification_build); | 346 | nm.notify(tag, uid, notification_build); | 
| 347 | }*/ | 347 | }*/ | 
| 348 | 348 | ||
| 349 | - public void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { | 349 | + public static void showNotification(Context context, PushCampaign pc, Intent newIntent, List<NotificationCompat.Action> actions, RemoteViews remoteViews, String tag, int id) { | 
| 350 | 350 | ||
| 351 | SecureRandom randomGenerator = new SecureRandom(); | 351 | SecureRandom randomGenerator = new SecureRandom(); | 
| 352 | int uid = randomGenerator.nextInt(1000); | 352 | int uid = randomGenerator.nextInt(1000); | ... | ... | 
| ... | @@ -27,6 +27,8 @@ package ly.warp.sdk.utils; | ... | @@ -27,6 +27,8 @@ package ly.warp.sdk.utils; | 
| 27 | 27 | ||
| 28 | import android.content.Context; | 28 | import android.content.Context; | 
| 29 | import android.content.Intent; | 29 | import android.content.Intent; | 
| 30 | +import android.content.pm.PackageManager; | ||
| 31 | +import android.os.Bundle; | ||
| 30 | import android.text.TextUtils; | 32 | import android.text.TextUtils; | 
| 31 | import android.util.Log; | 33 | import android.util.Log; | 
| 32 | 34 | ||
| ... | @@ -43,6 +45,7 @@ import java.io.Serializable; | ... | @@ -43,6 +45,7 @@ import java.io.Serializable; | 
| 43 | import java.util.ArrayList; | 45 | import java.util.ArrayList; | 
| 44 | import java.util.HashMap; | 46 | import java.util.HashMap; | 
| 45 | import java.util.HashSet; | 47 | import java.util.HashSet; | 
| 48 | +import java.util.Map; | ||
| 46 | 49 | ||
| 47 | import ly.warp.sdk.R; | 50 | import ly.warp.sdk.R; | 
| 48 | import ly.warp.sdk.Warply; | 51 | import ly.warp.sdk.Warply; | 
| ... | @@ -66,12 +69,14 @@ import ly.warp.sdk.io.models.LoyaltyBadgeModel; | ... | @@ -66,12 +69,14 @@ import ly.warp.sdk.io.models.LoyaltyBadgeModel; | 
| 66 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; | 69 | import ly.warp.sdk.io.models.LoyaltyContextualOfferModel; | 
| 67 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; | 70 | import ly.warp.sdk.io.models.LoyaltyGiftsForYouPackage; | 
| 68 | import ly.warp.sdk.io.models.MerchantList; | 71 | import ly.warp.sdk.io.models.MerchantList; | 
| 72 | +import ly.warp.sdk.io.models.PushCampaign; | ||
| 69 | import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel; | 73 | import ly.warp.sdk.io.models.WarplyCouponsChangedEventModel; | 
| 70 | import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; | 74 | import ly.warp.sdk.io.request.CosmoteRetrieveSharingRequest; | 
| 71 | import ly.warp.sdk.io.request.CosmoteSharingRequest; | 75 | import ly.warp.sdk.io.request.CosmoteSharingRequest; | 
| 72 | import ly.warp.sdk.io.request.WarplyIntegrationRequest; | 76 | import ly.warp.sdk.io.request.WarplyIntegrationRequest; | 
| 73 | import ly.warp.sdk.io.request.WarplyUserCouponsRequest; | 77 | import ly.warp.sdk.io.request.WarplyUserCouponsRequest; | 
| 74 | import ly.warp.sdk.services.EventService; | 78 | import ly.warp.sdk.services.EventService; | 
| 79 | +import ly.warp.sdk.services.FCMBaseMessagingService; | ||
| 75 | import ly.warp.sdk.utils.managers.WarplyEventBusManager; | 80 | import ly.warp.sdk.utils.managers.WarplyEventBusManager; | 
| 76 | import ly.warp.sdk.utils.managers.WarplyManager; | 81 | import ly.warp.sdk.utils.managers.WarplyManager; | 
| 77 | 82 | ||
| ... | @@ -1129,6 +1134,42 @@ public class WarplyManagerHelper { | ... | @@ -1129,6 +1134,42 @@ public class WarplyManagerHelper { | 
| 1129 | mDealsSum = sum; | 1134 | mDealsSum = sum; | 
| 1130 | } | 1135 | } | 
| 1131 | 1136 | ||
| 1137 | + public static boolean checkForLoyaltySDKNotification(Map<String, String> pushPayload) { | ||
| 1138 | + Bundle data = convertToBundle(pushPayload); | ||
| 1139 | + if (data == null || !data.containsKey("loyalty-action")) | ||
| 1140 | + return false; | ||
| 1141 | + PushCampaign pc = new PushCampaign(data); | ||
| 1142 | + | ||
| 1143 | + WarpUtils.log("Received push with action: " + pc.getAction()); | ||
| 1144 | + if (pc.getAction() == 0 && !pc.hasActions()) | ||
| 1145 | + FCMBaseMessagingService.showCampaignNotification(Warply.getWarplyContext(), pc); | ||
| 1146 | + else | ||
| 1147 | + showDefaultNotification(Warply.getWarplyContext(), data); | ||
| 1148 | + | ||
| 1149 | + return true; | ||
| 1150 | + } | ||
| 1151 | + | ||
| 1152 | + private static Bundle convertToBundle(Map<String, String> data) { | ||
| 1153 | + Bundle bundle = new Bundle(); | ||
| 1154 | + for (Map.Entry<String, String> entry : data.entrySet()) { | ||
| 1155 | + bundle.putString(entry.getKey(), entry.getValue()); | ||
| 1156 | + } | ||
| 1157 | + | ||
| 1158 | + return bundle; | ||
| 1159 | + } | ||
| 1160 | + | ||
| 1161 | + private static void showDefaultNotification(Context context, Bundle data) { | ||
| 1162 | + PushCampaign pc = new PushCampaign(data); | ||
| 1163 | + | ||
| 1164 | + if (pc != null) { | ||
| 1165 | + PackageManager pm = context.getPackageManager(); | ||
| 1166 | + Intent newIntent = pm.getLaunchIntentForPackage(context.getPackageName()); | ||
| 1167 | + | ||
| 1168 | + FCMBaseMessagingService.showNotification(context, pc, newIntent, null, null, null, 0); | ||
| 1169 | + } | ||
| 1170 | + | ||
| 1171 | + } | ||
| 1172 | + | ||
| 1132 | // =========================================================== | 1173 | // =========================================================== | 
| 1133 | // Inner and Anonymous Classes | 1174 | // Inner and Anonymous Classes | 
| 1134 | // =========================================================== | 1175 | // =========================================================== | ... | ... | 
| ... | @@ -418,7 +418,7 @@ public class WarpView extends WebView { | ... | @@ -418,7 +418,7 @@ public class WarpView extends WebView { | 
| 418 | EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent)); | 418 | EventBus.getDefault().post(new WarplyEventBusManager(questionnaireEvent)); | 
| 419 | } | 419 | } | 
| 420 | } else if (parts[1].equals("couponRetrieved")) { | 420 | } else if (parts[1].equals("couponRetrieved")) { | 
| 421 | -// EventBus.getDefault().post(new WarplyEventBusManager(new CouponEventModel())); | 421 | + EventBus.getDefault().post(new WarplyEventBusManager(new CouponEventModel())); | 
| 422 | } else if (parts[1].equals("couponShared")) { | 422 | } else if (parts[1].equals("couponShared")) { | 
| 423 | // EventBus.getDefault().post(new WarplyEventBusManager(new CouponEventModel())); | 423 | // EventBus.getDefault().post(new WarplyEventBusManager(new CouponEventModel())); | 
| 424 | } else if (parts[1].equals("steps") && parts[2].equals("widgetDisabled")) { // This is for the pacing widget | 424 | } else if (parts[1].equals("steps") && parts[2].equals("widgetDisabled")) { // This is for the pacing widget | ... | ... | 
| ... | @@ -52,7 +52,8 @@ | ... | @@ -52,7 +52,8 @@ | 
| 52 | android:layout_marginTop="4dp" | 52 | android:layout_marginTop="4dp" | 
| 53 | android:clipToPadding="false" | 53 | android:clipToPadding="false" | 
| 54 | android:orientation="vertical" | 54 | android:orientation="vertical" | 
| 55 | - android:paddingTop="44dp" /> | 55 | + android:paddingTop="44dp" | 
| 56 | + android:overScrollMode="never"/> | ||
| 56 | </RelativeLayout> | 57 | </RelativeLayout> | 
| 57 | 58 | ||
| 58 | <TextView | 59 | <TextView | ... | ... | 
| ... | @@ -115,7 +115,8 @@ | ... | @@ -115,7 +115,8 @@ | 
| 115 | android:layout_width="match_parent" | 115 | android:layout_width="match_parent" | 
| 116 | android:layout_height="match_parent" | 116 | android:layout_height="match_parent" | 
| 117 | android:layout_marginTop="-24dp" | 117 | android:layout_marginTop="-24dp" | 
| 118 | - android:fillViewport="true"> | 118 | + android:fillViewport="true" | 
| 119 | + android:overScrollMode="never"> | ||
| 119 | 120 | ||
| 120 | <RelativeLayout | 121 | <RelativeLayout | 
| 121 | android:layout_width="match_parent" | 122 | android:layout_width="match_parent" | ... | ... | 
- 
Please register or login to post a comment