From 847513e6d27cc2dec44faed3bedc0c68bf613215 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 11 Jul 2024 18:13:01 -0700 Subject: [PATCH] lint --- .../referrer/ExpoBlueskyReferrerModule.kt | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt b/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt index bd89ea7158..bac555233e 100644 --- a/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt +++ b/modules/expo-bluesky-swiss-army/android/src/main/java/expo/modules/blueskyswissarmy/referrer/ExpoBlueskyReferrerModule.kt @@ -14,52 +14,57 @@ class ExpoBlueskyReferrerModule : Module() { private var intent: Intent? = null private var activityReferrer: Uri? = null - override fun definition() = ModuleDefinition { - Name("ExpoBlueskyReferrer") + override fun definition() = + ModuleDefinition { + Name("ExpoBlueskyReferrer") - OnNewIntent { - intent = it - activityReferrer = appContext.currentActivity?.referrer - } - - AsyncFunction("getReferrerInfoAsync") { - val intentReferrer = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - intent?.getParcelableExtra(Intent.EXTRA_REFERRER, Uri::class.java) - } else { - intent?.getParcelableExtra(Intent.EXTRA_REFERRER) + OnNewIntent { + intent = it + activityReferrer = appContext.currentActivity?.referrer } - // Some apps explicitly set a referrer, like Chrome. In these cases, we prefer this since - // it's the actual website that the user came from rather than the app. - if (intentReferrer is Uri) { - val res = mapOf( - "referrer" to intentReferrer.toString(), - "hostname" to intentReferrer.host, - ) - intent = null - return@AsyncFunction res + AsyncFunction("getReferrerInfoAsync") { + val intentReferrer = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent?.getParcelableExtra(Intent.EXTRA_REFERRER, Uri::class.java) + } else { + intent?.getParcelableExtra(Intent.EXTRA_REFERRER) + } + + // Some apps explicitly set a referrer, like Chrome. In these cases, we prefer this since + // it's the actual website that the user came from rather than the app. + if (intentReferrer is Uri) { + val res = + mapOf( + "referrer" to intentReferrer.toString(), + "hostname" to intentReferrer.host, + ) + intent = null + return@AsyncFunction res + } + + // In all other cases, we'll just record the app that sent the intent. + if (activityReferrer != null) { + // referrer could become null here. `.toString()` though can be called on null + val res = + mapOf( + "referrer" to activityReferrer.toString(), + "hostname" to (activityReferrer?.host ?: ""), + ) + activityReferrer = null + return@AsyncFunction res + } + + return@AsyncFunction null } - // In all other cases, we'll just record the app that sent the intent. - if (activityReferrer != null) { - // referrer could become null here. `.toString()` though can be called on null - val res = mapOf( - "referrer" to activityReferrer.toString(), - "hostname" to (activityReferrer?.host ?: ""), - ) - activityReferrer = null - return@AsyncFunction res - } - - return@AsyncFunction null - } - - AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise -> - val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build() - referrerClient.startConnection(object : InstallReferrerStateListener { - override fun onInstallReferrerSetupFinished(responseCode: Int) { - if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) { - Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.") + AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise -> + val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build() + referrerClient.startConnection( + object : InstallReferrerStateListener { + override fun onInstallReferrerSetupFinished(responseCode: Int) { + if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) { + Log.d("ExpoGooglePlayReferrer", "Successfully retrieved referrer info.") val response = referrerClient.installReferrer Log.d("ExpoGooglePlayReferrer", "Install referrer: ${response.installReferrer}")