Skip to content

Instantly share code, notes, and snippets.

@Danyaga
Created October 15, 2019 17:00
Show Gist options
  • Save Danyaga/34cf22a1308f179b2d28ca2ad98d7e09 to your computer and use it in GitHub Desktop.
Save Danyaga/34cf22a1308f179b2d28ca2ad98d7e09 to your computer and use it in GitHub Desktop.
override fun prepareWith(
context : Context,
onDone : (() -> Unit)?
) {
this.isPrepared = false
this.mPrepareWith(context) {
this.markAsPrepared()
onDone?.invoke()
}
}
private fun mPrepareWith(
context : Context,
onDone : (() -> Unit)?
) {
val activity = context as? Activity ?: run {
this.error(
"${DeepLinks::class.java.simpleName} singleton require an ${Activity::class.java.simpleName} object as context."
)
onDone?.invoke()
return
}
Branch.enableLogging()
if (BuildConfig.isProduction.not()) {
Branch.enableTestMode()
Branch.enableDebugMode()
}
// The Branch.getAutoInstance has to be called by giving the
// context.applicationContext because with a common Context object
// the callback may not be called
val autoInstance : Branch = Branch.getAutoInstance(context.applicationContext)
val branchInitResult : Boolean = autoInstance.reInitSession(
activity,
Branch.BranchReferralInitListener { referringParams, error ->
error?.let {
this@DeepLinks.error(
"Error during init of Branch singleton (" + it.message + ")."
)
onDone?.invoke()
return@BranchReferralInitListener
}
//doing some work with referringParams
this@DeepLinks.success(
"prepare() completed! {lastSharedUrlPart : ${this.lastSharedUrlPart}, couponIdToShow : ${this.couponIdToShow}, sharedCampaignId : ${this.sharedCampaignId} }"
)
onDone?.invoke()
}
)
if (branchInitResult) {
this.log(
"Branch init successful, waiting for the given callback..."
)
return
}
this.error(
"Branch init FAILED. Calling onDone."
)
onDone?.invoke()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment