Skip to content

Commit 0411092

Browse files
authored
Remove unnecessary code from wrapper (#514)
1 parent 034ce50 commit 0411092

File tree

5 files changed

+33
-44
lines changed

5 files changed

+33
-44
lines changed

AndroidSDKCore/src/main/java/com/leanplum/Leanplum.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,9 @@ private static void setTrafficSourceInfoInternal(HashMap<String, Object> params)
16721672
*/
16731673
public static void track(final String event, double value, String info,
16741674
Map<String, ?> params) {
1675-
MigrationManager.getWrapper().track(event, value, info, params);
1675+
LeanplumInternal.addStartIssuedHandler(() -> {
1676+
MigrationManager.getWrapper().track(event, value, info, params);
1677+
});
16761678
LeanplumInternal.track(event, value, info, params, null);
16771679
}
16781680

@@ -1698,7 +1700,9 @@ public static void trackPurchase(final String event, double value, String curren
16981700
requestArgs.put(Constants.Params.IAP_CURRENCY_CODE, currencyCode);
16991701
}
17001702

1701-
MigrationManager.getWrapper().trackPurchase(event, value, currencyCode, params);
1703+
LeanplumInternal.addStartIssuedHandler(() -> {
1704+
MigrationManager.getWrapper().trackPurchase(event, value, currencyCode, params);
1705+
});
17021706
LeanplumInternal.track(event, value, null, params, requestArgs);
17031707
} catch (Throwable t) {
17041708
Log.exception(t);
@@ -1768,17 +1772,19 @@ public static void trackGooglePlayPurchase(String eventName, String item, long p
17681772
}
17691773
modifiedParams.put(Constants.Params.IAP_ITEM, item);
17701774

1771-
if (MigrationManager.trackGooglePlayPurchases()) {
1772-
MigrationManager.getWrapper().trackGooglePlayPurchase(
1773-
eventName,
1774-
item,
1775-
priceMicros / 1000000.0,
1776-
currencyCode,
1777-
purchaseData,
1778-
dataSignature,
1779-
params
1780-
);
1781-
}
1775+
LeanplumInternal.addStartIssuedHandler(() -> {
1776+
if (MigrationManager.trackGooglePlayPurchases()) {
1777+
MigrationManager.getWrapper().trackGooglePlayPurchase(
1778+
eventName,
1779+
item,
1780+
priceMicros / 1000000.0,
1781+
currencyCode,
1782+
purchaseData,
1783+
dataSignature,
1784+
params
1785+
);
1786+
}
1787+
});
17821788
LeanplumInternal.track(eventName, priceMicros / 1000000.0, null, modifiedParams, requestArgs);
17831789
}
17841790

