Complete Guide to HosteDay Kotlin & Android SDK (hosteday-kotlin)
The official
hosteday-kotlinSDK is a modular, production-ready library for Android and Kotlin apps built on HosteDay. Architected natively with Kotlin Coroutines, StateFlow, OkHttp, and Kotlinx Serialization, it ships with first-class Jetpack Compose components and zero-boilerplatehosteday_config.jsoninitialization.
- Official SDK Page: HosteDay Kotlin & Android SDK
- Official Maven Central Namespace: central.sonatype.com/namespace/com.hosteday
- GitHub Repository: mustafa3max/hosteday-kotlin
- Alternative Distribution (JitPack): jitpack.io/#mustafa3max/hosteday-kotlin
- Minimum Requirements:
Android API 24+|Kotlin 2.0+
1. Overview & Architecture
hosteday-kotlin is split into 5 clean modules so you only bundle what your app actually uses:
| Module | Purpose |
|---|---|
hosteday-core |
Core HTTP client (OkHttp), Auth, dynamic CRUD query builder, background jobs, and structured error handling (Pure Kotlin). |
hosteday-realtime |
Reverb WebSocket client supporting Public, Private, and Presence channels plus client- Whisper events. |
hosteday-notifications |
Firebase Cloud Messaging (FCM v1) device token sync and automatic unregistration on sign-out. |
hosteday-android |
Zero-config assets/hosteday_config.json loader, EncryptedSharedPreferences token persistence, and connectivity monitoring. |
hosteday-compose |
Drop-in Jetpack Compose UI components including HostedayConnectivityBanner and FeaturePaywallScreen. |
2. Installation & Gradle Setup
The SDK is officially published on Maven Central under the verified com.hosteday namespace:
- Official Maven Central Portal: https://central.sonatype.com/namespace/com.hosteday
Option 1 (Primary & Recommended): Install via mavenCentral()
Ensure mavenCentral() is enabled in settings.gradle.kts (included by default in modern Android projects), then add the modules you need in app/build.gradle.kts:
// app/build.gradle.kts
dependencies {
implementation("com.hosteday:hosteday-core:1.0.1")
implementation("com.hosteday:hosteday-realtime:1.0.1")
implementation("com.hosteday:hosteday-notifications:1.0.1")
implementation("com.hosteday:hosteday-android:1.0.1")
implementation("com.hosteday:hosteday-compose:1.0.1")
}
Option 2 (Alternative): Install via JitPack
If you prefer JitPack, add jitpack.io to settings.gradle.kts:
// settings.gradle.kts
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Then add the dependencies in app/build.gradle.kts:
// app/build.gradle.kts
dependencies {
// All modules bundled
implementation("com.github.mustafa3max:hosteday-kotlin:v1.0.1")
// Or pick individual modules
implementation("com.github.mustafa3max.hosteday-kotlin:hosteday-core:v1.0.1")
implementation("com.github.mustafa3max.hosteday-kotlin:hosteday-android:v1.0.1")
implementation("com.github.mustafa3max.hosteday-kotlin:hosteday-realtime:v1.0.1")
implementation("com.github.mustafa3max.hosteday-kotlin:hosteday-notifications:v1.0.1")
implementation("com.github.mustafa3max.hosteday-kotlin:hosteday-compose:v1.0.1")
}
3. Zero-Config Initialization
Download your unified hosteday_config.json from SDK Connect (https://dash.hosteday.com/sdk-connect) and place it at:
app/src/main/assets/hosteday_config.json
Initialize the SDK once inside your Application class:
import android.app.Application
import com.hosteday.android.Hosteday
import com.hosteday.core.HostedayConfig
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// Recommended: Zero-config initialization from assets/hosteday_config.json
Hosteday.initializeFromAsset(
context = this,
assetName = "hosteday_config.json",
)
// Or manual configuration:
// Hosteday.initializeApp(
// config = HostedayConfig(
// baseUrl = "https://your-app.hosteday.com",
// apiToken = "YOUR_API_PROTECTION_TOKEN",
// )
// )
}
}
Remember to register android:name=".MyApp" and <uses-permission android:name="android.permission.INTERNET" /> in AndroidManifest.xml.
4. Authentication & StateFlow
Hosteday.auth handles sign-in, registration, profile updates, and avatar uploads while automatically persisting tokens inside EncryptedSharedPreferences on Android:
import com.hosteday.core.Hosteday
import java.io.File
// 1. Sign in with email & password
suspend fun login(email: String, password: String) {
val user = Hosteday.auth.signInWithEmailAndPassword(
email = email,
password = password,
)
println("Signed in as ${user.name} (${user.email})")
}
// 2. Register a new account
suspend fun register(name: String, email: String, password: String) {
val user = Hosteday.auth.createUserWithEmailAndPassword(
name = name,
email = email,
password = password,
)
}
// 3. Update profile, upload avatar & reload
suspend fun updateAccount(avatarFile: File) {
Hosteday.auth.updateProfile(name = "Alex Mercer")
Hosteday.auth.updateAvatar(file = avatarFile)
val refreshedUser = Hosteday.auth.reload()
}
// 4. Sign out and clear encrypted session
suspend fun logout() {
Hosteday.auth.signOut()
}
Observing Auth State in Jetpack Compose / ViewModel
Collect Hosteday.auth.authStateChanges (StateFlow<HostedayUser?>) directly in your UI:
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import com.hosteday.core.Hosteday
@Composable
fun RootNavigation() {
val currentUser by Hosteday.auth.authStateChanges.collectAsState()
if (currentUser != null) {
HomeScreen(user = currentUser!!)
} else {
LoginScreen()
}
}
5. Dynamic CRUD & Advanced Filters
Query and mutate your HosteDay database tables with typed pagination (HostedayPage), filters, search, relations (relationField / relationValue), and structured validation errors (HostedayException):
import com.hosteday.core.Hosteday
import com.hosteday.core.exceptions.HostedayException
suspend fun manageProducts() {
try {
// 1. Paginated index with filters, search & relation scoping
val page = Hosteday.api.index(
table = "products",
page = 1,
perPage = 20,
search = "cloud",
filters = mapOf(
"status" to "active",
"price_gte" to 50,
),
relationField = "category_id",
relationValue = "3",
)
println("Loaded ${page.items.size} of ${page.total} items")
// 2. Show single record
val product = Hosteday.api.show(table = "products", id = 42)
// 3. Create record
val created = Hosteday.api.post(
table = "products",
body = mapOf(
"name" to "Pro Cloud Plan",
"price" to 99,
"status" to "active",
),
)
// 4. Update record
Hosteday.api.put(
table = "products",
id = 42,
body = mapOf("price" to 89),
)
// 5. Delete record
Hosteday.api.delete(table = "products", id = 42)
} catch (e: HostedayException) {
println("API Error (${e.statusCode}): ${e.message}")
e.validationErrors.forEach { (field, messages) ->
println("$field: ${messages.joinToString(", ")}")
}
}
}
6. Realtime WebSockets & Presence Channels
hosteday-realtime exposes Public, Private, and Presence channels as Kotlin Flows, including presence member tracking, client- Whisper events, and server-side event publishing:
import com.hosteday.realtime.HostedayRealtime
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
fun connectRealtime(scope: CoroutineScope, userId: Long) {
// 1. Public channel
val publicChannel = HostedayRealtime.subscribePublic("news.updates")
scope.launch {
publicChannel.listen("article.published").collect { payload ->
println("Breaking update: $payload")
}
}
// 2. Private user-scoped channel
val privateChannel = HostedayRealtime.subscribePrivate("orders.$userId")
scope.launch {
privateChannel.listen("order.updated").collect { payload ->
println("Order updated: $payload")
}
}
// 3. Presence channel with member roster & Whisper events
val room = HostedayRealtime.subscribePresence("auction.42")
scope.launch {
room.listenPresenceMembersList().collect { members ->
println("Online members: ${members.size}")
}
}
scope.launch {
room.listenPresenceMemberAdded().collect { member ->
println("Joined: ${member.userInfo}")
}
}
scope.launch {
room.listenPresenceMemberRemoved().collect { member ->
println("Left: ${member.userId}")
}
}
// Client-to-client Whisper event (client-)
room.whisper(event = "client-typing", data = mapOf("typing" to true))
// Server-side broadcast via POST /api/realtime/events/presence
scope.launch {
HostedayRealtime.publishPresenceEvent(
channel = "auction.42",
event = "bid.placed",
payload = mapOf("amount" to 520, "currency" to "USD"),
)
}
}
7. Push Notifications (FCM) & Background Jobs
A. FCM Device Token Synchronization
import com.hosteday.notifications.HostedayNotifications
// Sync token on login or FirebaseMessagingService.onNewToken()
suspend fun onFcmTokenReady(fcmToken: String) {
HostedayNotifications.syncDeviceToken(
token = fcmToken,
platform = "android",
)
}
// Unregister device token on sign-out
suspend fun onUserLogout(fcmToken: String) {
HostedayNotifications.unregisterDeviceToken(token = fcmToken)
Hosteday.auth.signOut()
}
B. Dispatching & Tracking Background Jobs
import com.hosteday.core.Hosteday
suspend fun dispatchReportJob() {
val job = Hosteday.jobs.dispatch(
jobName = "generate_monthly_invoice",
payload = mapOf("month" to "2026-11", "format" to "pdf"),
)
val status = Hosteday.jobs.getStatus(jobId = job.id)
println("Job ${job.id} state: ${status.state}")
}
8. Jetpack Compose UI Components (hosteday-compose)
Drop ready-made connectivity and paywall components directly into your Compose hierarchy:
import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import com.hosteday.compose.FeaturePaywallScreen
import com.hosteday.compose.HostedayConnectivityBanner
@Composable
fun MainAppScaffold(
isProUser: Boolean,
onUpgradeClick: () -> Unit,
content: @Composable () -> Unit,
) {
Column {
// Automatically reacts to network & WebSocket connectivity
HostedayConnectivityBanner()
if (isProUser) {
content()
} else {
FeaturePaywallScreen(
title = "Pro Feature",
description = "Upgrade your plan to unlock unlimited realtime analytics.",
actionLabel = "Upgrade Now",
onActionClick = onUpgradeClick,
)
}
}
}