NeoDay Android SDK - Campaigns

The NeoDaySDK factory methods are executed asynchronously in order to fetch the data and return a NeoDayViewController.

/**
* Makes the Campaigns Overview screen that shows all the Campaigns available for a user.
*
* @param filter a CampaignTypeFilter to filter the return campaigns
* @param completion returns NeoDayViewController or an Exception
*/
fun makeCampaignsOverview(
    filter: CampaignTypeFilter = CampaignTypeFilter.ShowAll,
    completion: (Result<NeoDayViewController>) -> Unit)
)

/**
* Makes the Campaign detail screen based on the campaignId and/or campaignInstanceID.
*
* @param campaignId the id of the Campaign
* @param campaignInstanceId Optional, a Campaign will have a unique campaignInstanceId when a user can participate in the Campaign.
* @param completion returns NeoDayViewController or an Exception
*/
fun makeCampaignDetail(
    campaignId: String, 
    campaignInstanceId: String? = null,
    completion: (Result<NeoDayViewController>) -> Unit
)

/** 
* Makes the Campaign transaction history screen based on the campaignId and blockID.
*
* @param campaignId The id of the Campaign
* @param blockId The id of the block
* @param completion returns NeoDayViewController or an Exception
*/
fun makeCampaignTransactionsHistory(
    campaignId: String, 
    blockId: String,
    completion: (Result<NeoDayViewController>) -> Unit
)

/** 
* Participate with a Campaign without having to be on the Campaign detail screen.
*
* @param participationMethod The participation method to use for a Campaign
* @param completion returns the result of participating
*/
fun participate(
    participationMethod: ParticipationMethod,
    completion: (Result<Boolean>) -> Unit
)

Directly requesting a Campaigns Overview screen

val vc = remember { mutableStateOf<NeoDayViewController?>(null) }
neoDaySDK.makeCampaignsOverview { result ->
    try {
        vc.value = result.getOrThrow()
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
}
vc.value?.getView()?.invoke()

Directly requesting a Campaign detail screen

val vc = remember { mutableStateOf<NeoDayViewController?>(null) }
neoDaySDK.makeCampaignDetail(
    campaignId = "<campaignId>",
    campaignInstanceId = "<campaignInstanceId>"
) { result ->
    try {
        vc.value = result.getOrThrow()
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
}
vc.value?.getView()?.invoke()

Directly requesting a Campaign Transaction History screen

val vc = remember { mutableStateOf<NeoDayViewController?>(null) }
neoDaySDK.makeCampaignTransactionsHistory(
    campaignId = "<campaignId>",
) { result ->
    try {
        vc.value = result.getOrThrow()
    } catch (ex: Exception) {
        ex.printStackTrace()
    }
}
vc.value?.getView()?.invoke()

Participating with a Campaign

It is possible to participate with a Campaign without being on the Campaign Detail screen. This is currently only supported for the "Scratch Card" Campaign in combination with a "code submission" participation.

val campaignId = "<some-campaign-id>"
val code = "<some-code>"

neoDaySDK.participate(
    ParticipationMethod.CodeSubmission(campaignId, code)
) { result ->
    try {
        result.getOrThrow()
        // code submission succeed
    } catch (ex: Exception) {
        // code submission failed
    }
}

// NeoDayDeepLinkListener
neoDaySDK.neoDayDeepLinkListener = = object : NeoDayDeepLinkListener {
    override fun handleDeepLink(
        deepLink: DeepLink,
        factoryMethod: (((Result<NeoDayViewController>) -> Unit) -> Unit)?
    ) {
        when (deepLink.identifier) {
            DeepLinkIdentifier.campaignGamificationView -> {
                factoryMethod?.invoke { result ->
                    try {
                        viewModel.gamificationView = result.getOrThrow()
                        // show the view
                    } catch (ex: Exception) {
                        // on error
                    }
                }
            }
            // ...
        }
    }
    
}