AndroidSDKCore/src/main/java/com/leanplum/migration/MigrationManager.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ object MigrationManager {
2828

2929
@JvmStatic
3030
fun updateWrapper() {
31+
if (Constants.isNoop()) {
32+
wrapper = NullWrapper
33+
return
34+
}
35+
3136
if (getState().useCleverTap()
3237
&& (wrapper == NullWrapper || wrapper == StaticMethodsWrapper)
3338
) {
3439
wrapper = WrapperFactory.createWrapper(cleverTapInstanceCallback)
3540
} else if (wrapper != NullWrapper && !getState().useCleverTap()) {
36-
wrapper = WrapperFactory.createNullWrapper()
41+
wrapper = NullWrapper
3742
}
3843
}
3944

AndroidSDKCore/src/main/java/com/leanplum/migration/wrapper/CTWrapper.kt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import com.clevertap.android.sdk.ActivityLifecycleCallback
66
import com.clevertap.android.sdk.CleverTapAPI
77
import com.clevertap.android.sdk.CleverTapInstanceConfig
88
import com.leanplum.callbacks.CleverTapInstanceCallback
9-
import com.leanplum.internal.Constants
10-
import com.leanplum.internal.LeanplumInternal
119
import com.leanplum.internal.Log
1210
import com.leanplum.migration.MigrationConstants
1311
import com.leanplum.migration.MigrationManager
@@ -99,7 +97,6 @@ internal class CTWrapper(
9997
info: String?,
10098
params: Map<String, Any?>?
10199
) {
102-
if (Constants.isNoop()) return
103100
if (event == null) return
104101

105102
val properties =
@@ -112,10 +109,8 @@ internal class CTWrapper(
112109
properties[MigrationConstants.INFO_PARAM] = info
113110
}
114111

115-
LeanplumInternal.addStartIssuedHandler {
116-
Log.d("Wrapper: Leanplum.track will call pushEvent with $event and $properties")
117-
cleverTapInstance?.pushEvent(event, properties)
118-
}
112+
Log.d("Wrapper: Leanplum.track will call pushEvent with $event and $properties")
113+
cleverTapInstance?.pushEvent(event, properties)
119114
}
120115

121116
/**
@@ -127,8 +122,6 @@ internal class CTWrapper(
127122
currencyCode: String?,
128123
params: Map<String, Any?>?
129124
) {
130-
if (Constants.isNoop()) return
131-
132125
val filteredParams =
133126
params?.mapValues(::mapNotSupportedValues)?.toMutableMap()
134127
?: mutableMapOf()
@@ -143,10 +136,8 @@ internal class CTWrapper(
143136

144137
val items = arrayListOf<HashMap<String, Any?>>()
145138

146-
LeanplumInternal.addStartIssuedHandler {
147-
Log.d("Wrapper: Leanplum.trackPurchase will call pushChargedEvent with $details and $items")
148-
cleverTapInstance?.pushChargedEvent(details, items)
149-
}
139+
Log.d("Wrapper: Leanplum.trackPurchase will call pushChargedEvent with $details and $items")
140+
cleverTapInstance?.pushChargedEvent(details, items)
150141
}
151142

152143
/**
@@ -161,8 +152,6 @@ internal class CTWrapper(
161152
dataSignature: String?,
162153
params: Map<String, Any?>?
163154
) {
164-
if (Constants.isNoop()) return
165-
166155
val filteredParams =
167156
params?.mapValues(::mapNotSupportedValues)?.toMutableMap()
168157
?: mutableMapOf()
@@ -178,10 +167,8 @@ internal class CTWrapper(
178167

179168
val items = arrayListOf<HashMap<String, Any?>>()
180169

181-
LeanplumInternal.addStartIssuedHandler {
182-
Log.d("Wrapper: Leanplum.trackGooglePlayPurchase will call pushChargedEvent with $details and $items")
183-
cleverTapInstance?.pushChargedEvent(details, items)
184-
}
170+
Log.d("Wrapper: Leanplum.trackGooglePlayPurchase will call pushChargedEvent with $details and $items")
171+
cleverTapInstance?.pushChargedEvent(details, items)
185172
}
186173

187174
/**

AndroidSDKCore/src/main/java/com/leanplum/migration/wrapper/IdentityManager.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@ internal class IdentityManager(
7979
}
8080
}
8181

82-
private fun identity(): String {
83-
return when (val userId = userId) {
84-
deviceId -> deviceId
85-
else -> userId
86-
}
87-
}
88-
89-
fun profile() = mapOf(MigrationConstants.IDENTITY to identity())
82+
fun profile() = mapOf(MigrationConstants.IDENTITY to userId)
9083

9184
fun setUserId(userId: String) {
9285
if (state == ANONYMOUS) {

AndroidSDKCore/src/main/java/com/leanplum/migration/wrapper/WrapperFactory.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.leanplum.migration.wrapper
22

33
import com.leanplum.Leanplum
44
import com.leanplum.callbacks.CleverTapInstanceCallback
5+
import com.leanplum.internal.Constants
56
import com.leanplum.internal.LeanplumInternal
67
import com.leanplum.migration.model.MigrationConfig
78

@@ -33,7 +34,4 @@ internal object WrapperFactory {
3334
}
3435
}
3536

36-
fun createNullWrapper(): IWrapper {
37-
return NullWrapper
38-
}
3937
}

0 commit comments

Comments
 (0)