diff --git a/AGENTS.md b/AGENTS.md index 7fe8ea7..9f96b59 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -164,9 +164,9 @@ Legende: ✅ erledigt · 🚧 in Arbeit · ⬜ offen `upsertItemName` in Projektion (innerhalb Push-Transaktion). - ✅ **Phase C – Caddy:** `Caddyfile.behind-proxy` (auto_https off, trusted_proxies), `CADDY_HTTP_PORT`/`CADDY_HTTPS_PORT` in docker-compose. -- ⬜ **Phase D – Android-Fundament:** Gradle (Kotlin DSL, Version Catalog, Hilt/KSP, Compose BOM), - Theme, Nav, Room. -- ⬜ **Phase D – Repository + Retrofit-API + DTOs.** +- ✅ **Phase D – Android-Fundament:** Gradle (Kotlin DSL, Version Catalog, Hilt/KSP, Compose BOM, Room, Retrofit, WorkManager), Theme, Nav. + **Verifiziert:** `./gradlew assembleDebug` und `./gradlew test` erfolgreich. +- ✅ **Phase D – Repository + Retrofit-API + DTOs:** Room DB (`lists`, `items`, `op_log`), DAOs (LWW upsert), `MitbringslApi`, AuthInterceptor, Hilt Modules (`DatabaseModule`, `NetworkModule`, `RepositoryModule`). - ⬜ **Phase D – Login-Screen** (eigene User + Google Credential Manager + Generic OIDC PKCE). - ⬜ **Phase E – SyncEngine** (OutboxDrain + CursorPull via WorkManager), HLC client-side. - ⬜ **Phase E – Listen-Übersicht + Detail + AddItemBar (Autocomplete) + Settings.** @@ -174,27 +174,16 @@ Legende: ✅ erledigt · 🚧 in Arbeit · ⬜ offen - ⬜ **Phase F – README + docs** (ARCHITECTURE/SYNC/API). ### Wo genau weitermachen? -**Phase C ist komplett ✅. Nächster Schritt = Phase D (Android-Fundament).** +**Phase D (Fundament + Repositories) ist komplett ✅. Nächster Schritt = Phase D Login-Screen / Phase E SyncEngine.** -Phase C erledigt: -- ✅ `internal/sync/hlc.go` – HLC (wall_ms<<16|counter, Tick/Now/After, global mutex). -- ✅ `internal/store/opstore.go` – AppendOps idempotent (ON CONFLICT DO NOTHING), LWW-Projektion - (list_create/rename/delete, item_add/update/remove), PullOps (cursor, 500er Pages). -- ✅ `internal/store/liststore.go` – CreateList / GetLists / GetList (owner-check MVP). -- ✅ `internal/store/itemstore.go` – GetItems (nicht-gelöschte Items einer Liste). -- ✅ `internal/store/suggeststore.go` – Search (pg_trgm fuzzy, LIKE-fallback, 10 Ergebnisse). -- ✅ `internal/httpapi/lists.go` – GET/POST /api/lists, GET /api/lists/{id} + Items. -- ✅ `internal/httpapi/ops.go` – POST /api/lists/{id}/ops (Push), GET /api/lists/{id}/ops (Pull). -- ✅ `internal/httpapi/suggest.go` – GET /api/suggestions?q=. -- ✅ `internal/httpapi/api.go` – alle Routen verdrahtet. -- ✅ `deploy/Caddyfile.behind-proxy` – auto_https off + trusted_proxies. -- ✅ `deploy/docker-compose.yml` – CADDY_HTTP_PORT / CADDY_HTTPS_PORT. - -Phase D – Android-Fundament (offen): -1. Gradle-Setup: Kotlin DSL + `libs.versions.toml`, Hilt/KSP, Compose BOM, Room, Retrofit. -2. Theme (Material 3) + Navigation (Compose Nav). -3. Room-Datenbankschema (Listen/Items/OpLog/Outbox). -4. Retrofit-API + DTOs passend zu den Backend-Endpoints. +Phase D erledigt: +- ✅ Android CLI Setup (`android create empty-activity`). +- ✅ Version Catalog (`libs.versions.toml`) mit Compose BOM, Hilt, Room, Retrofit, OkHttp, WorkManager, Kotlinx Serialization. +- ✅ AGP 9.0 Compatibility (Kotlin Plugin built-in). +- ✅ Room DB (`AppDatabase`), Entities (`ListEntity`, `ItemEntity`, `OpLogEntity`), DAOs mit LWW Upsert (`ListDao`, `ItemDao`, `OpLogDao`). +- ✅ Retrofit API Interface (`MitbringslApi`), DTOs (`Dtos.kt`), AuthInterceptor (Bearer Token Injection). +- ✅ Hilt Dependency Injection (`DatabaseModule`, `NetworkModule`, `RepositoryModule`, `@HiltAndroidApp MitbringslApp`). +- ✅ Gradle build & unit tests verifiziert (`assembleDebug` & `test` grün). --- @@ -238,6 +227,6 @@ docker run --rm --network \ ## Git-Status - Repo initialisiert, Branch `main`. Remote ist konfiguriert (`origin`). -- Phase A + Phase B (vollständig) committed und gepusht. -- Phase C (Sync-Kern + Caddy behind-proxy) committed und gepusht. **Phase C vollständig ✅.** -- Nächster Schritt: **Phase D – Android-Fundament** (siehe Roadmap oben). +- Phase A + Phase B + Phase C committed und gepusht. +- Phase D (Android-Fundament, Room DB, Retrofit API, Hilt Setup) committed und gepusht. **Phase D Fundament vollständig ✅.** +- Nächster Schritt: **Login-Screen / Phase E SyncEngine** (siehe Roadmap oben). diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..3111f41 --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,17 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +*.jks +*.keystore diff --git a/android/app/.gitignore b/android/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/android/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 0000000..e0666c7 --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,125 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.compose.compiler) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.ksp) + alias(libs.plugins.room) +} + +android { + namespace = "com.example.mitbringsl" + compileSdk = 36 + + defaultConfig { + applicationId = "com.example.mitbringsl" + minSdk = 26 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + + // Backend base URL – override in release build or via local.properties + buildConfigField("String", "BASE_URL", "\"http://10.0.2.2:8080/\"") + } + + buildTypes { + release { + isMinifyEnabled = true + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + // Override BASE_URL for production + buildConfigField("String", "BASE_URL", "\"https://mitbringsl.example.com/\"") + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + buildFeatures { + compose = true + buildConfig = true // needed for BASE_URL injection + aidl = false + shaders = false + } + + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +// Room schema export directory +room { + schemaDirectory("$projectDir/schemas") +} + +kotlin { + jvmToolchain(17) +} + +dependencies { + val composeBom = platform(libs.androidx.compose.bom) + implementation(composeBom) + androidTestImplementation(composeBom) + + // Core Android + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + + // Lifecycle / ViewModel + implementation(libs.androidx.lifecycle.runtime.compose) + implementation(libs.androidx.lifecycle.viewmodel.compose) + + // Compose UI + Material3 + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + debugImplementation(libs.androidx.compose.ui.tooling) + + // Navigation 3 + implementation(libs.androidx.navigation3.ui) + implementation(libs.androidx.navigation3.runtime) + implementation(libs.androidx.lifecycle.viewmodel.navigation3) + + // Hilt (DI) + implementation(libs.hilt.android) + ksp(libs.hilt.android.compiler) + implementation(libs.hilt.navigation.compose) + + // Room (local DB – source of truth) + implementation(libs.room.runtime) + implementation(libs.room.ktx) + ksp(libs.room.compiler) + + // Retrofit + OkHttp (network) + implementation(libs.retrofit) + implementation(libs.retrofit.serialization) + implementation(libs.okhttp) + implementation(libs.okhttp.logging) + + // Kotlinx Serialization (JSON) + implementation(libs.kotlinx.serialization.json) + + // Coroutines + implementation(libs.kotlinx.coroutines.android) + + // WorkManager (background sync) + implementation(libs.workmanager.ktx) + implementation(libs.hilt.work) + ksp(libs.hilt.work.compiler) + + // Tests + testImplementation(libs.junit) + testImplementation(libs.kotlinx.coroutines.test) + androidTestImplementation(libs.androidx.test.core) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.androidx.test.espresso.core) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.test.manifest) +} diff --git a/android/app/schemas/com.example.mitbringsl.data.local.AppDatabase/1.json b/android/app/schemas/com.example.mitbringsl.data.local.AppDatabase/1.json new file mode 100644 index 0000000..26b5546 --- /dev/null +++ b/android/app/schemas/com.example.mitbringsl.data.local.AppDatabase/1.json @@ -0,0 +1,305 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "c5e70cf816f82a65da0a30d8315b70e8", + "entities": [ + { + "tableName": "lists", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `ownerId` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `hlcTs` INTEGER NOT NULL, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "ownerId", + "columnName": "ownerId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "deletedAt", + "columnName": "deletedAt", + "affinity": "INTEGER" + }, + { + "fieldPath": "hlcTs", + "columnName": "hlcTs", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_lists_ownerId", + "unique": false, + "columnNames": [ + "ownerId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_lists_ownerId` ON `${TABLE_NAME}` (`ownerId`)" + }, + { + "name": "index_lists_deletedAt", + "unique": false, + "columnNames": [ + "deletedAt" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_lists_deletedAt` ON `${TABLE_NAME}` (`deletedAt`)" + } + ] + }, + { + "tableName": "items", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `listId` TEXT NOT NULL, `name` TEXT NOT NULL, `quantity` TEXT, `checked` INTEGER NOT NULL, `sortOrder` INTEGER, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `hlcTs` INTEGER NOT NULL, `clientId` TEXT, `checkedAt` INTEGER, PRIMARY KEY(`id`), FOREIGN KEY(`listId`) REFERENCES `lists`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "listId", + "columnName": "listId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "quantity", + "columnName": "quantity", + "affinity": "TEXT" + }, + { + "fieldPath": "checked", + "columnName": "checked", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "sortOrder", + "columnName": "sortOrder", + "affinity": "INTEGER" + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "updatedAt", + "columnName": "updatedAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "deletedAt", + "columnName": "deletedAt", + "affinity": "INTEGER" + }, + { + "fieldPath": "hlcTs", + "columnName": "hlcTs", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "clientId", + "columnName": "clientId", + "affinity": "TEXT" + }, + { + "fieldPath": "checkedAt", + "columnName": "checkedAt", + "affinity": "INTEGER" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [ + { + "name": "index_items_listId", + "unique": false, + "columnNames": [ + "listId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_items_listId` ON `${TABLE_NAME}` (`listId`)" + }, + { + "name": "index_items_deletedAt", + "unique": false, + "columnNames": [ + "deletedAt" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_items_deletedAt` ON `${TABLE_NAME}` (`deletedAt`)" + } + ], + "foreignKeys": [ + { + "table": "lists", + "onDelete": "CASCADE", + "onUpdate": "NO ACTION", + "columns": [ + "listId" + ], + "referencedColumns": [ + "id" + ] + } + ] + }, + { + "tableName": "op_log", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`localId` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `listId` TEXT NOT NULL, `clientId` TEXT NOT NULL, `clientSeq` INTEGER NOT NULL, `opType` TEXT NOT NULL, `targetId` TEXT NOT NULL, `payload` TEXT NOT NULL, `hlcTs` INTEGER NOT NULL, `createdAt` INTEGER NOT NULL, `serverSeq` INTEGER, `synced` INTEGER NOT NULL)", + "fields": [ + { + "fieldPath": "localId", + "columnName": "localId", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "listId", + "columnName": "listId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "clientId", + "columnName": "clientId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "clientSeq", + "columnName": "clientSeq", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "opType", + "columnName": "opType", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "targetId", + "columnName": "targetId", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "payload", + "columnName": "payload", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "hlcTs", + "columnName": "hlcTs", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "createdAt", + "columnName": "createdAt", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "serverSeq", + "columnName": "serverSeq", + "affinity": "INTEGER" + }, + { + "fieldPath": "synced", + "columnName": "synced", + "affinity": "INTEGER", + "notNull": true + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "localId" + ] + }, + "indices": [ + { + "name": "index_op_log_listId", + "unique": false, + "columnNames": [ + "listId" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_op_log_listId` ON `${TABLE_NAME}` (`listId`)" + }, + { + "name": "index_op_log_clientId_clientSeq", + "unique": true, + "columnNames": [ + "clientId", + "clientSeq" + ], + "orders": [], + "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_op_log_clientId_clientSeq` ON `${TABLE_NAME}` (`clientId`, `clientSeq`)" + }, + { + "name": "index_op_log_synced", + "unique": false, + "columnNames": [ + "synced" + ], + "orders": [], + "createSql": "CREATE INDEX IF NOT EXISTS `index_op_log_synced` ON `${TABLE_NAME}` (`synced`)" + } + ] + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'c5e70cf816f82a65da0a30d8315b70e8')" + ] + } +} \ No newline at end of file diff --git a/android/app/src/androidTest/java/com/example/mitbringsl/ui/main/MainScreenTest.kt b/android/app/src/androidTest/java/com/example/mitbringsl/ui/main/MainScreenTest.kt new file mode 100644 index 0000000..a4f8be1 --- /dev/null +++ b/android/app/src/androidTest/java/com/example/mitbringsl/ui/main/MainScreenTest.kt @@ -0,0 +1,26 @@ +package com.example.mitbringsl.ui.main + +import androidx.activity.ComponentActivity +import androidx.compose.ui.test.junit4.createAndroidComposeRule +import androidx.compose.ui.test.onNodeWithText +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +/** UI tests for [com.example.mitbringsl.ui.main.MainScreen]. */ +class MainScreenTest { + + @get:Rule val composeTestRule = createAndroidComposeRule() + + @Before + fun setup() { + composeTestRule.setContent { MainScreen(FAKE_DATA) } + } + + @Test + fun firstItem_exists() { + FAKE_DATA.forEach { composeTestRule.onNodeWithText(it).assertExists() } + } +} + +private val FAKE_DATA = listOf("Sample1", "Sample2", "Sample3") diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4282944 --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/java/com/example/mitbringsl/MainActivity.kt b/android/app/src/main/java/com/example/mitbringsl/MainActivity.kt new file mode 100644 index 0000000..f3b8f27 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/MainActivity.kt @@ -0,0 +1,26 @@ +package com.example.mitbringsl + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.ui.Modifier +import com.example.mitbringsl.theme.MitbringslTheme + +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class MainActivity : ComponentActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + enableEdgeToEdge() + setContent { + MitbringslTheme { Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { MainNavigation() } } + } + } +} diff --git a/android/app/src/main/java/com/example/mitbringsl/MitbringslApp.kt b/android/app/src/main/java/com/example/mitbringsl/MitbringslApp.kt new file mode 100644 index 0000000..e403882 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/MitbringslApp.kt @@ -0,0 +1,18 @@ +package com.example.mitbringsl + +import android.app.Application +import androidx.hilt.work.HiltWorkerFactory +import androidx.work.Configuration +import dagger.hilt.android.HiltAndroidApp +import javax.inject.Inject + +@HiltAndroidApp +class MitbringslApp : Application(), Configuration.Provider { + + @Inject lateinit var workerFactory: HiltWorkerFactory + + override val workManagerConfiguration: Configuration + get() = Configuration.Builder() + .setWorkerFactory(workerFactory) + .build() +} diff --git a/android/app/src/main/java/com/example/mitbringsl/Navigation.kt b/android/app/src/main/java/com/example/mitbringsl/Navigation.kt new file mode 100644 index 0000000..e7a0ac7 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/Navigation.kt @@ -0,0 +1,27 @@ +package com.example.mitbringsl + +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawingPadding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation3.runtime.entryProvider +import androidx.navigation3.runtime.rememberNavBackStack +import androidx.navigation3.ui.NavDisplay +import com.example.mitbringsl.ui.main.MainScreen + +@Composable +fun MainNavigation() { + val backStack = rememberNavBackStack(Main) + + NavDisplay( + backStack = backStack, + onBack = { backStack.removeLastOrNull() }, + entryProvider = + entryProvider { + entry
{ + MainScreen(onItemClick = { navKey -> backStack.add(navKey) }, modifier = Modifier.safeDrawingPadding().padding(16.dp)) + } + }, + ) +} diff --git a/android/app/src/main/java/com/example/mitbringsl/NavigationKeys.kt b/android/app/src/main/java/com/example/mitbringsl/NavigationKeys.kt new file mode 100644 index 0000000..78f8e8f --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/NavigationKeys.kt @@ -0,0 +1,6 @@ +package com.example.mitbringsl + +import androidx.navigation3.runtime.NavKey +import kotlinx.serialization.Serializable + +@Serializable data object Main : NavKey diff --git a/android/app/src/main/java/com/example/mitbringsl/data/DataRepository.kt b/android/app/src/main/java/com/example/mitbringsl/data/DataRepository.kt new file mode 100644 index 0000000..32fba47 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/DataRepository.kt @@ -0,0 +1,32 @@ +package com.example.mitbringsl.data + +import com.example.mitbringsl.data.local.dao.ListDao +import com.example.mitbringsl.data.local.entity.ListEntity +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject +import javax.inject.Singleton + +/** + * Repository interface for shopping lists. + * Phase D stub – only observes local Room data. + * Phase E will add the full sync logic (push outbox + pull cursor). + */ +interface ListRepository { + fun observeLists(ownerId: String): Flow> + suspend fun createList(name: String, ownerId: String): ListEntity +} + +@Singleton +class DefaultListRepository @Inject constructor( + private val listDao: ListDao, +) : ListRepository { + + override fun observeLists(ownerId: String): Flow> = + listDao.observeLists(ownerId) + + override suspend fun createList(name: String, ownerId: String): ListEntity { + val entity = ListEntity(name = name, ownerId = ownerId) + listDao.upsert(entity) + return entity + } +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/AppDatabase.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/AppDatabase.kt new file mode 100644 index 0000000..158a803 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/AppDatabase.kt @@ -0,0 +1,29 @@ +package com.example.mitbringsl.data.local + +import androidx.room.Database +import androidx.room.RoomDatabase +import com.example.mitbringsl.data.local.dao.ItemDao +import com.example.mitbringsl.data.local.dao.ListDao +import com.example.mitbringsl.data.local.dao.OpLogDao +import com.example.mitbringsl.data.local.entity.ItemEntity +import com.example.mitbringsl.data.local.entity.ListEntity +import com.example.mitbringsl.data.local.entity.OpLogEntity + +@Database( + entities = [ + ListEntity::class, + ItemEntity::class, + OpLogEntity::class, + ], + version = 1, + exportSchema = true, +) +abstract class AppDatabase : RoomDatabase() { + abstract fun listDao(): ListDao + abstract fun itemDao(): ItemDao + abstract fun opLogDao(): OpLogDao + + companion object { + const val DATABASE_NAME = "mitbringsl.db" + } +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ItemDao.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ItemDao.kt new file mode 100644 index 0000000..8efdcc3 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ItemDao.kt @@ -0,0 +1,52 @@ +package com.example.mitbringsl.data.local.dao + +import androidx.room.* +import com.example.mitbringsl.data.local.entity.ItemEntity +import kotlinx.coroutines.flow.Flow + +@Dao +interface ItemDao { + + /** Observe all non-deleted items for a list, ordered by sort_order then creation time. */ + @Query(""" + SELECT * FROM items + WHERE listId = :listId AND deletedAt IS NULL + ORDER BY sortOrder ASC, createdAt ASC + """) + fun observeItems(listId: String): Flow> + + @Upsert + suspend fun upsert(item: ItemEntity) + + @Upsert + suspend fun upsertAll(items: List) + + /** + * LWW upsert – only updates mutable fields when incoming hlc_ts is greater. + * The tombstone (deletedAt) is also applied through LWW. + */ + @Query(""" + INSERT INTO items (id, listId, name, quantity, checked, sortOrder, + createdAt, updatedAt, deletedAt, hlcTs, clientId, checkedAt) + VALUES (:id, :listId, :name, :quantity, :checked, :sortOrder, + :createdAt, :updatedAt, :deletedAt, :hlcTs, :clientId, :checkedAt) + ON CONFLICT(id) DO UPDATE SET + name = CASE WHEN :hlcTs > hlcTs THEN :name ELSE name END, + quantity = CASE WHEN :hlcTs > hlcTs THEN :quantity ELSE quantity END, + checked = CASE WHEN :hlcTs > hlcTs THEN :checked ELSE checked END, + sortOrder = CASE WHEN :hlcTs > hlcTs THEN :sortOrder ELSE sortOrder END, + updatedAt = CASE WHEN :hlcTs > hlcTs THEN :updatedAt ELSE updatedAt END, + deletedAt = CASE WHEN :hlcTs > hlcTs THEN :deletedAt ELSE deletedAt END, + checkedAt = CASE WHEN :hlcTs > hlcTs THEN :checkedAt ELSE checkedAt END, + hlcTs = CASE WHEN :hlcTs > hlcTs THEN :hlcTs ELSE hlcTs END + """) + suspend fun upsertLww( + id: String, listId: String, name: String, quantity: String?, + checked: Boolean, sortOrder: Int?, + createdAt: Long, updatedAt: Long, deletedAt: Long?, + hlcTs: Long, clientId: String?, checkedAt: Long?, + ) + + @Query("SELECT * FROM items WHERE id = :itemId LIMIT 1") + suspend fun getItem(itemId: String): ItemEntity? +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ListDao.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ListDao.kt new file mode 100644 index 0000000..e1d54ef --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/ListDao.kt @@ -0,0 +1,51 @@ +package com.example.mitbringsl.data.local.dao + +import androidx.room.* +import com.example.mitbringsl.data.local.entity.ListEntity +import kotlinx.coroutines.flow.Flow + +@Dao +interface ListDao { + + /** Observe all non-deleted lists for a given owner, newest first. */ + @Query("SELECT * FROM lists WHERE ownerId = :ownerId AND deletedAt IS NULL ORDER BY updatedAt DESC") + fun observeLists(ownerId: String): Flow> + + /** One-shot lookup of a single list. */ + @Query("SELECT * FROM lists WHERE id = :listId AND deletedAt IS NULL LIMIT 1") + suspend fun getList(listId: String): ListEntity? + + /** + * Upsert a list. + * On conflict (same primary key) the row is replaced so that fresh data + * from the server always wins in the initial seed / full-sync path. + * For LWW conflict resolution during incremental sync, see [upsertLww]. + */ + @Upsert + suspend fun upsert(list: ListEntity) + + @Upsert + suspend fun upsertAll(lists: List) + + /** + * LWW upsert: only update if the incoming hlc_ts is strictly greater than + * the stored one (Last-Write-Wins register). + */ + @Query(""" + INSERT INTO lists (id, name, ownerId, createdAt, updatedAt, deletedAt, hlcTs) + VALUES (:id, :name, :ownerId, :createdAt, :updatedAt, :deletedAt, :hlcTs) + ON CONFLICT(id) DO UPDATE SET + name = CASE WHEN :hlcTs > hlcTs THEN :name ELSE name END, + updatedAt = CASE WHEN :hlcTs > hlcTs THEN :updatedAt ELSE updatedAt END, + deletedAt = CASE WHEN :hlcTs > hlcTs THEN :deletedAt ELSE deletedAt END, + hlcTs = CASE WHEN :hlcTs > hlcTs THEN :hlcTs ELSE hlcTs END + """) + suspend fun upsertLww( + id: String, name: String, ownerId: String, + createdAt: Long, updatedAt: Long, + deletedAt: Long?, hlcTs: Long, + ) + + @Query("SELECT COUNT(*) FROM lists WHERE ownerId = :ownerId AND deletedAt IS NULL") + suspend fun count(ownerId: String): Int +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/dao/OpLogDao.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/OpLogDao.kt new file mode 100644 index 0000000..3557311 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/dao/OpLogDao.kt @@ -0,0 +1,43 @@ +package com.example.mitbringsl.data.local.dao + +import androidx.room.* +import com.example.mitbringsl.data.local.entity.OpLogEntity +import kotlinx.coroutines.flow.Flow + +@Dao +interface OpLogDao { + + /** All unsynced ops ordered by creation time (oldest first for FIFO drain). */ + @Query("SELECT * FROM op_log WHERE synced = 0 ORDER BY createdAt ASC, localId ASC") + fun observeUnsynced(): Flow> + + @Query("SELECT * FROM op_log WHERE synced = 0 ORDER BY createdAt ASC, localId ASC") + suspend fun getUnsynced(): List + + /** Unsynced ops for a specific list. */ + @Query("SELECT * FROM op_log WHERE listId = :listId AND synced = 0 ORDER BY createdAt ASC") + suspend fun getUnsyncedForList(listId: String): List + + @Insert(onConflict = OnConflictStrategy.IGNORE) + suspend fun insert(op: OpLogEntity): Long + + /** Mark an op as synced and store the server-assigned seq. */ + @Query("UPDATE op_log SET synced = 1, serverSeq = :serverSeq WHERE localId = :localId") + suspend fun markSynced(localId: Long, serverSeq: Long) + + /** Mark multiple ops synced at once (by localId). */ + @Transaction + suspend fun markAllSynced(results: Map) { + results.forEach { (localId, serverSeq) -> markSynced(localId, serverSeq) } + } + + @Query("DELETE FROM op_log WHERE synced = 1 AND createdAt < :olderThanMs") + suspend fun deleteOldSynced(olderThanMs: Long) + + @Query("SELECT COUNT(*) FROM op_log WHERE synced = 0") + fun observeUnsyncedCount(): Flow + + /** Highest server seq we have stored locally for a given list (used as pull cursor). */ + @Query("SELECT MAX(serverSeq) FROM op_log WHERE listId = :listId AND synced = 1") + suspend fun maxServerSeq(listId: String): Long? +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ItemEntity.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ItemEntity.kt new file mode 100644 index 0000000..2a35fc7 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ItemEntity.kt @@ -0,0 +1,39 @@ +package com.example.mitbringsl.data.local.entity + +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.Index +import androidx.room.PrimaryKey + +/** + * Local projection of a shopping list item. + * Source of truth flows from [OpLogEntity] via the sync engine. + */ +@Entity( + tableName = "items", + foreignKeys = [ + ForeignKey( + entity = ListEntity::class, + parentColumns = ["id"], + childColumns = ["listId"], + onDelete = ForeignKey.CASCADE, + ) + ], + indices = [Index("listId"), Index("deletedAt")] +) +data class ItemEntity( + @PrimaryKey val id: String, + val listId: String, + val name: String, + val quantity: String? = null, + val checked: Boolean = false, + val sortOrder: Int? = null, + val createdAt: Long = System.currentTimeMillis(), + val updatedAt: Long = System.currentTimeMillis(), + /** Tombstone – null means the item is alive. */ + val deletedAt: Long? = null, + val hlcTs: Long = 0L, + /** UUID of the client that created this item. */ + val clientId: String? = null, + val checkedAt: Long? = null, +) diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ListEntity.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ListEntity.kt new file mode 100644 index 0000000..3763027 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/ListEntity.kt @@ -0,0 +1,26 @@ +package com.example.mitbringsl.data.local.entity + +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey +import java.util.UUID + +/** + * Local projection of a shopping list. + * Written by the sync engine when ops arrive from the server. + * [ownerId] is the authenticated user's ID (UUID string). + */ +@Entity( + tableName = "lists", + indices = [Index("ownerId"), Index("deletedAt")] +) +data class ListEntity( + @PrimaryKey val id: String = UUID.randomUUID().toString(), + val name: String, + val ownerId: String, + val createdAt: Long = System.currentTimeMillis(), + val updatedAt: Long = System.currentTimeMillis(), + val deletedAt: Long? = null, + /** Hybrid Logical Clock timestamp – used for LWW conflict resolution. */ + val hlcTs: Long = 0L, +) diff --git a/android/app/src/main/java/com/example/mitbringsl/data/local/entity/OpLogEntity.kt b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/OpLogEntity.kt new file mode 100644 index 0000000..1ab4247 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/local/entity/OpLogEntity.kt @@ -0,0 +1,42 @@ +package com.example.mitbringsl.data.local.entity + +import androidx.room.Entity +import androidx.room.Index +import androidx.room.PrimaryKey + +/** + * Client-side op_log – the outbox for unsynced operations. + * + * Each row is a pending operation that has not yet been acknowledged by the + * server. The sync engine drains this table by pushing ops via + * POST /api/lists/{id}/ops and removes rows on success. + * + * [clientSeq] is a monotonically-increasing counter scoped to [clientId]. + * Together they form the idempotency key used by the server. + */ +@Entity( + tableName = "op_log", + indices = [ + Index("listId"), + Index(value = ["clientId", "clientSeq"], unique = true), + Index("synced"), + ] +) +data class OpLogEntity( + @PrimaryKey(autoGenerate = true) val localId: Long = 0, + val listId: String, + /** UUID of this device installation – stable, generated once. */ + val clientId: String, + val clientSeq: Long, + /** One of: list_create, list_rename, list_delete, item_add, item_update, item_remove. */ + val opType: String, + val targetId: String, + /** JSON payload, e.g. {"name":"Milch","quantity":"1L"}. */ + val payload: String = "{}", + /** Client-generated HLC timestamp. */ + val hlcTs: Long, + val createdAt: Long = System.currentTimeMillis(), + /** Set to the server-assigned seq once the op has been acknowledged. */ + val serverSeq: Long? = null, + val synced: Boolean = false, +) diff --git a/android/app/src/main/java/com/example/mitbringsl/data/remote/api/AuthInterceptor.kt b/android/app/src/main/java/com/example/mitbringsl/data/remote/api/AuthInterceptor.kt new file mode 100644 index 0000000..9dc4bcf --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/remote/api/AuthInterceptor.kt @@ -0,0 +1,25 @@ +package com.example.mitbringsl.data.remote.api + +import okhttp3.Interceptor +import okhttp3.Response + +/** + * OkHttp interceptor that injects the session Bearer token into every request. + * + * [tokenProvider] is a lambda so the interceptor always reads the most recent + * token without needing to be recreated after login. + */ +class AuthInterceptor(private val tokenProvider: () -> String?) : Interceptor { + + override fun intercept(chain: Interceptor.Chain): Response { + val token = tokenProvider() + val request = if (token.isNullOrBlank()) { + chain.request() + } else { + chain.request().newBuilder() + .header("Authorization", "Bearer $token") + .build() + } + return chain.proceed(request) + } +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/remote/api/MitbringslApi.kt b/android/app/src/main/java/com/example/mitbringsl/data/remote/api/MitbringslApi.kt new file mode 100644 index 0000000..64ae203 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/remote/api/MitbringslApi.kt @@ -0,0 +1,59 @@ +package com.example.mitbringsl.data.remote.api + +import com.example.mitbringsl.data.remote.dto.* +import retrofit2.Response +import retrofit2.http.* + +/** + * Retrofit API interface matching the mitbringsl backend. + * + * Authentication: every authenticated call must include + * Authorization: Bearer + * This is injected by the AuthInterceptor in the OkHttp client. + */ +interface MitbringslApi { + + // --- Auth --------------------------------------------------------------- + + @POST("auth/register") + suspend fun register(@Body body: RegisterRequestDto): Response + + @POST("auth/login") + suspend fun login(@Body body: LoginRequestDto): Response + + @POST("auth/oidc") + suspend fun loginOidc(@Body body: OidcRequestDto): Response + + @POST("auth/logout") + suspend fun logout(): Response + + // --- Lists -------------------------------------------------------------- + + @GET("api/lists") + suspend fun getLists(): Response + + @POST("api/lists") + suspend fun createList(@Body body: CreateListRequestDto): Response + + @GET("api/lists/{id}") + suspend fun getList(@Path("id") listId: String): Response + + // --- Ops ---------------------------------------------------------------- + + @POST("api/lists/{id}/ops") + suspend fun pushOps( + @Path("id") listId: String, + @Body body: PushRequestDto, + ): Response + + @GET("api/lists/{id}/ops") + suspend fun pullOps( + @Path("id") listId: String, + @Query("since") since: Long, + ): Response + + // --- Suggestions -------------------------------------------------------- + + @GET("api/suggestions") + suspend fun getSuggestions(@Query("q") query: String): Response +} diff --git a/android/app/src/main/java/com/example/mitbringsl/data/remote/dto/Dtos.kt b/android/app/src/main/java/com/example/mitbringsl/data/remote/dto/Dtos.kt new file mode 100644 index 0000000..e649631 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/data/remote/dto/Dtos.kt @@ -0,0 +1,138 @@ +package com.example.mitbringsl.data.remote.dto + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonObject + +// --------------------------------------------------------------------------- +// Auth +// --------------------------------------------------------------------------- + +@Serializable +data class RegisterRequestDto( + val email: String, + val password: String, + @SerialName("display_name") val displayName: String = "", +) + +@Serializable +data class LoginRequestDto( + val email: String, + val password: String, +) + +@Serializable +data class OidcRequestDto( + val provider: String, + @SerialName("id_token") val idToken: String, +) + +@Serializable +data class AuthResponseDto( + val token: String, + @SerialName("expires_at") val expiresAt: String, + val user: UserDto, +) + +@Serializable +data class UserDto( + val id: String, + val email: String, + @SerialName("display_name") val displayName: String = "", +) + +// --------------------------------------------------------------------------- +// Lists +// --------------------------------------------------------------------------- + +@Serializable +data class CreateListRequestDto(val name: String) + +@Serializable +data class ListDto( + val id: String, + val name: String, + @SerialName("updated_at") val updatedAt: String, + @SerialName("hlc_ts") val hlcTs: Long, +) + +@Serializable +data class ListsResponseDto(val lists: List) + +@Serializable +data class ListDetailDto( + val id: String, + val name: String, + @SerialName("updated_at") val updatedAt: String, + @SerialName("hlc_ts") val hlcTs: Long, + val items: List, +) + +@Serializable +data class ItemDto( + val id: String, + @SerialName("list_id") val listId: String, + val name: String, + val quantity: String? = null, + val checked: Boolean = false, + @SerialName("sort_order") val sortOrder: Int? = null, + @SerialName("created_at") val createdAt: String, + @SerialName("updated_at") val updatedAt: String, + @SerialName("hlc_ts") val hlcTs: Long, + @SerialName("client_id") val clientId: String? = null, + @SerialName("checked_at") val checkedAt: String? = null, +) + +// --------------------------------------------------------------------------- +// Ops (Push / Pull) +// --------------------------------------------------------------------------- + +@Serializable +data class PushRequestDto( + @SerialName("client_id") val clientId: String, + val ops: List, +) + +@Serializable +data class IncomingOpDto( + @SerialName("client_seq") val clientSeq: Long, + @SerialName("op_type") val opType: String, + @SerialName("target_id") val targetId: String, + @SerialName("hlc_ts") val hlcTs: Long, + val payload: JsonObject, +) + +@Serializable +data class PushResponseDto(val results: List) + +@Serializable +data class OpResultDto( + @SerialName("client_seq") val clientSeq: Long, + val seq: Long, + @SerialName("hlc_ts") val hlcTs: Long, +) + +@Serializable +data class PullResponseDto( + val ops: List, + @SerialName("has_more") val hasMore: Boolean, +) + +@Serializable +data class ServerOpDto( + val seq: Long, + @SerialName("client_id") val clientId: String, + @SerialName("op_type") val opType: String, + @SerialName("target_id") val targetId: String, + val payload: JsonObject, + @SerialName("client_seq") val clientSeq: Long, + @SerialName("hlc_ts") val hlcTs: Long, + @SerialName("created_at") val createdAt: String, +) + +// --------------------------------------------------------------------------- +// Suggestions +// --------------------------------------------------------------------------- + +@Serializable +data class SuggestionsResponseDto(val suggestions: List) diff --git a/android/app/src/main/java/com/example/mitbringsl/di/DatabaseModule.kt b/android/app/src/main/java/com/example/mitbringsl/di/DatabaseModule.kt new file mode 100644 index 0000000..c8c3957 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/di/DatabaseModule.kt @@ -0,0 +1,30 @@ +package com.example.mitbringsl.di + +import android.content.Context +import androidx.room.Room +import com.example.mitbringsl.data.local.AppDatabase +import com.example.mitbringsl.data.local.dao.ItemDao +import com.example.mitbringsl.data.local.dao.ListDao +import com.example.mitbringsl.data.local.dao.OpLogDao +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object DatabaseModule { + + @Provides + @Singleton + fun provideDatabase(@ApplicationContext context: Context): AppDatabase = + Room.databaseBuilder(context, AppDatabase::class.java, AppDatabase.DATABASE_NAME) + .fallbackToDestructiveMigration(dropAllTables = false) + .build() + + @Provides fun provideListDao(db: AppDatabase): ListDao = db.listDao() + @Provides fun provideItemDao(db: AppDatabase): ItemDao = db.itemDao() + @Provides fun provideOpLogDao(db: AppDatabase): OpLogDao = db.opLogDao() +} diff --git a/android/app/src/main/java/com/example/mitbringsl/di/NetworkModule.kt b/android/app/src/main/java/com/example/mitbringsl/di/NetworkModule.kt new file mode 100644 index 0000000..b265083 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/di/NetworkModule.kt @@ -0,0 +1,73 @@ +package com.example.mitbringsl.di + +import android.content.Context +import com.example.mitbringsl.BuildConfig +import com.example.mitbringsl.data.remote.api.AuthInterceptor +import com.example.mitbringsl.data.remote.api.MitbringslApi +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import kotlinx.serialization.json.Json +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import retrofit2.converter.kotlinx.serialization.asConverterFactory +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object NetworkModule { + + /** + * Lax JSON decoder: ignores unknown keys so the app doesn't crash when the + * backend adds new fields, and handles missing optional fields gracefully. + */ + @Provides + @Singleton + fun provideJson(): Json = Json { + ignoreUnknownKeys = true + isLenient = true + coerceInputValues = true + } + + @Provides + @Singleton + fun provideTokenProvider(@ApplicationContext context: Context): () -> String? = { + // Read token from SharedPreferences (written after login). + context.getSharedPreferences("session", Context.MODE_PRIVATE) + .getString("token", null) + } + + @Provides + @Singleton + fun provideOkHttpClient(tokenProvider: () -> String?): OkHttpClient { + val logging = HttpLoggingInterceptor().apply { + level = if (BuildConfig.DEBUG) { + HttpLoggingInterceptor.Level.BODY + } else { + HttpLoggingInterceptor.Level.NONE + } + } + return OkHttpClient.Builder() + .addInterceptor(AuthInterceptor(tokenProvider)) + .addInterceptor(logging) + .build() + } + + @Provides + @Singleton + fun provideRetrofit(client: OkHttpClient, json: Json): Retrofit = + Retrofit.Builder() + .baseUrl(BuildConfig.BASE_URL) + .client(client) + .addConverterFactory(json.asConverterFactory("application/json; charset=UTF-8".toMediaType())) + .build() + + @Provides + @Singleton + fun provideMitbringslApi(retrofit: Retrofit): MitbringslApi = + retrofit.create(MitbringslApi::class.java) +} diff --git a/android/app/src/main/java/com/example/mitbringsl/di/RepositoryModule.kt b/android/app/src/main/java/com/example/mitbringsl/di/RepositoryModule.kt new file mode 100644 index 0000000..80e9b8c --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/di/RepositoryModule.kt @@ -0,0 +1,18 @@ +package com.example.mitbringsl.di + +import com.example.mitbringsl.data.DefaultListRepository +import com.example.mitbringsl.data.ListRepository +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +abstract class RepositoryModule { + + @Binds + @Singleton + abstract fun bindListRepository(impl: DefaultListRepository): ListRepository +} diff --git a/android/app/src/main/java/com/example/mitbringsl/theme/Color.kt b/android/app/src/main/java/com/example/mitbringsl/theme/Color.kt new file mode 100644 index 0000000..96b947e --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/theme/Color.kt @@ -0,0 +1,11 @@ +package com.example.mitbringsl.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) diff --git a/android/app/src/main/java/com/example/mitbringsl/theme/Theme.kt b/android/app/src/main/java/com/example/mitbringsl/theme/Theme.kt new file mode 100644 index 0000000..c1a127d --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/theme/Theme.kt @@ -0,0 +1,50 @@ +package com.example.mitbringsl.theme + +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext + +private val DarkColorScheme = darkColorScheme(primary = Purple80, secondary = PurpleGrey80, tertiary = Pink80) + +private val LightColorScheme = + lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40, + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ + ) + +@Composable +fun MitbringslTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit, +) { + val colorScheme = + when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content) +} diff --git a/android/app/src/main/java/com/example/mitbringsl/theme/Type.kt b/android/app/src/main/java/com/example/mitbringsl/theme/Type.kt new file mode 100644 index 0000000..ac30a62 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/theme/Type.kt @@ -0,0 +1,36 @@ +package com.example.mitbringsl.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = + Typography( + bodyLarge = + TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ + ) diff --git a/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreen.kt b/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreen.kt new file mode 100644 index 0000000..e4c93eb --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreen.kt @@ -0,0 +1,35 @@ +package com.example.mitbringsl.ui.main + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.hilt.navigation.compose.hiltViewModel +import androidx.navigation3.runtime.NavKey +import com.example.mitbringsl.theme.MitbringslTheme + +@Composable +fun MainScreen( + onItemClick: (NavKey) -> Unit, + modifier: Modifier = Modifier, + viewModel: MainScreenViewModel = hiltViewModel(), +) { + MainScreen(data = listOf("Mitbringsl App Initialized"), modifier = modifier) +} + +@Composable +internal fun MainScreen(data: List, modifier: Modifier = Modifier) { + Column(modifier) { data.forEach { Greeting(it) } } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text(text = "$name", modifier = modifier) +} + +@Preview(showBackground = true) +@Composable +fun MainScreenPreview() { + MitbringslTheme { MainScreen(listOf("Mitbringsl App Initialized")) } +} diff --git a/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreenViewModel.kt b/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreenViewModel.kt new file mode 100644 index 0000000..de34d70 --- /dev/null +++ b/android/app/src/main/java/com/example/mitbringsl/ui/main/MainScreenViewModel.kt @@ -0,0 +1,18 @@ +package com.example.mitbringsl.ui.main + +import androidx.lifecycle.ViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +/** + * Placeholder ViewModel for the main screen. + * Will be replaced in Phase E with the full ListsViewModel backed by Room. + */ +@HiltViewModel +class MainScreenViewModel @Inject constructor() : ViewModel() + +sealed interface MainScreenUiState { + object Loading : MainScreenUiState + data class Error(val throwable: Throwable) : MainScreenUiState + data class Success(val data: List) : MainScreenUiState +} diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..237b423 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Mitbringsl + \ No newline at end of file diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..e63cd59 --- /dev/null +++ b/android/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +