Skip to main content

Complete Android App Example

A complete example showing how to integrate the Reachu Kotlin SDK into an Android application.

Overview

This example demonstrates:

  • SDK initialization
  • Product catalog display
  • Shopping cart management
  • Checkout flow
  • Payment integration (Stripe, Klarna, Vipps)

Project Structure

app/
src/main/
java/com/yourapp/
MainActivity.kt
ProductListScreen.kt
CartScreen.kt
CheckoutScreen.kt
res/
assets/
reachu-config.json
build.gradle.kts

Dependencies

build.gradle.kts
dependencies {
// Reachu SDK
implementation("io.reachu:reachu-kotlin-sdk:1.0.0")

// Jetpack Compose
implementation("androidx.compose.ui:ui:1.5.4")
implementation("androidx.compose.material3:material3:1.1.2")
implementation("androidx.activity:activity-compose:1.8.1")

// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")

// Stripe
implementation("com.stripe:stripe-android:20.37.0")

// Klarna
implementation("com.klarna.mobile:sdk:2.0.0")
}

Application Setup

Application.kt
import android.app.Application
import io.reachu.ReachuCore.configuration.ConfigurationLoader

class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ConfigurationLoader.loadConfiguration(context = this)
}
}

Main Activity

MainActivity.kt
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import io.reachu.ReachuUI.Managers.CartManager
import io.reachu.ReachuUI.Components.CheckoutDraft

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val cartManager = remember { CartManager() }
val checkoutDraft = remember { CheckoutDraft() }

setContent {
MyApp(cartManager, checkoutDraft)
}
}
}

@Composable
fun MyApp(cartManager: CartManager, checkoutDraft: CheckoutDraft) {
var showCheckout by remember { mutableStateOf(false) }

Scaffold(
topBar = {
TopAppBar(
title = { Text("My Store") },
actions = {
IconButton(onClick = { showCheckout = true }) {
Badge {
Text("${cartManager.items.size}")
}
Icon(Icons.Default.ShoppingCart)
}
}
)
}
) { padding ->
ProductListScreen(
cartManager = cartManager,
modifier = Modifier.padding(padding)
)

if (showCheckout) {
CheckoutScreen(
cartManager = cartManager,
checkoutDraft = checkoutDraft,
onDismiss = { showCheckout = false }
)
}
}
}

Product List Screen

ProductListScreen.kt
import androidx.compose.foundation.lazy.grid.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import io.reachu.ReachuUI.Managers.CartManager
import kotlinx.coroutines.launch

@Composable
fun ProductListScreen(
cartManager: CartManager,
modifier: Modifier = Modifier
) {
val scope = rememberCoroutineScope()
var products by remember { mutableStateOf<List<Product>>(emptyList()) }

LaunchedEffect(Unit) {
// Load products
products = loadProducts()
}

LazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = modifier,
contentPadding = PaddingValues(16.dp),
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
items(products) { product ->
ProductCard(
product = product,
onAddToCart = {
scope.launch {
cartManager.addProduct(
productId = product.id,
quantity = 1
)
}
}
)
}
}
}

Checkout Screen

CheckoutScreen.kt
import androidx.compose.runtime.*
import androidx.compose.ui.window.Dialog
import io.reachu.ReachuUI.Components.*

@Composable
fun CheckoutScreen(
cartManager: CartManager,
checkoutDraft: CheckoutDraft,
onDismiss: () -> Unit
) {
Dialog(onDismissRequest = onDismiss) {
val checkoutOverlay = remember {
RCheckoutOverlay(cartManager, checkoutDraft)
}

RCheckoutOverlayCompose(
overlay = checkoutOverlay,
onDismiss = onDismiss
)
}
}

Next Steps


Ready to build?