Showing
3 changed files
with
178 additions
and
157 deletions
| ... | @@ -1586,8 +1586,8 @@ public enum Warply { | ... | @@ -1586,8 +1586,8 @@ public enum Warply { |
| 1586 | } | 1586 | } |
| 1587 | } | 1587 | } |
| 1588 | 1588 | ||
| 1589 | - if (INSTANCE.mRequestQueue == null) | 1589 | + if (INSTANCE.mRequestQueue == null && INSTANCE.mContext != null) |
| 1590 | - INSTANCE.mRequestQueue = Volley.newRequestQueue(mContext); | 1590 | + INSTANCE.mRequestQueue = Volley.newRequestQueue(INSTANCE.mContext); |
| 1591 | 1591 | ||
| 1592 | if (tempAnalytics != null && tempAnalytics.length() > 0) { | 1592 | if (tempAnalytics != null && tempAnalytics.length() > 0) { |
| 1593 | String urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/"; | 1593 | String urlAnalytics = WarplyProperty.getBaseUrl(mContext) + WarpConstants.WARPLY_ASYNC + WarpConstants.WARPLY_ANALYTICS + WarplyProperty.getAppUuid(mContext) + "/"; | ... | ... |
| ... | @@ -247,7 +247,7 @@ public class WarplyManagerHelper { | ... | @@ -247,7 +247,7 @@ public class WarplyManagerHelper { |
| 247 | /** | 247 | /** |
| 248 | * Handle sharing flow | 248 | * Handle sharing flow |
| 249 | */ | 249 | */ |
| 250 | - public static void handleSharing(Context context, String sharingId) { | 250 | + public static void handleSharing(Activity context, String sharingId) { |
| 251 | WarpUtils.log("SHARING_ID: " + sharingId); | 251 | WarpUtils.log("SHARING_ID: " + sharingId); |
| 252 | WarplyManager.cosmoteSharing(new CosmoteSharingRequest().setSharingId(sharingId), new CallbackReceiver<JSONObject>() { | 252 | WarplyManager.cosmoteSharing(new CosmoteSharingRequest().setSharingId(sharingId), new CallbackReceiver<JSONObject>() { |
| 253 | @Override | 253 | @Override |
| ... | @@ -292,205 +292,223 @@ public class WarplyManagerHelper { | ... | @@ -292,205 +292,223 @@ public class WarplyManagerHelper { |
| 292 | /** | 292 | /** |
| 293 | * First dialog when we handle the deeplink | 293 | * First dialog when we handle the deeplink |
| 294 | */ | 294 | */ |
| 295 | - private static void initialSharingDialog(Context context, String alertTitle, String sharingId, boolean isSupermarket) { | 295 | + private static void initialSharingDialog(Activity context, String alertTitle, String sharingId, boolean isSupermarket) { |
| 296 | - mAlertDialogSharing = new AlertDialog.Builder(context) | 296 | + if (!context.isFinishing()) { |
| 297 | - .setTitle(R.string.cos_dlg_success_title) | 297 | + mAlertDialogSharing = new AlertDialog.Builder(context) |
| 298 | - .setMessage(alertTitle) | 298 | + .setTitle(R.string.cos_dlg_success_title) |
| 299 | - .setNegativeButton(R.string.cos_dlg_negative_button, (dialogPositive, whichPositive) -> { | 299 | + .setMessage(alertTitle) |
| 300 | - rejectSharingDialog(context, sharingId); | 300 | + .setNegativeButton(R.string.cos_dlg_negative_button, (dialogPositive, whichPositive) -> { |
| 301 | - }) | 301 | + rejectSharingDialog(context, sharingId); |
| 302 | - .setPositiveButton(R.string.cos_dlg_positive_button, (dialogNegative, whichNegative) -> { | 302 | + }) |
| 303 | - WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() | 303 | + .setPositiveButton(R.string.cos_dlg_positive_button, (dialogNegative, whichNegative) -> { |
| 304 | - .setSharingId(sharingId) | 304 | + WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() |
| 305 | - .setAccept(true), | 305 | + .setSharingId(sharingId) |
| 306 | - new CallbackReceiver<JSONObject>() { | 306 | + .setAccept(true), |
| 307 | - @Override | 307 | + new CallbackReceiver<JSONObject>() { |
| 308 | - public void onSuccess(JSONObject result) { | 308 | + @Override |
| 309 | - int status = result.optInt("status", 2); | 309 | + public void onSuccess(JSONObject result) { |
| 310 | - if (status == 1) { | 310 | + int status = result.optInt("status", 2); |
| 311 | - WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() { | 311 | + if (status == 1) { |
| 312 | - @Override | 312 | + WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() { |
| 313 | - public void onSuccess(CouponList result) { | 313 | + @Override |
| 314 | - WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); | 314 | + public void onSuccess(CouponList result) { |
| 315 | - couponsChanged.setChanged(true); | 315 | + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); |
| 316 | - EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); | 316 | + couponsChanged.setChanged(true); |
| 317 | - } | 317 | + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); |
| 318 | - | 318 | + } |
| 319 | - @Override | 319 | + |
| 320 | - public void onFailure(int errorCode) { | 320 | + @Override |
| 321 | - | 321 | + public void onFailure(int errorCode) { |
| 322 | - } | 322 | + |
| 323 | - }); | 323 | + } |
| 324 | - acceptSharingDialog(context, isSupermarket); | 324 | + }); |
| 325 | - } else | 325 | + acceptSharingDialog(context, isSupermarket); |
| 326 | - errorSharingDialog(context); | 326 | + } else |
| 327 | - } | 327 | + errorSharingDialog(context); |
| 328 | + } | ||
| 328 | 329 | ||
| 329 | - @Override | 330 | + @Override |
| 330 | - public void onFailure(int errorCode) { | 331 | + public void onFailure(int errorCode) { |
| 331 | - errorSharingDialog(context); | 332 | + errorSharingDialog(context); |
| 332 | - } | 333 | + } |
| 333 | - }); | 334 | + }); |
| 334 | - }) | 335 | + }) |
| 335 | - .show(); | 336 | + .show(); |
| 337 | + } | ||
| 336 | } | 338 | } |
| 337 | 339 | ||
| 338 | /** | 340 | /** |
| 339 | * Dialog when we success get the sharing gift | 341 | * Dialog when we success get the sharing gift |
| 340 | */ | 342 | */ |
| 341 | - private static void acceptSharingDialog(Context context, boolean isSupermarket) { | 343 | + private static void acceptSharingDialog(Activity context, boolean isSupermarket) { |
| 342 | - mAlertDialogAcceptSharing = new AlertDialog.Builder(context) | 344 | + if (!context.isFinishing()) { |
| 343 | - .setTitle(R.string.cos_dlg_success_title) | 345 | + mAlertDialogAcceptSharing = new AlertDialog.Builder(context) |
| 344 | - .setMessage(isSupermarket ? R.string.cos_dlg_positive_button_text2 : R.string.cos_dlg_positive_button_text) | 346 | + .setTitle(R.string.cos_dlg_success_title) |
| 345 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 347 | + .setMessage(isSupermarket ? R.string.cos_dlg_positive_button_text2 : R.string.cos_dlg_positive_button_text) |
| 346 | - dialogPositive.dismiss(); | 348 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 347 | - }) | 349 | + dialogPositive.dismiss(); |
| 348 | - .show(); | 350 | + }) |
| 351 | + .show(); | ||
| 352 | + } | ||
| 349 | } | 353 | } |
| 350 | 354 | ||
| 351 | /** | 355 | /** |
| 352 | * Dialog when we reject the sharing gift | 356 | * Dialog when we reject the sharing gift |
| 353 | */ | 357 | */ |
| 354 | - private static void rejectSharingDialog(Context context, String sharingId) { | 358 | + private static void rejectSharingDialog(Activity context, String sharingId) { |
| 355 | - mAlertDialogRejectSharing = new AlertDialog.Builder(context) | 359 | + if (!context.isFinishing()) { |
| 356 | - .setTitle(R.string.cos_dlg_reject_title) | 360 | + mAlertDialogRejectSharing = new AlertDialog.Builder(context) |
| 357 | - .setMessage(R.string.cos_dlg_reject_text) | 361 | + .setTitle(R.string.cos_dlg_reject_title) |
| 358 | - .setPositiveButton(R.string.cos_dlg_negative_button, (dialogPositive, whichPositive) -> { | 362 | + .setMessage(R.string.cos_dlg_reject_text) |
| 359 | - WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() | 363 | + .setPositiveButton(R.string.cos_dlg_negative_button, (dialogPositive, whichPositive) -> { |
| 360 | - .setSharingId(sharingId) | 364 | + WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() |
| 361 | - .setAccept(false), | 365 | + .setSharingId(sharingId) |
| 362 | - new CallbackReceiver<JSONObject>() { | 366 | + .setAccept(false), |
| 363 | - @Override | 367 | + new CallbackReceiver<JSONObject>() { |
| 364 | - public void onSuccess(JSONObject result) { | 368 | + @Override |
| 365 | - int status = result.optInt("status", 2); | 369 | + public void onSuccess(JSONObject result) { |
| 366 | - if (status == 1) | 370 | + int status = result.optInt("status", 2); |
| 367 | - returnSharingSuccessDialog(context); | 371 | + if (status == 1) |
| 368 | - else | 372 | + returnSharingSuccessDialog(context); |
| 369 | - errorSharingDialog(context); | 373 | + else |
| 370 | - } | 374 | + errorSharingDialog(context); |
| 375 | + } | ||
| 371 | 376 | ||
| 372 | - @Override | 377 | + @Override |
| 373 | - public void onFailure(int errorCode) { | 378 | + public void onFailure(int errorCode) { |
| 374 | - errorSharingDialog(context); | 379 | + errorSharingDialog(context); |
| 375 | - } | 380 | + } |
| 376 | - }); | 381 | + }); |
| 377 | - }) | 382 | + }) |
| 378 | - .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { | 383 | + .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogNegative, whichNegative) -> { |
| 379 | - dialogNegative.dismiss(); | 384 | + dialogNegative.dismiss(); |
| 380 | - }) | 385 | + }) |
| 381 | - .show(); | 386 | + .show(); |
| 387 | + } | ||
| 382 | } | 388 | } |
| 383 | 389 | ||
| 384 | /** | 390 | /** |
| 385 | * Dialog when the gift gets returned | 391 | * Dialog when the gift gets returned |
| 386 | */ | 392 | */ |
| 387 | - private static void returnSharingDialog(Context context, String alertTitle) { | 393 | + private static void returnSharingDialog(Activity context, String alertTitle) { |
| 388 | - mAlertDialogReturnSharing = new AlertDialog.Builder(context) | 394 | + if (!context.isFinishing()) { |
| 389 | - .setTitle(R.string.cod_dlg_return_title) | 395 | + mAlertDialogReturnSharing = new AlertDialog.Builder(context) |
| 390 | - .setMessage(alertTitle) | 396 | + .setTitle(R.string.cod_dlg_return_title) |
| 391 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 397 | + .setMessage(alertTitle) |
| 392 | - dialogPositive.dismiss(); | 398 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 393 | - }) | 399 | + dialogPositive.dismiss(); |
| 394 | - .show(); | 400 | + }) |
| 401 | + .show(); | ||
| 402 | + } | ||
| 395 | } | 403 | } |
| 396 | 404 | ||
| 397 | /** | 405 | /** |
| 398 | * Dialog when the gift gets successfully returned | 406 | * Dialog when the gift gets successfully returned |
| 399 | */ | 407 | */ |
| 400 | - private static void returnSharingSuccessDialog(Context context) { | 408 | + private static void returnSharingSuccessDialog(Activity context) { |
| 401 | - mAlertDialogReturnSharing = new AlertDialog.Builder(context) | 409 | + if (!context.isFinishing()) { |
| 402 | - .setTitle(R.string.cod_dlg_reject_title) | 410 | + mAlertDialogReturnSharing = new AlertDialog.Builder(context) |
| 403 | - .setMessage(R.string.cod_dlg_reject_subtitle) | 411 | + .setTitle(R.string.cod_dlg_reject_title) |
| 404 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 412 | + .setMessage(R.string.cod_dlg_reject_subtitle) |
| 405 | - dialogPositive.dismiss(); | 413 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 406 | - }) | 414 | + dialogPositive.dismiss(); |
| 407 | - .show(); | 415 | + }) |
| 416 | + .show(); | ||
| 417 | + } | ||
| 408 | } | 418 | } |
| 409 | 419 | ||
| 410 | /** | 420 | /** |
| 411 | * Error dialog | 421 | * Error dialog |
| 412 | */ | 422 | */ |
| 413 | - private static void errorSharingDialog(Context context) { | 423 | + private static void errorSharingDialog(Activity context) { |
| 414 | - mAlertDialogErrorSharing = new AlertDialog.Builder(context) | 424 | + if (!context.isFinishing()) { |
| 415 | - .setTitle(R.string.cos_dlg_error_title) | 425 | + mAlertDialogErrorSharing = new AlertDialog.Builder(context) |
| 416 | - .setMessage(R.string.cos_dlg_error_subtitle) | 426 | + .setTitle(R.string.cos_dlg_error_title) |
| 417 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 427 | + .setMessage(R.string.cos_dlg_error_subtitle) |
| 418 | - dialogPositive.dismiss(); | 428 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 419 | - }) | 429 | + dialogPositive.dismiss(); |
| 420 | - .show(); | 430 | + }) |
| 431 | + .show(); | ||
| 432 | + } | ||
| 421 | } | 433 | } |
| 422 | 434 | ||
| 423 | /** | 435 | /** |
| 424 | * Return dialog | 436 | * Return dialog |
| 425 | */ | 437 | */ |
| 426 | - private static void returnDialog(Context context, String message, String sharingId) { | 438 | + private static void returnDialog(Activity context, String message, String sharingId) { |
| 427 | - mAlertDialogErrorSharing = new AlertDialog.Builder(context) | 439 | + if (!context.isFinishing()) { |
| 428 | - .setTitle(R.string.cos_dlg_return_title) | 440 | + mAlertDialogErrorSharing = new AlertDialog.Builder(context) |
| 429 | - .setMessage(message) | 441 | + .setTitle(R.string.cos_dlg_return_title) |
| 430 | - .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogPositive, whichPositive) -> { | 442 | + .setMessage(message) |
| 443 | + .setNegativeButton(R.string.cos_dlg_negative_button2, (dialogPositive, whichPositive) -> { | ||
| 431 | // rejectSharingDialog(context, sharingId); | 444 | // rejectSharingDialog(context, sharingId); |
| 432 | - dialogPositive.dismiss(); | 445 | + dialogPositive.dismiss(); |
| 433 | - }) | 446 | + }) |
| 434 | - .setPositiveButton(R.string.cos_dlg_positive_button, (dialogNegative, whichNegative) -> { | 447 | + .setPositiveButton(R.string.cos_dlg_positive_button, (dialogNegative, whichNegative) -> { |
| 435 | - WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() | 448 | + WarplyManager.cosmoteRetrieveSharing(new CosmoteRetrieveSharingRequest() |
| 436 | - .setSharingId(sharingId) | 449 | + .setSharingId(sharingId) |
| 437 | - .setAccept(true), | 450 | + .setAccept(true), |
| 438 | - new CallbackReceiver<JSONObject>() { | 451 | + new CallbackReceiver<JSONObject>() { |
| 439 | - @Override | 452 | + @Override |
| 440 | - public void onSuccess(JSONObject result) { | 453 | + public void onSuccess(JSONObject result) { |
| 441 | - int status = result.optInt("status", 2); | 454 | + int status = result.optInt("status", 2); |
| 442 | - if (status == 1) { | 455 | + if (status == 1) { |
| 443 | - WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() { | 456 | + WarplyManager.getUserCouponsWithCouponsets(new CallbackReceiver<CouponList>() { |
| 444 | - @Override | 457 | + @Override |
| 445 | - public void onSuccess(CouponList result) { | 458 | + public void onSuccess(CouponList result) { |
| 446 | - WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); | 459 | + WarplyCouponsChangedEventModel couponsChanged = new WarplyCouponsChangedEventModel(); |
| 447 | - couponsChanged.setChanged(true); | 460 | + couponsChanged.setChanged(true); |
| 448 | - EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); | 461 | + EventBus.getDefault().post(new WarplyEventBusManager(couponsChanged)); |
| 449 | - } | 462 | + } |
| 450 | - | 463 | + |
| 451 | - @Override | 464 | + @Override |
| 452 | - public void onFailure(int errorCode) { | 465 | + public void onFailure(int errorCode) { |
| 453 | - | 466 | + |
| 454 | - } | 467 | + } |
| 455 | - }); | 468 | + }); |
| 456 | // acceptSharingDialog(context); | 469 | // acceptSharingDialog(context); |
| 457 | - } else | 470 | + } else |
| 458 | - errorSharingDialog(context); | 471 | + errorSharingDialog(context); |
| 459 | - } | 472 | + } |
| 460 | 473 | ||
| 461 | - @Override | 474 | + @Override |
| 462 | - public void onFailure(int errorCode) { | 475 | + public void onFailure(int errorCode) { |
| 463 | - errorSharingDialog(context); | 476 | + errorSharingDialog(context); |
| 464 | - } | 477 | + } |
| 465 | - }); | 478 | + }); |
| 466 | - }) | 479 | + }) |
| 467 | - .show(); | 480 | + .show(); |
| 481 | + } | ||
| 468 | } | 482 | } |
| 469 | 483 | ||
| 470 | /** | 484 | /** |
| 471 | * Expired dialog | 485 | * Expired dialog |
| 472 | */ | 486 | */ |
| 473 | - private static void errorExpiredDialog(Context context, String message) { | 487 | + private static void errorExpiredDialog(Activity context, String message) { |
| 474 | - mAlertDialogErrorExpiredSharing = new AlertDialog.Builder(context) | 488 | + if (!context.isFinishing()) { |
| 475 | - .setTitle(R.string.cos_dlg_error_title) | 489 | + mAlertDialogErrorExpiredSharing = new AlertDialog.Builder(context) |
| 476 | - .setMessage(message) | 490 | + .setTitle(R.string.cos_dlg_error_title) |
| 477 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 491 | + .setMessage(message) |
| 478 | - dialogPositive.dismiss(); | 492 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 479 | - }) | 493 | + dialogPositive.dismiss(); |
| 480 | - .show(); | 494 | + }) |
| 495 | + .show(); | ||
| 496 | + } | ||
| 481 | } | 497 | } |
| 482 | 498 | ||
| 483 | /** | 499 | /** |
| 484 | * Used dialog | 500 | * Used dialog |
| 485 | */ | 501 | */ |
| 486 | - private static void errorUsedDialog(Context context, String message) { | 502 | + private static void errorUsedDialog(Activity context, String message) { |
| 487 | - mAlertDialogErrorUsedSharing = new AlertDialog.Builder(context) | 503 | + if (!context.isFinishing()) { |
| 488 | - .setTitle(R.string.cos_dlg_error_title) | 504 | + mAlertDialogErrorUsedSharing = new AlertDialog.Builder(context) |
| 489 | - .setMessage(message) | 505 | + .setTitle(R.string.cos_dlg_error_title) |
| 490 | - .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { | 506 | + .setMessage(message) |
| 491 | - dialogPositive.dismiss(); | 507 | + .setPositiveButton(R.string.cos_dlg_positive_button2, (dialogPositive, whichPositive) -> { |
| 492 | - }) | 508 | + dialogPositive.dismiss(); |
| 493 | - .show(); | 509 | + }) |
| 510 | + .show(); | ||
| 511 | + } | ||
| 494 | } | 512 | } |
| 495 | 513 | ||
| 496 | /** | 514 | /** | ... | ... |
| ... | @@ -659,6 +659,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { | ... | @@ -659,6 +659,7 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { |
| 659 | private void checkForPermissions(String origin, Callback callback) { | 659 | private void checkForPermissions(String origin, Callback callback) { |
| 660 | String perm = Manifest.permission.ACCESS_FINE_LOCATION; | 660 | String perm = Manifest.permission.ACCESS_FINE_LOCATION; |
| 661 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || getContext().checkSelfPermission(perm) == PackageManager.PERMISSION_GRANTED) { | 661 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || getContext().checkSelfPermission(perm) == PackageManager.PERMISSION_GRANTED) { |
| 662 | + geolocationCallback = callback; | ||
| 662 | if (isGPSEnabled()) { | 663 | if (isGPSEnabled()) { |
| 663 | callback.invoke(origin, true, false); | 664 | callback.invoke(origin, true, false); |
| 664 | } else { | 665 | } else { |
| ... | @@ -678,6 +679,8 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { | ... | @@ -678,6 +679,8 @@ public class WarpView extends WebView implements DefaultLifecycleObserver { |
| 678 | } | 679 | } |
| 679 | 680 | ||
| 680 | private void enableLocationSettings() { | 681 | private void enableLocationSettings() { |
| 682 | + if (geolocationCallback == null) return; | ||
| 683 | + | ||
| 681 | GoogleApiClient googleApiClient = new GoogleApiClient.Builder(WarpActivity) | 684 | GoogleApiClient googleApiClient = new GoogleApiClient.Builder(WarpActivity) |
| 682 | .addApi(LocationServices.API) | 685 | .addApi(LocationServices.API) |
| 683 | .build(); | 686 | .build(); | ... | ... |
-
Please register or login to post a comment