finish migration

This commit is contained in:
Hailey
2024-06-25 14:09:36 -07:00
parent b57217cb4c
commit 1ccafde11b
14 changed files with 107 additions and 222 deletions
@@ -1,5 +1,8 @@
package expo.modules.blueskyswissarmy.referrer
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.Log
import com.android.installreferrer.api.InstallReferrerClient
import com.android.installreferrer.api.InstallReferrerStateListener
@@ -8,9 +11,45 @@ import expo.modules.kotlin.modules.ModuleDefinition
import expo.modules.kotlin.Promise
class ExpoBlueskyReferrerModule : Module() {
private var intent: Intent? = null
private var activityReferrer: Uri? = null
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)
}
// 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) {
return@AsyncFunction mapOf(
"referrer" to intentReferrer.toString(),
"hostname" to intentReferrer.host,
)
}
// 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
return@AsyncFunction mapOf(
"referrer" to activityReferrer.toString(),
"hostname" to (activityReferrer?.host ?: ""),
)
}
return@AsyncFunction null
}
AsyncFunction("getGooglePlayReferrerInfoAsync") { promise: Promise ->
val referrerClient = InstallReferrerClient.newBuilder(appContext.reactContext).build()
referrerClient.startConnection(object : InstallReferrerStateListener {