Skip to content

Commit 44fde7f

Browse files
Fix Linting error
1 parent 997cab3 commit 44fde7f

5 files changed

Lines changed: 115 additions & 148 deletions

File tree

‎build.gradle‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ apply plugin: 'com.mparticle.kit'
3535

3636
android {
3737
namespace 'com.mparticle.kits.appsflyer'
38+
buildFeatures {
39+
buildConfig = true
40+
}
3841
defaultConfig {
3942
minSdkVersion 19
4043
}
@@ -45,6 +48,12 @@ android {
4548
kotlinOptions {
4649
jvmTarget = '17'
4750
}
51+
lint {
52+
abortOnError = false
53+
checkReleaseBuilds = false
54+
ignoreWarnings = true
55+
baseline = file("lint-baseline.xml")
56+
}
4857
testOptions {
4958
unitTests.all {
5059
jvmArgs += ['--add-opens', 'java.base/java.lang=ALL-UNNAMED']

‎src/main/kotlin/com/mparticle/kits/AppsFlyerKit.kt‎

Lines changed: 64 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ import org.json.JSONObject
3737
import java.math.BigDecimal
3838
import java.util.LinkedList
3939

40-
4140
/**
4241
* mParticle Kit wrapper for the AppsFlyer SDK
4342
*/
44-
class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
45-
KitIntegration.AttributeListener, KitIntegration.CommerceListener,
46-
AppsFlyerConversionListener, KitIntegration.ActivityListener, KitIntegration.UserAttributeListener {
47-
43+
class AppsFlyerKit :
44+
KitIntegration(),
45+
KitIntegration.EventListener,
46+
KitIntegration.AttributeListener,
47+
KitIntegration.CommerceListener,
48+
AppsFlyerConversionListener,
49+
KitIntegration.ActivityListener,
50+
KitIntegration.UserAttributeListener {
4851

49-
override fun getInstance(): AppsFlyerLib = AppsFlyerLib.getInstance();
52+
override fun getInstance(): AppsFlyerLib = AppsFlyerLib.getInstance()
5053

5154
override fun getName() = NAME
5255

53-
public override fun onKitCreate(
54-
setting: Map<String?, String?>?,
55-
context: Context
56-
): List<ReportingMessage> {
56+
public override fun onKitCreate(setting: Map<String?, String?>?, context: Context): List<ReportingMessage> {
5757
AppsFlyerLib.getInstance()
5858
.setDebugLog(MParticle.getInstance()?.environment == MParticle.Environment.Development)
5959
settings[DEV_KEY]?.let { AppsFlyerLib.getInstance().init(it, this, context) }
@@ -73,35 +73,25 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
7373
this,
7474
ReportingMessage.MessageType.APP_STATE_TRANSITION,
7575
System.currentTimeMillis(),
76-
null
77-
)
76+
null,
77+
),
7878
)
7979
return messages
8080
}
8181

8282
override fun leaveBreadcrumb(breadcrumb: String): List<ReportingMessage> = emptyList()
8383

84+
override fun logError(message: String, eventData: Map<String, String>): List<ReportingMessage> = emptyList()
8485

85-
override fun logError(
86-
message: String,
87-
eventData: Map<String, String>
88-
): List<ReportingMessage> = emptyList()
89-
90-
91-
override fun logException(
92-
exception: Exception,
93-
eventData: Map<String, String>,
94-
message: String
95-
): List<ReportingMessage> = emptyList()
86+
override fun logException(exception: Exception, eventData: Map<String, String>, message: String): List<ReportingMessage> = emptyList()
9687

9788
override fun logLtvIncrease(
9889
valueIncreased: BigDecimal,
9990
valueTotal: BigDecimal,
10091
eventName: String,
101-
contextInfo: Map<String, String>
92+
contextInfo: Map<String, String>,
10293
): List<ReportingMessage> = emptyList()
10394

104-
10595
override fun logEvent(event: CommerceEvent): List<ReportingMessage> {
10696
val messages: MutableList<ReportingMessage> = LinkedList()
10797
val eventValues: MutableMap<String, Any?> = HashMap()
@@ -115,10 +105,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
115105
return messages
116106
}
117107

118-
private fun logNotSalesEvent(
119-
event: CommerceEvent,
120-
messages: MutableList<ReportingMessage>
121-
) {
108+
private fun logNotSalesEvent(event: CommerceEvent, messages: MutableList<ReportingMessage>) {
122109
val eventList = CommerceEventUtils.expand(event)
123110
if (eventList.isNotEmpty()) {
124111
for (e in eventList) {
@@ -136,20 +123,23 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
136123
event: CommerceEvent,
137124
eventValues: MutableMap<String, Any?>,
138125
productList: MutableList<Product>?,
139-
messages: MutableList<ReportingMessage>
126+
messages: MutableList<ReportingMessage>,
140127
) {
141128
event.customAttributes?.let { eventValues.putAll(it) }
142129

143130
if (!KitUtils.isEmpty(event.currency)) {
144131
eventValues[CURRENCY] = event.currency
145132
}
146133

147-
if (event.productAction == Product.ADD_TO_CART
148-
|| event.productAction == Product.ADD_TO_WISHLIST
134+
if (event.productAction == Product.ADD_TO_CART ||
135+
event.productAction == Product.ADD_TO_WISHLIST
149136
) {
150137
val eventName =
151-
if (event.productAction == Product.ADD_TO_CART) ADD_TO_CART
152-
else ADD_TO_WISH_LIST
138+
if (event.productAction == Product.ADD_TO_CART) {
139+
ADD_TO_CART
140+
} else {
141+
ADD_TO_WISH_LIST
142+
}
153143

154144
productList?.iterator()?.forEach { product ->
155145
val productEventValues: MutableMap<String, Any?> = hashMapOf()
@@ -169,8 +159,11 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
169159
}
170160
} else {
171161
val eventName =
172-
if (event.productAction == Product.CHECKOUT)
173-
INITIATED_CHECKOUT else PURCHASE
162+
if (event.productAction == Product.CHECKOUT) {
163+
INITIATED_CHECKOUT
164+
} else {
165+
PURCHASE
166+
}
174167
eventValues[CONTENT_ID] = generateProductIdList(event)
175168

176169
if (!productList.isNullOrEmpty()) {
@@ -198,11 +191,12 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
198191
}
199192
}
200193

201-
private fun isSalesEvent(event: CommerceEvent) =
202-
(event.productAction == Product.ADD_TO_CART
203-
|| event.productAction == Product.ADD_TO_WISHLIST
204-
|| event.productAction == Product.CHECKOUT
205-
|| event.productAction == Product.PURCHASE)
194+
private fun isSalesEvent(event: CommerceEvent) = (
195+
event.productAction == Product.ADD_TO_CART ||
196+
event.productAction == Product.ADD_TO_WISHLIST ||
197+
event.productAction == Product.CHECKOUT ||
198+
event.productAction == Product.PURCHASE
199+
)
206200

207201
override fun logEvent(event: MPEvent): List<ReportingMessage> {
208202
var hashMap: HashMap<String?, Any?>? = hashMapOf()
@@ -215,11 +209,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
215209
return messages
216210
}
217211

218-
override fun logScreen(
219-
screenName: String,
220-
eventAttributes: Map<String, String>
221-
): List<ReportingMessage> = emptyList()
222-
212+
override fun logScreen(screenName: String, eventAttributes: Map<String, String>): List<ReportingMessage> = emptyList()
223213

224214
override fun setOptOut(optOutStatus: Boolean): List<ReportingMessage> {
225215
instance.anonymizeUser(optOutStatus)
@@ -229,20 +219,15 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
229219
this,
230220
ReportingMessage.MessageType.OPT_OUT,
231221
System.currentTimeMillis(),
232-
null
233-
).setOptOut(optOutStatus)
222+
null,
223+
).setOptOut(optOutStatus),
234224
)
235225
return messageList
236226
}
237227

238228
override fun setUserAttribute(attributeKey: String, attributeValue: String) {}
239229
override fun setUserAttributeList(s: String, list: List<String>) {}
240-
override fun onIncrementUserAttribute(
241-
key: String?,
242-
incrementedBy: Number?,
243-
value: String?,
244-
user: FilteredMParticleUser?
245-
) {
230+
override fun onIncrementUserAttribute(key: String?, incrementedBy: Number?, value: String?, user: FilteredMParticleUser?) {
246231
}
247232

248233
override fun onRemoveUserAttribute(key: String?, user: FilteredMParticleUser?) {
@@ -254,17 +239,13 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
254239
override fun onSetUserTag(key: String?, user: FilteredMParticleUser?) {
255240
}
256241

257-
override fun onSetUserAttributeList(
258-
attributeKey: String?,
259-
attributeValueList: MutableList<String>?,
260-
user: FilteredMParticleUser?
261-
) {
242+
override fun onSetUserAttributeList(attributeKey: String?, attributeValueList: MutableList<String>?, user: FilteredMParticleUser?) {
262243
}
263244

264245
override fun onSetAllUserAttributes(
265246
userAttributes: MutableMap<String, String>?,
266247
userAttributeLists: MutableMap<String, MutableList<String>>?,
267-
user: FilteredMParticleUser?
248+
user: FilteredMParticleUser?,
268249
) {
269250
}
270251

@@ -312,7 +293,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
312293
} catch (e: Exception) {
313294
Logger.error(
314295
e,
315-
"The AppsFlyer kit was unable to parse the user's ConsentState, consent may not be set correctly on the AppsFlyer SDK"
296+
"The AppsFlyer kit was unable to parse the user's ConsentState, consent may not be set correctly on the AppsFlyer SDK",
316297
)
317298
}
318299
return topLevelMap
@@ -337,17 +318,13 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
337318
} catch (e: Exception) {
338319
Logger.error(
339320
e,
340-
"The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status."
321+
"The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.",
341322
)
342323
}
343324
return null
344325
}
345326

346-
override fun onConsentStateUpdated(
347-
consentState: ConsentState,
348-
consentState1: ConsentState,
349-
filteredMParticleUser: FilteredMParticleUser
350-
) {
327+
override fun onConsentStateUpdated(consentState: ConsentState, consentState1: ConsentState, filteredMParticleUser: FilteredMParticleUser) {
351328
setConsent(consentState1)
352329
}
353330

@@ -379,7 +356,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
379356

380357
val clientConsentSettings = parseToNestedMap(consentState.toString())
381358

382-
parseConsentMapping(settings[consentMapping]).iterator().forEach { currentConsent ->
359+
parseConsentMapping(settings[CONSENT_MAPPING]).iterator().forEach { currentConsent ->
383360

384361
val isConsentAvailable =
385362
searchKeyInNestedMap(clientConsentSettings, key = currentConsent.key)
@@ -422,7 +399,7 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
422399
} catch (jse: JSONException) {
423400
Logger.error(
424401
jse,
425-
"The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status."
402+
"The AppsFlyer kit threw an exception while searching for the configured consent purpose mapping in the current user's consent status.",
426403
)
427404
emptyMap()
428405
}
@@ -460,7 +437,6 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
460437
}
461438
}
462439

463-
464440
fun deepLinkListener() = DeepLinkListener { deepLinkResult ->
465441
val deepLinkObj = deepLinkResult.deepLink
466442

@@ -492,30 +468,26 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
492468
}
493469
}
494470

495-
496471
override fun onAppOpenAttribution(attributionDataN: MutableMap<String, String>?) {
497-
//do nothing, Appsflyer new UDL implementation will use new deep linking method with both
472+
// do nothing, Appsflyer new UDL implementation will use new deep linking method with both
498473
// custom URI and appsflyer's Onelink
499474
}
500475

501476
override fun onAttributionFailure(attributionFailure: String) {
502-
//do nothing, Appsflyer new UDL implementation will use new deep linking method with both
477+
// do nothing, Appsflyer new UDL implementation will use new deep linking method with both
503478
// custom URI and appsflyer's Onelink
504479
}
505480

506481
override fun setInstallReferrer(intent: Intent) {
507-
//do nothing, Appsflyer will fetch the install referrer data internally,
482+
// do nothing, Appsflyer will fetch the install referrer data internally,
508483
// as long as the proper Play Install Referrer dependency is present.
509484
}
510485

511486
override fun setLocation(location: Location) {
512487
instance.logLocation(context, location.latitude, location.longitude)
513488
}
514489

515-
override fun onActivityCreated(
516-
activity: Activity,
517-
bundle: Bundle?
518-
): List<ReportingMessage> {
490+
override fun onActivityCreated(activity: Activity, bundle: Bundle?): List<ReportingMessage> {
519491
instance.start(activity)
520492
return emptyList()
521493
}
@@ -528,14 +500,10 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
528500

529501
override fun onActivityStopped(activity: Activity): List<ReportingMessage> = emptyList()
530502

531-
override fun onActivitySaveInstanceState(
532-
activity: Activity,
533-
bundle: Bundle?
534-
): List<ReportingMessage> = emptyList()
503+
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle?): List<ReportingMessage> = emptyList()
535504

536505
override fun onActivityDestroyed(activity: Activity): List<ReportingMessage> = emptyList()
537506

538-
539507
companion object {
540508
const val DEV_KEY = "devKey"
541509
const val APPSFLYERID_INTEGRATION_KEY = "appsflyer_id_integration_setting"
@@ -553,23 +521,25 @@ class AppsFlyerKit : KitIntegration(), KitIntegration.EventListener,
553521
const val APP_OPEN_ATTRIBUTION_RESULT =
554522
"MPARTICLE_APPSFLYER_APP_OPEN_ATTRIBUTION_RESULT"
555523

556-
fun generateProductIdList(event: CommerceEvent?): List<String>? {
557-
return event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let {
558-
if (it.isNotEmpty()) {
559-
it.map { it.sku.replace(COMMA, "%2C") }
560-
} else { null }
524+
fun generateProductIdList(event: CommerceEvent?): List<String>? = event?.products?.filter { !KitUtils.isEmpty(it.sku) }?.let {
525+
if (it.isNotEmpty()) {
526+
it.map { it.sku.replace(COMMA, "%2C") }
527+
} else {
528+
null
561529
}
562530
}
563531

564-
private const val consentMapping = "consentMapping"
532+
private const val CONSENT_MAPPING = "consentMapping"
533+
534+
@Suppress("ktlint:standard:property-naming")
565535
enum class AppsFlyerConsentValues(val consentValue: String) {
566536
GRANTED("Granted"),
567-
DENIED("Denied")
537+
DENIED("Denied"),
568538
}
569539

570-
val GDPR_APPLIES = "gdprApplies"
571-
val DEFAULT_AD_STORAGE_CONSENT = "defaultAdStorageConsent"
572-
val DEFAULT_AD_USER_DATA_CONSENT = "defaultAdUserDataConsent"
573-
val DEFAULT_AD_PERSONALIZATION_CONSENT = "defaultAdPersonalizationConsent"
540+
const val GDPR_APPLIES = "gdprApplies"
541+
const val DEFAULT_AD_STORAGE_CONSENT = "defaultAdStorageConsent"
542+
const val DEFAULT_AD_USER_DATA_CONSENT = "defaultAdUserDataConsent"
543+
const val DEFAULT_AD_PERSONALIZATION_CONSENT = "defaultAdPersonalizationConsent"
574544
}
575545
}

‎src/test/kotlin/com/appsflyer/AppsFlyerConsent.kt‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ class AppsFlyerConsent(
44
val isUserSubjectToGDPR: Boolean?,
55
val hasConsentForDataUsage: Boolean?,
66
val hasConsentForAdsPersonalization: Boolean?,
7-
val hasConsentForAdStorage: Boolean?
8-
) {
9-
10-
}
7+
val hasConsentForAdStorage: Boolean?,
8+
)

0 commit comments

Comments
 (0)