Skip to content

Commit 641a6d3

Browse files
committed
refactor(kits): inline setAllUserAttributes into onSetAllUserAttributes
Remove redundant setAllUserAttributes helpers from kits and AttributeListenerTestKit. Update BaseAttributeListener Javadoc in KitIntegration. Made-with: Cursor
1 parent 06d7764 commit 641a6d3

16 files changed

Lines changed: 125 additions & 248 deletions

File tree

android-kit-base/src/androidTest/kotlin/com/mparticle/kits/testkits/AttributeListenerTestKit.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,16 @@ open class AttributeListenerTestKit :
3333
onAttributeReceived?.invoke(attributeKey, attributeValueList)
3434
}
3535

36-
fun setAllUserAttributes(
36+
override fun onSetAllUserAttributes(
3737
userAttributes: Map<String, String>,
3838
userAttributeLists: Map<String, List<String>>,
39+
user: FilteredMParticleUser,
3940
) {
4041
setAllUserAttributes?.invoke(userAttributes, userAttributeLists)
4142
userAttributes.forEach { onAttributeReceived?.invoke(it.key, it.value) }
4243
userAttributeLists.forEach { onAttributeReceived?.invoke(it.key, it.value) }
4344
}
4445

45-
override fun onSetAllUserAttributes(
46-
userAttributes: Map<String, String>,
47-
userAttributeLists: Map<String, List<String>>,
48-
user: FilteredMParticleUser,
49-
) {
50-
setAllUserAttributes(userAttributes, userAttributeLists)
51-
}
52-
5346
override fun setUserIdentity(
5447
identityType: MParticle.IdentityType,
5548
identity: String?,

android-kit-base/src/main/java/com/mparticle/kits/KitIntegration.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ void onSetUserAttributeList(
411411

412412
/**
413413
* Called when the full set of user attributes is synchronized for the current user.
414-
* Kits implementing {@link AttributeListener} typically implement a {@code setAllUserAttributes}
415-
* helper and invoke it from here with the same maps.
416414
*
417415
* @param userAttributes scalar user attributes
418416
* @param userAttributeLists list-valued user attributes when {@link #supportsAttributeLists()} is true;

kits/adobe/adobe-5/src/main/kotlin/com/mparticle/kits/AdobeKitBase.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,12 @@ abstract class AdobeKitBase :
5858

5959
override fun supportsAttributeLists(): Boolean = false
6060

61-
fun setAllUserAttributes(
62-
map: Map<String, String>,
63-
map1: Map<String, List<String>>,
64-
) {
65-
syncIds()
66-
}
67-
6861
override fun onSetAllUserAttributes(
6962
userAttributes: Map<String, String>,
7063
userAttributeLists: Map<String, List<String>>,
7164
user: FilteredMParticleUser,
7265
) {
73-
setAllUserAttributes(userAttributes, userAttributeLists)
66+
syncIds()
7467
}
7568

7669
override fun onRemoveUserAttribute(

kits/adobemedia/adobemedia-5/src/main/kotlin/com/mparticle/kits/AdobeKit.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,12 @@ open class AdobeKit :
9595

9696
override fun supportsAttributeLists(): Boolean = false
9797

98-
fun setAllUserAttributes(
99-
map: Map<String, String>,
100-
map1: Map<String, List<String>>,
101-
) {
102-
syncIds()
103-
}
104-
10598
override fun onSetAllUserAttributes(
10699
userAttributes: Map<String, String>,
107100
userAttributeLists: Map<String, List<String>>,
108101
user: FilteredMParticleUser,
109102
) {
110-
setAllUserAttributes(userAttributes, userAttributeLists)
103+
syncIds()
111104
}
112105

113106
override fun onRemoveUserAttribute(

kits/appsflyer/appsflyer-6/src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,11 @@ class AppsFlyerKit :
289289
userAttributeLists: MutableMap<String, MutableList<String>>?,
290290
user: FilteredMParticleUser?,
291291
) {
292-
setAllUserAttributes(
293-
userAttributes ?: emptyMap(),
294-
userAttributeLists ?: emptyMap(),
295-
)
292+
// No-op: this kit does not implement this feature.
296293
}
297294

298295
override fun supportsAttributeLists(): Boolean = true
299296

300-
fun setAllUserAttributes(
301-
map: Map<String, String>,
302-
map1: Map<String, List<String>>,
303-
) {
304-
// No-op: this kit does not implement this feature.
305-
}
306-
307297
override fun removeUserIdentity(identityType: MParticle.IdentityType) {
308298
with(instance) {
309299
if (MParticle.IdentityType.CustomerId == identityType) {

kits/apptimize/apptimize-3/src/main/kotlin/com/mparticle/kits/ApptimizeKit.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,16 @@ class ApptimizeKit :
132132
override fun supportsAttributeLists(): Boolean = false
133133

134134
/**
135-
* @param attributeLists is ignored by the Apptimize kit.
135+
* [userAttributeLists] is ignored by the Apptimize kit.
136136
*/
137-
fun setAllUserAttributes(
138-
attributes: Map<String, String>,
139-
attributeLists: Map<String, List<String>>,
140-
) {
141-
for ((key, value) in attributes) {
142-
Apptimize.setUserAttribute(key, value)
143-
}
144-
}
145-
146137
override fun onSetAllUserAttributes(
147138
userAttributes: Map<String, String>,
148139
userAttributeLists: Map<String, List<String>>,
149140
user: FilteredMParticleUser,
150141
) {
151-
setAllUserAttributes(userAttributes, userAttributeLists)
142+
for ((key, value) in userAttributes) {
143+
Apptimize.setUserAttribute(key, value)
144+
}
152145
}
153146

154147
override fun onRemoveUserAttribute(

kits/branch/branch-5/src/main/kotlin/com/mparticle/kits/BranchMetricsKit.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,11 @@ class BranchMetricsKit :
184184

185185
override fun supportsAttributeLists(): Boolean = true
186186

187-
fun setAllUserAttributes(
188-
map: Map<String, String>,
189-
map1: Map<String, List<String>>,
190-
) {}
191-
192187
override fun onSetAllUserAttributes(
193188
userAttributes: Map<String, String>,
194189
userAttributeLists: Map<String, List<String>>,
195190
user: FilteredMParticleUser,
196191
) {
197-
setAllUserAttributes(userAttributes, userAttributeLists)
198192
}
199193

200194
override fun onRemoveUserAttribute(

kits/braze/braze-38/src/main/kotlin/com/mparticle/kits/AppboyKit.kt

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,31 @@ open class AppboyKit :
535535
userAttributeLists: MutableMap<String, MutableList<String>>?,
536536
user: FilteredMParticleUser?,
537537
) {
538-
setAllUserAttributes(
539-
userAttributes ?: emptyMap(),
540-
userAttributeLists ?: emptyMap(),
541-
)
538+
val attributes = userAttributes ?: emptyMap()
539+
val attributeLists = userAttributeLists ?: emptyMap()
540+
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
541+
for ((key, value) in attributes) {
542+
applyScalarUserAttribute(key, value)
543+
}
544+
for ((key, value) in attributeLists) {
545+
Braze
546+
.getInstance(context)
547+
.getCurrentUser(
548+
object : IValueCallback<BrazeUser> {
549+
override fun onSuccess(brazeUser: BrazeUser) {
550+
val array = value.toTypedArray<String?>()
551+
brazeUser.setCustomAttributeArray(key, array)
552+
queueDataFlush()
553+
}
554+
555+
override fun onError() {
556+
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
557+
}
558+
},
559+
)
560+
}
561+
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
562+
}
542563
}
543564

544565
override fun supportsAttributeLists(): Boolean = true
@@ -676,38 +697,6 @@ open class AppboyKit :
676697
dataFlushRunnable?.let { dataFlushHandler.postDelayed(it, FLUSH_DELAY.toLong()) }
677698
}
678699

679-
/**
680-
* This is called when the Kit is added to the mParticle SDK, typically on app-startup.
681-
*/
682-
fun setAllUserAttributes(
683-
attributes: Map<String, String>,
684-
attributeLists: Map<String, List<String>>,
685-
) {
686-
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
687-
for ((key, value) in attributes) {
688-
applyScalarUserAttribute(key, value)
689-
}
690-
for ((key, value) in attributeLists) {
691-
Braze
692-
.getInstance(context)
693-
.getCurrentUser(
694-
object : IValueCallback<BrazeUser> {
695-
override fun onSuccess(brazeUser: BrazeUser) {
696-
val array = value.toTypedArray<String?>()
697-
brazeUser.setCustomAttributeArray(key, array)
698-
queueDataFlush()
699-
}
700-
701-
override fun onError() {
702-
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
703-
}
704-
},
705-
)
706-
}
707-
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
708-
}
709-
}
710-
711700
override fun setUserIdentity(
712701
identityType: IdentityType,
713702
identity: String,

kits/braze/braze-39/src/main/kotlin/com/mparticle/kits/AppboyKit.kt

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,31 @@ open class AppboyKit :
535535
userAttributeLists: MutableMap<String, MutableList<String>>?,
536536
user: FilteredMParticleUser?,
537537
) {
538-
setAllUserAttributes(
539-
userAttributes ?: emptyMap(),
540-
userAttributeLists ?: emptyMap(),
541-
)
538+
val attributes = userAttributes ?: emptyMap()
539+
val attributeLists = userAttributeLists ?: emptyMap()
540+
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
541+
for ((key, value) in attributes) {
542+
applyScalarUserAttribute(key, value)
543+
}
544+
for ((key, value) in attributeLists) {
545+
Braze
546+
.getInstance(context)
547+
.getCurrentUser(
548+
object : IValueCallback<BrazeUser> {
549+
override fun onSuccess(brazeUser: BrazeUser) {
550+
val array = value.toTypedArray<String?>()
551+
brazeUser.setCustomAttributeArray(key, array)
552+
queueDataFlush()
553+
}
554+
555+
override fun onError() {
556+
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
557+
}
558+
},
559+
)
560+
}
561+
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
562+
}
542563
}
543564

