Android

Kotlin library co.mealio.sdk. minSdk 24. Coroutines API, optional Compose sheet.

Install

app/build.gradle.kts
dependencies {
    implementation("co.mealio:mealio-sdk:0.1.0")
    // optional ready-made sheet
    implementation("co.mealio:mealio-sdk-compose:0.1.0")
}

The SDK's manifest adds the INTERNET permission and its sign-in activity. Nothing to add to yours.

Configure once

MyApp.kt
class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        MealioCart.configure(
            context = this,
            publishableKey = "pk_live_...",
            sessionTokenProvider = { myApi.fetchMealioSessionToken() }, // suspend, calls your server
        )
    }
}

Fill a cart

Kotlin
lifecycleScope.launch {
    try {
        val recipe = Recipe(id = "tinga", title = "Chicken Tinga",
            ingredients = listOf(RecipeIngredient("1 yellow onion"), RecipeIngredient("corn tortillas")))
        val session = MealioCart.prepareCart(store = "heb", recipe = recipe, zip = "78704")

        // session.ready: the user's earlier choices. session.needsChoice: let the user pick.
        session.choose(key, productId, preferenceId = chosenPreferenceOrNull)
        session.skip("salt")

        val result = session.addToCart()   // result.added, result.skipped, result.failed
    } catch (e: MealioException) {
        // e.code: login_cancelled, store_unavailable, location_required, ...
    }
}

Drop-in sheet

Compose
session?.let { s ->
    MealioCartSheet(session = s, onDismiss = { session = null }, onAdded = { result -> session = null })
}

Sign out

Kotlin
MealioCart.signOutOfStore("heb")
MealioCart.signOutOfAllStores()
Android's cookie store is shared by every WebView in your app, so signOutOfAllStores() clears all of them, not only the stores'. Stores that offer "Sign in with Google" need email and password here, because Google blocks its sign-in inside embedded WebViews.