Created
October 15, 2019 17:00
-
-
Save Danyaga/34cf22a1308f179b2d28ca2ad98d7e09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
[email protected]( | |
"Error during init of Branch singleton (" + it.message + ")." | |
) | |
onDone?.invoke() | |
return@BranchReferralInitListener | |
} | |
//doing some work with referringParams | |
[email protected]( | |
"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