544565
override fun supportsAttributeLists(): Boolean = true
@@ -676,38 +697,6 @@ open class AppboyKit :
676697
dataFlushRunnable?.let { dataFlushHandler.postDelayed(it, FLUSH_DELAY.toLong()) }
677698
}
678699

679-
/**
680-
* This is called when the Kit is added to the mParticle SDK, typically on app-startup.
681-
*/
682-
fun setAllUserAttributes(
683-
attributes: Map<String, String>,
684-
attributeLists: Map<String, List<String>>,
685-
) {
686-
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
687-
for ((key, value) in attributes) {
688-
applyScalarUserAttribute(key, value)
689-
}
690-
for ((key, value) in attributeLists) {
691-
Braze
692-
.getInstance(context)
693-
.getCurrentUser(
694-
object : IValueCallback<BrazeUser> {
695-
override fun onSuccess(brazeUser: BrazeUser) {
696-
val array = value.toTypedArray<String?>()
697-
brazeUser.setCustomAttributeArray(key, array)
698-
queueDataFlush()
699-
}
700-
701-
override fun onError() {
702-
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
703-
}
704-
},
705-
)
706-
}
707-
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
708-
}
709-
}
710-
711700
override fun setUserIdentity(
712701
identityType: IdentityType,
713702
identity: String,

kits/braze/braze-40/src/main/kotlin/com/mparticle/kits/AppboyKit.kt

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,31 @@ open class AppboyKit :
535535
userAttributeLists: MutableMap<String, MutableList<String>>?,
536536
user: FilteredMParticleUser?,
537537
) {
538-
setAllUserAttributes(
539-
userAttributes ?: emptyMap(),
540-
userAttributeLists ?: emptyMap(),
541-
)
538+
val attributes = userAttributes ?: emptyMap()
539+
val attributeLists = userAttributeLists ?: emptyMap()
540+
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
541+
for ((key, value) in attributes) {
542+
applyScalarUserAttribute(key, value)
543+
}
544+
for ((key, value) in attributeLists) {
545+
Braze
546+
.getInstance(context)
547+
.getCurrentUser(
548+
object : IValueCallback<BrazeUser> {
549+
override fun onSuccess(brazeUser: BrazeUser) {
550+
val array = value.toTypedArray<String?>()
551+
brazeUser.setCustomAttributeArray(key, array)
552+
queueDataFlush()
553+
}
554+
555+
override fun onError() {
556+
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
557+
}
558+
},
559+
)
560+
}
561+
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
562+
}
542563
}
543564

544565
override fun supportsAttributeLists(): Boolean = true
@@ -676,38 +697,6 @@ open class AppboyKit :
676697
dataFlushRunnable?.let { dataFlushHandler.postDelayed(it, FLUSH_DELAY.toLong()) }
677698
}
678699

679-
/**
680-
* This is called when the Kit is added to the mParticle SDK, typically on app-startup.
681-
*/
682-
fun setAllUserAttributes(
683-
attributes: Map<String, String>,
684-
attributeLists: Map<String, List<String>>,
685-
) {
686-
if (!kitPreferences.getBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, false)) {
687-
for ((key, value) in attributes) {
688-
applyScalarUserAttribute(key, value)
689-
}
690-
for ((key, value) in attributeLists) {
691-
Braze
692-
.getInstance(context)
693-
.getCurrentUser(
694-
object : IValueCallback<BrazeUser> {
695-
override fun onSuccess(brazeUser: BrazeUser) {
696-
val array = value.toTypedArray<String?>()
697-
brazeUser.setCustomAttributeArray(key, array)
698-
queueDataFlush()
699-
}
700-
701-
override fun onError() {
702-
Logger.warning("unable to set key: " + key + " with User Attribute List: " + value)
703-
}
704-
},
705-
)
706-
}
707-
kitPreferences.edit().putBoolean(PREF_KEY_HAS_SYNCED_ATTRIBUTES, true).apply()
708-
}
709-
}
710-
711700
override fun setUserIdentity(
712701
identityType: IdentityType,
713702
identity: String,

0 commit comments

Comments
 (0)