Skip to content

Commit 94d2456

Browse files
committed
Merge branch 'develop' into feature/feat-channels-registration
# Conflicts: # AndroidSDK/src/com/leanplum/LeanplumPushService.java
2 parents 204a9d8 + 88a7ad3 commit 94d2456

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

AndroidSDK/src/com/leanplum/Leanplum.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,35 @@ public static void track(final String event, double value, String info,
15561556
LeanplumInternal.track(event, value, info, params, null);
15571557
}
15581558

1559+
/**
1560+
* Manually track purchase event with currency code in your application. It is advised to use
1561+
* {@link Leanplum#trackGooglePlayPurchase} instead for in-app purchases.
1562+
*
1563+
* @param event Name of the event.
1564+
* @param value The value of the event. Can be price.
1565+
* @param currencyCode The currency code corresponding to the price.
1566+
* @param params Key-value pairs with metrics or data associated with the event. Parameters can be
1567+
* strings or numbers. You can use up to 200 different parameter names in your app.
1568+
*/
1569+
public static void trackPurchase(final String event, double value, String currencyCode,
1570+
Map<String, ?> params) {
1571+
try {
1572+
if (TextUtils.isEmpty(event)) {
1573+
Log.w("trackPurchase - Empty event parameter provided.");
1574+
}
1575+
1576+
final Map<String, String> requestArgs = new HashMap<>();
1577+
if (!TextUtils.isEmpty(currencyCode)) {
1578+
requestArgs.put(Constants.Params.IAP_CURRENCY_CODE, currencyCode);
1579+
}
1580+
1581+
LeanplumInternal.track(event, value, null, params, requestArgs);
1582+
} catch (Throwable t) {
1583+
Log.e("trackPurchase - Failed to track purchase event.");
1584+
Util.handleException(t);
1585+
}
1586+
}
1587+
15591588
/**
15601589
* Tracks an in-app purchase as a Purchase event.
15611590
*

AndroidSDK/src/com/leanplum/LeanplumNotificationChannel.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040

4141
import org.json.JSONArray;
4242

43+
import java.util.ArrayList;
4344
import java.util.HashMap;
45+
import java.util.Iterator;
4446
import java.util.List;
4547
import java.util.Map;
4648

@@ -602,10 +604,17 @@ private static class NotificationChannelData {
602604
showBadge = (boolean) CollectionUtil.getOrDefault(channel, "show_badge", showBadge);
603605

604606
try {
605-
List<Long> pattern = CollectionUtil.uncheckedCast(
607+
List<Number> pattern = CollectionUtil.uncheckedCast(
606608
CollectionUtil.getOrDefault(channel, "vibration_pattern", null));
607609
if (pattern != null) {
608-
vibrationPattern = CollectionUtil.toPrimitive(pattern.toArray(new Long[pattern.size()]));
610+
vibrationPattern = new long[pattern.size()];
611+
Iterator<Number> iterator = pattern.iterator();
612+
for (int i = 0; i < vibrationPattern.length; i++) {
613+
Number next = iterator.next();
614+
if (next != null) {
615+
vibrationPattern[i] = next.longValue();
616+
}
617+
}
609618
}
610619
} catch (Exception e) {
611620
Log.w("Failed to parse vibration pattern.");

AndroidSDKTests/src/test/java/com/leanplum/LeanplumNotificationChannelTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ public void testNotificationChannels() throws Exception {
9595
channel2.put("name", "name_2");
9696
channel2.put("importance", 1);
9797
channel2.put("description", "description_2");
98+
channel2.put("enable_vibration", true);
99+
channel2.put("vibration_pattern", new long[] {1L, 2L, 3L, 4L, 5L});
98100

99101
HashMap<String, Object> channel3 = new HashMap<>();
100102
channel3.put("id", "id_3");
101103
channel3.put("name", "name_3");
102104
channel3.put("importance", 1);
103105
channel3.put("description", "description_3");
106+
channel3.put("enable_vibration", true);
107+
channel3.put("vibration_pattern", new ArrayList<Long>() {{add(1L); add(2L); add(3L);}});
104108

105109
groupList.add(group1);
106110
groupList.add(group2);

AndroidSDKTests/src/test/java/com/leanplum/LeanplumTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.List;
5757
import java.util.Locale;
5858
import java.util.Map;
59+
import java.util.Objects;
5960
import java.util.concurrent.CountDownLatch;
6061
import java.util.concurrent.Semaphore;
6162
import java.util.concurrent.TimeUnit;
@@ -603,7 +604,7 @@ public void onRequest(String httpMethod, String apiMethod, Map<String, Object> p
603604
});
604605
Leanplum.trackGooglePlayPurchase(eventName, 10, "USD", "data", "signature");
605606

606-
// Validate request for purchae.
607+
// Validate request for purchase.
607608
RequestHelper.addRequestHandler(new RequestHelper.RequestHandler() {
608609
@Override
609610
public void onRequest(String httpMethod, String apiMethod, Map<String, Object> params) {
@@ -621,6 +622,23 @@ public void onRequest(String httpMethod, String apiMethod, Map<String, Object> p
621622
}
622623
});
623624
Leanplum.trackGooglePlayPurchase(eventName, 10, "USD", "data", "signature", new HashMap<String, Object>());
625+
626+
// Validate request for manual purchase.
627+
RequestHelper.addRequestHandler(new RequestHelper.RequestHandler() {
628+
@Override
629+
public void onRequest(String httpMethod, String apiMethod, Map<String, Object> params) {
630+
assertEquals(Constants.Methods.TRACK, apiMethod);
631+
632+
String requestEventName = (String) params.get("event");
633+
String requestEventValue = (String) params.get("value");
634+
String requestCurrencyCode = (String) params.get("currencyCode");
635+
636+
assertEquals(eventName, requestEventName);
637+
assertEquals("1.99", requestEventValue);
638+
assertEquals("USD", requestCurrencyCode);
639+
}
640+
});
641+
Leanplum.trackPurchase(eventName, 1.99, "USD", new HashMap<String, Objects>());
624642
}
625643

626644
@Test

Leanplum.svg

Lines changed: 1 addition & 0 deletions
Loading

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# Leanplum-Android-SDK
1+
![Leanplum](Leanplum.svg)
2+
3+
<p align="center">
4+
<img src='https://jenkins.leanplum.com/buildStatus/icon?job=android-sdk'></a>
5+
<a href="https://raw.githubusercontent.com/Leanplum/Leanplum-iOS-SDK/master/LICENSE"><img src="https://img.shields.io/badge/license-apache%202.0-blue.svg?style=flat" alt="License: Apache 2.0" /></a>
6+
</p>
7+
28
## Installation & Usage
39
Please refer to: https://www.leanplum.com/docs#/setup/android
410
## Development Workflow

0 commit comments

Comments
 (0)