diff --git a/apps/README.md b/apps/README.md index 89acb50..f421071 100644 --- a/apps/README.md +++ b/apps/README.md @@ -6,7 +6,7 @@ | [pc/](pc/README.md) | 桌面浏览器网页 | `item-atlas-pc` | | [admin/](admin/README.md) | 管理后台 | `item-atlas-admin` | | [ios/](ios/README.md) | iOS 原生应用 | 见物 | -| `android/` | Android 原生应用 | 见物 | +| [android/](android/README.md) | Android 原生应用 | 见物 | 前三个客户端独立构建,Web Dockerfile 随各自源码维护。各端对齐 OpenAPI 契约、错误码、术语和关键交互。Web 首版包含 H5、PC 和后台,原生端按各自设计和发布节奏推进。 diff --git a/apps/android/.gitattributes b/apps/android/.gitattributes new file mode 100644 index 0000000..f663f18 --- /dev/null +++ b/apps/android/.gitattributes @@ -0,0 +1 @@ +gradlew.bat text eol=crlf diff --git a/apps/android/.gitignore b/apps/android/.gitignore new file mode 100644 index 0000000..d0093b2 --- /dev/null +++ b/apps/android/.gitignore @@ -0,0 +1,6 @@ +.gradle/ +.kotlin/ +**/build/ +local.properties +*.jks +*.keystore diff --git a/apps/android/README.md b/apps/android/README.md new file mode 100644 index 0000000..e4daeb3 --- /dev/null +++ b/apps/android/README.md @@ -0,0 +1,23 @@ +# 见物 Android + +Android 8.0(API 26)及以上。使用 Kotlin、Jetpack Compose 和见物原生会话 API。用已有账号登录后,可新建或切换空间、按名称和别名找物、查看详情、手动添加物品和移位。录入可以不选位置,移位也可以清空位置。只读空间仅显示查询功能。 + +会话令牌只在应用进程内使用,续期由 API 客户端处理。应用被完全关闭后需要重新登录。应用不预置物品、账号或凭据。 + +## 构建和安装 + +准备 JDK 17 或 21、Android SDK Platform 35 与 Build Tools 35.0.0。用 `ANDROID_HOME` 指向 SDK,Gradle Wrapper 会校验其发行包。 + +```sh +cd apps/android +./gradlew :app:assembleDebug +adb install -r app/build/outputs/apk/debug/app-debug.apk +``` + +调试版默认连接 `https://api-atlas.tutudog.com`。联调其他环境时传入 `-PATLAS_API_ORIGIN=https://你的网关域名`,只接受 HTTPS。调试 APK 供开发和试装。商店分发需要单独的发布签名和 AAB。 + +## 验收 + +登录后切换空间,输入名称或别名并打开详情。分别尝试在有位置和无位置时录入,再移动到另一个位置或清空位置。用只读成员检查物品写入口,用网络中断检查失败提示,退出后确认页面清空。首版测试范围为账号、空间与物品,拍照、语音、社区及平面图随后接入。 + +[客户端架构](../../docs/architecture/clients.md) · [Android 构建](https://developer.android.com/build/building-cmdline) diff --git a/apps/android/app/build.gradle.kts b/apps/android/app/build.gradle.kts new file mode 100644 index 0000000..75aaea9 --- /dev/null +++ b/apps/android/app/build.gradle.kts @@ -0,0 +1,47 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + id("com.android.application") + kotlin("android") + id("org.jetbrains.kotlin.plugin.compose") + kotlin("plugin.serialization") +} + +android { + namespace = "com.tutudog.itematlas" + compileSdk = 35 + + defaultConfig { + applicationId = "com.tutudog.itematlas" + minSdk = 26 + targetSdk = 35 + versionCode = 1 + versionName = "0.1.0" + + val apiOrigin = providers.gradleProperty("ATLAS_API_ORIGIN").orElse("https://api-atlas.tutudog.com").get() + require(Regex("https://[A-Za-z0-9.-]+(:[0-9]+)?").matches(apiOrigin)) { "ATLAS_API_ORIGIN must be an HTTPS origin" } + buildConfigField("String", "ATLAS_API_ORIGIN", "\"$apiOrigin\"") + } + + buildFeatures { + compose = true + buildConfig = true + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + +kotlin { compilerOptions.jvmTarget.set(JvmTarget.JVM_17) } + +dependencies { + implementation(platform("androidx.compose:compose-bom:2025.05.01")) + implementation("androidx.activity:activity-compose:1.10.1") + implementation("androidx.compose.foundation:foundation") + implementation("androidx.compose.material3:material3") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.7") + implementation("com.squareup.okhttp3:okhttp:4.12.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") +} diff --git a/apps/android/app/src/main/AndroidManifest.xml b/apps/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..31bcc75 --- /dev/null +++ b/apps/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + diff --git a/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasApi.kt b/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasApi.kt new file mode 100644 index 0000000..c85ef24 --- /dev/null +++ b/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasApi.kt @@ -0,0 +1,188 @@ +package com.tutudog.itematlas + +import java.io.IOException +import java.util.concurrent.TimeUnit +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import okhttp3.Call +import okhttp3.Callback +import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response + +@Serializable +data class Space(val id: String, val name: String, val role: String) { + val writable: Boolean get() = role == "OWNER" || role == "EDITOR" +} + +@Serializable +data class Place(val id: String, val name: String, val path: String, val parentId: String? = null) + +@Serializable +data class Item( + val id: String, + val name: String, + val quantity: Int, + val notes: String = "", + val locationId: String? = null, + val locationPath: String = "", + val aliases: List = emptyList(), + val version: Int, +) + +@Serializable +data class ItemDetail(val item: Item) + +@Serializable +data class ItemInput( + val name: String, + val quantity: Int, + val locationId: String?, + val aliases: List, + val notes: String, +) + +class ApiError(val status: Int, message: String) : Exception(message) + +class AtlasApi(origin: String = BuildConfig.ATLAS_API_ORIGIN) { + @Serializable + private data class Grant(val accessToken: String, val refreshToken: String, val expiresIn: Long) + + @Serializable + private data class Login(val username: String, val password: String) + + @Serializable + private data class Refresh(val refreshToken: String) + + @Serializable + private data class SpaceInput(val name: String) + + @Serializable + private data class MoveInput(val locationId: String?, val version: Int) + + @Serializable + private data class Problem(val detail: String? = null, val message: String? = null) + + private data class Session(val grant: Grant, val expiry: Long) + + private val base = origin.toHttpUrl() + private val json = Json { ignoreUnknownKeys = true; encodeDefaults = true } + private val media = "application/json".toMediaType() + private val http = OkHttpClient.Builder().callTimeout(25, TimeUnit.SECONDS).build() + private val sessionLock = Mutex() + private var session: Session? = null + + suspend fun login(username: String, password: String) = sessionLock.withLock { + install(json.decodeFromString(transport(path("api", "session", "login"), "POST", json.encodeToString(Login(username, password))))) + } + + suspend fun logout() { + val previous = sessionLock.withLock { session.also { session = null } } ?: return + try { + transport(path("api", "session", "logout"), "POST", json.encodeToString(Refresh(previous.grant.refreshToken))) + } catch (_: IOException) { + // Local session is already cleared. + } catch (_: ApiError) { + } + } + + suspend fun spaces(): List = json.decodeFromString(read(path("api", "households"))) + + suspend fun createSpace(name: String): Space = + json.decodeFromString(read(path("api", "households"), "POST", json.encodeToString(SpaceInput(name)))) + + suspend fun locations(space: Space): List = json.decodeFromString(read(family(space, "locations"))) + + suspend fun search(space: Space, query: String, offset: Int = 0): List { + val url = family(space, "items").newBuilder() + .addQueryParameter("q", query.trim()) + .addQueryParameter("limit", "30") + .addQueryParameter("offset", offset.toString()) + .build() + return json.decodeFromString(read(url)) + } + + suspend fun detail(space: Space, id: String): ItemDetail = json.decodeFromString(read(family(space, "items", id))) + + suspend fun create(space: Space, input: ItemInput, key: String): Item = + json.decodeFromString(read(family(space, "items"), "POST", json.encodeToString(input), key)) + + suspend fun move(space: Space, item: Item, position: Place?): Item = + json.decodeFromString(read(family(space, "items", item.id, "moves"), "POST", + json.encodeToString(MoveInput(position?.id, item.version)))) + + private fun family(space: Space, vararg segments: String) = path("api", "households", space.id, *segments) + private fun path(vararg segments: String) = base.newBuilder().apply { + segments.forEach { addPathSegment(it) } + }.build() + + private fun install(grant: Grant) { + session = Session(grant, System.currentTimeMillis() + grant.expiresIn * 1000) + } + + private suspend fun access(rejected: String? = null): String = sessionLock.withLock { + val current = session ?: throw ApiError(401, "请重新登录。") + if (current.expiry > System.currentTimeMillis() + 30_000 && current.grant.accessToken != rejected) { + return@withLock current.grant.accessToken + } + try { + val refreshed = json.decodeFromString(transport(path("api", "session", "refresh"), "POST", + json.encodeToString(Refresh(current.grant.refreshToken)))) + install(refreshed) + refreshed.accessToken + } catch (failure: ApiError) { + if (failure.status == 401) session = null + throw failure + } + } + + private suspend fun read(url: okhttp3.HttpUrl, method: String = "GET", body: String? = null, key: String? = null): String { + val first = access() + return try { + transport(url, method, body, first, key) + } catch (failure: ApiError) { + if (failure.status != 401) throw failure + transport(url, method, body, access(first), key) + } + } + + private suspend fun transport( + url: okhttp3.HttpUrl, + method: String, + payload: String?, + token: String? = null, + key: String? = null, + ): String = suspendCancellableCoroutine { continuation -> + val request = Request.Builder().url(url).method(method, payload?.toRequestBody(media)) + .header("Accept", "application/json") + .apply { + token?.let { header("Authorization", "Bearer $it") } + key?.let { header("Idempotency-Key", it) } + }.build() + val call = http.newCall(request) + continuation.invokeOnCancellation { call.cancel() } + call.enqueue(object : Callback { + override fun onFailure(call: Call, e: IOException) = continuation.resumeWith(Result.failure(e)) + + override fun onResponse(call: Call, response: Response) { + continuation.resumeWith(runCatching { + response.use { + val raw = it.body?.string().orEmpty() + if (!it.isSuccessful) { + val detail = runCatching { json.decodeFromString(raw) }.getOrNull() + throw ApiError(it.code, detail?.detail ?: detail?.message ?: "请求失败(${it.code})") + } + raw + } + }) + } + }) + } +} diff --git a/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasViewModel.kt b/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasViewModel.kt new file mode 100644 index 0000000..4281784 --- /dev/null +++ b/apps/android/app/src/main/java/com/tutudog/itematlas/AtlasViewModel.kt @@ -0,0 +1,249 @@ +package com.tutudog.itematlas + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import java.io.IOException +import java.util.UUID +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.Job +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch + +enum class Screen { SignIn, Inventory, Detail, Add, Move } + +data class AtlasState( + val screen: Screen = Screen.SignIn, + val spaces: List = emptyList(), + val space: Space? = null, + val places: List = emptyList(), + val items: List = emptyList(), + val selected: Item? = null, + val query: String = "", + val nextOffset: Int = 0, + val hasMore: Boolean = false, + val loading: Boolean = false, + val busy: Boolean = false, + val error: String? = null, +) + +class AtlasViewModel : ViewModel() { + private val api = AtlasApi() + private val mutable = MutableStateFlow(AtlasState()) + val state = mutable.asStateFlow() + private var listJob: Job? = null + private var placesJob: Job? = null + private var detailJob: Job? = null + private var pendingItem: ItemInput? = null + private var pendingKey = "" + + fun signIn(username: String, password: String) { + if (mutable.value.busy) return + if (username.isBlank() || password.isEmpty()) { + mutable.update { it.copy(error = "请输入账号和密码。") } + return + } + action { + api.login(username.trim(), password) + mutable.update { it.copy(screen = Screen.Inventory) } + fetchSpaces() + } + } + + fun retrySpaces() = action { fetchSpaces() } + + fun createSpace(name: String) = action { + val space = api.createSpace(name.trim()) + mutable.update { it.copy(spaces = it.spaces + space) } + switchSpace(space) + } + + private suspend fun fetchSpaces() { + val spaces = api.spaces() + mutable.update { it.copy(spaces = spaces) } + spaces.firstOrNull()?.let(::switchSpace) + } + + fun switchSpace(space: Space) { + if (mutable.value.space?.id == space.id) return + listJob?.cancel() + placesJob?.cancel() + detailJob?.cancel() + mutable.update { + it.copy(space = space, places = emptyList(), items = emptyList(), selected = null, + query = "", hasMore = false, nextOffset = 0, error = null, screen = Screen.Inventory) + } + search() + locations() + } + + private fun locations() { + val space = mutable.value.space ?: return + placesJob?.cancel() + placesJob = viewModelScope.launch { + try { + val places = api.locations(space) + if (mutable.value.space?.id == space.id) mutable.update { it.copy(places = places) } + } catch (failure: Exception) { + if (failure is CancellationException) throw failure + if (mutable.value.screen == Screen.Add || mutable.value.screen == Screen.Move) { + handle(failure) + } + } + } + } + + fun setQuery(query: String) { + if (query == mutable.value.query) return + mutable.update { it.copy(query = query.take(150), items = emptyList(), nextOffset = 0, hasMore = false) } + search(debounce = true) + } + + fun search(append: Boolean = false, debounce: Boolean = false) { + val prior = mutable.value + val space = prior.space ?: return + if (append && (prior.loading || !prior.hasMore)) return + listJob?.cancel() + mutable.update { it.copy(loading = true, error = null) } + listJob = viewModelScope.launch { + try { + if (debounce) delay(200) + val offset = if (append) prior.nextOffset else 0 + val found = api.search(space, prior.query, offset) + mutable.update { + if (it.space?.id != space.id || it.query != prior.query) it + else { + val merged = if (append) (it.items + found).distinctBy(Item::id) else found + val next = offset + found.size + it.copy(items = merged, nextOffset = next, hasMore = found.size == 30 && next <= 10000, + loading = false) + } + } + } catch (failure: Exception) { + if (failure is CancellationException) throw failure + mutable.update { it.copy(loading = false) } + handle(failure) + } + } + } + + fun open(item: Item) { + val space = mutable.value.space ?: return + detailJob?.cancel() + mutable.update { it.copy(screen = Screen.Detail, selected = item, error = null) } + detailJob = viewModelScope.launch { + try { + val detail = api.detail(space, item.id) + if (mutable.value.selected?.id == item.id && mutable.value.space?.id == space.id) { + mutable.update { it.copy(selected = detail.item) } + } + } catch (failure: Exception) { + if (failure is CancellationException) throw failure + if (failure is ApiError && failure.status in setOf(403, 404)) { + mutable.update { it.copy(selected = null) } + } + handle(failure) + } + } + } + + fun startAdd() { + if (mutable.value.space?.writable != true) return + pendingItem = null + pendingKey = "" + mutable.update { it.copy(screen = Screen.Add, error = null) } + locations() + } + + fun create(name: String, quantity: String, location: Place?, aliases: String, notes: String) { + val space = mutable.value.space?.takeIf { it.writable } ?: return + val count = quantity.toIntOrNull() + val names = aliases.split(',', ',', '、').map(String::trim).filter(String::isNotEmpty).distinct() + if (name.trim().length !in 1..150 || count == null || count !in 1..9999 || + notes.length > 1500 || names.size > 20 || names.any { it.length > 80 }) { + mutable.update { it.copy(error = "请检查名称、数量、别名和备注的长度。") } + return + } + val input = ItemInput(name.trim(), count, location?.id, names, notes) + if (pendingItem != input) { + pendingItem = input + pendingKey = UUID.randomUUID().toString() + } + action { + val item = api.create(space, input, pendingKey) + mutable.update { it.copy(screen = Screen.Detail, selected = item, query = "", items = emptyList()) } + } + } + + fun startMove() { + if (mutable.value.space?.writable != true || mutable.value.selected == null) return + mutable.update { it.copy(screen = Screen.Move, error = null) } + locations() + } + + fun move(position: Place?) { + val space = mutable.value.space?.takeIf { it.writable } ?: return + val item = mutable.value.selected ?: return + if (position?.id == item.locationId) return + action { + val moved = api.move(space, item, position) + mutable.update { it.copy(screen = Screen.Detail, selected = moved) } + } + } + + fun back() { + if (mutable.value.busy) return + detailJob?.cancel() + val from = mutable.value.screen + mutable.update { + when (from) { + Screen.Move -> it.copy(screen = Screen.Detail, error = null) + Screen.Detail, Screen.Add -> it.copy(screen = Screen.Inventory, selected = null, error = null) + else -> it + } + } + if (from == Screen.Detail) search() + } + + fun signOut() { + if (mutable.value.busy) return + listJob?.cancel() + detailJob?.cancel() + placesJob?.cancel() + mutable.value = AtlasState(busy = true) + viewModelScope.launch { + try { api.logout() } + finally { mutable.update { it.copy(busy = false) } } + } + } + + private fun action(block: suspend () -> Unit) { + if (mutable.value.busy) return + mutable.update { it.copy(busy = true, error = null) } + viewModelScope.launch { + try { block() } + catch (failure: Exception) { + if (failure is CancellationException) throw failure + handle(failure) + } finally { mutable.update { it.copy(busy = false) } } + } + } + + private fun handle(failure: Exception) { + if (failure is ApiError && failure.status == 401 && mutable.value.screen != Screen.SignIn) { + listJob?.cancel() + placesJob?.cancel() + detailJob?.cancel() + mutable.value = AtlasState(error = "登录已过期,请重新登录。") + } else { + val detail = when (failure) { + is IOException -> "连接服务失败,请检查网络。" + is ApiError -> failure.message ?: "请求失败,请重试。" + else -> "无法读取服务返回的数据,请重试。" + } + mutable.update { it.copy(error = detail) } + } + } +} diff --git a/apps/android/app/src/main/java/com/tutudog/itematlas/MainActivity.kt b/apps/android/app/src/main/java/com/tutudog/itematlas/MainActivity.kt new file mode 100644 index 0000000..785208d --- /dev/null +++ b/apps/android/app/src/main/java/com/tutudog/itematlas/MainActivity.kt @@ -0,0 +1,359 @@ +package com.tutudog.itematlas + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.SystemBarStyle +import androidx.activity.compose.BackHandler +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.activity.viewModels +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Button +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.LinearProgressIndicator +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusDirection +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.input.PasswordVisualTransformation +import androidx.compose.ui.unit.dp + +class MainActivity : ComponentActivity() { + private val model by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.light(0, 0), + navigationBarStyle = SystemBarStyle.light(0, 0x33000000), + ) + setContent { + MaterialTheme(colorScheme = lightColorScheme(primary = Color(0xFF1B604A))) { + AtlasApp(model) + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +private fun AtlasApp(model: AtlasViewModel) { + val state by model.state.collectAsState() + val child = state.screen in listOf(Screen.Detail, Screen.Add, Screen.Move) + BackHandler(child, model::back) + Scaffold(topBar = { + if (state.screen != Screen.SignIn) { + val title = when (state.screen) { + Screen.Detail -> "物品详情" + Screen.Add -> "添加物品" + Screen.Move -> "移动物品" + else -> "见物" + } + TopAppBar( + title = { Text(title) }, + navigationIcon = { if (child) TextButton(onClick = model::back, enabled = !state.busy) { Text("返回") } }, + actions = { + if (state.screen == Screen.Inventory) { + TextButton(onClick = model::signOut, enabled = !state.busy) { Text("退出登录") } + } + }, + ) + } + }) { insets -> + val content = Modifier.padding(insets).imePadding() + when (state.screen) { + Screen.SignIn -> SignIn(state, model, content) + Screen.Inventory -> Inventory(state, model, content) + Screen.Detail -> Detail(state, model, content) + Screen.Add -> AddItem(state, model, content) + Screen.Move -> MoveItem(state, model, content) + } + } +} + +@Composable +private fun SignIn(state: AtlasState, model: AtlasViewModel, modifier: Modifier) { + var account by rememberSaveable { mutableStateOf("") } + var password by remember { mutableStateOf("") } + val focus = LocalFocusManager.current + val submit = { + focus.clearFocus() + model.signIn(account, password) + } + Form(modifier) { + Spacer(Modifier.height(24.dp)) + Image(painterResource(R.drawable.brand), contentDescription = null, modifier = Modifier.size(72.dp)) + Text("见物", style = MaterialTheme.typography.headlineLarge, fontWeight = FontWeight.SemiBold) + Text("于寻常处见生活", style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant) + Spacer(Modifier.height(8.dp)) + OutlinedTextField( + account, { account = it }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("账号") }, singleLine = true, + keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next), + keyboardActions = KeyboardActions(onNext = { focus.moveFocus(FocusDirection.Down) }), + ) + OutlinedTextField( + password, { password = it }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("密码") }, singleLine = true, visualTransformation = PasswordVisualTransformation(), + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password, imeAction = ImeAction.Done), + keyboardActions = KeyboardActions(onDone = { submit() }), + ) + Status(state) + Button(onClick = submit, enabled = !state.busy && account.isNotBlank() && password.isNotEmpty(), + modifier = Modifier.fillMaxWidth()) { Text(if (state.busy) "正在登录" else "登录") } + } +} + +@Composable +private fun Inventory(state: AtlasState, model: AtlasViewModel, modifier: Modifier) { + var pickSpace by remember { mutableStateOf(false) } + var showCreateSpace by remember { mutableStateOf(false) } + Column(modifier.fillMaxWidth().padding(horizontal = 20.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) { + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { + Box { + OutlinedButton(onClick = { pickSpace = true }, enabled = !state.busy) { + Text(state.space?.name ?: "我的空间") + } + DropdownMenu(expanded = pickSpace, onDismissRequest = { pickSpace = false }) { + state.spaces.forEach { space -> + DropdownMenuItem(text = { Text(space.name) }, onClick = { + pickSpace = false + model.switchSpace(space) + }) + } + DropdownMenuItem(text = { Text("新建空间") }, onClick = { + pickSpace = false + showCreateSpace = true + }) + } + } + if (state.space?.writable == true) { + Button(onClick = model::startAdd, enabled = !state.busy) { Text("添加物品") } + } + } + if (state.space == null && !state.busy) { + Text(if (state.error == null) "暂无空间" else "空间暂时无法加载", style = MaterialTheme.typography.titleLarge) + if (state.error == null) { + Button(onClick = { showCreateSpace = true }) { Text("新建空间") } + } else { + OutlinedButton(onClick = { model.retrySpaces() }) { Text("刷新空间") } + } + } + if (state.space != null) { + OutlinedTextField( + state.query, model::setQuery, Modifier.fillMaxWidth(), singleLine = true, + label = { Text("按名称或别名找物") }, + trailingIcon = { + if (state.query.isNotEmpty()) TextButton(onClick = { model.setQuery("") }) { Text("清空") } + }, + ) + } + Status(state) + if (state.loading) LinearProgressIndicator(Modifier.fillMaxWidth()) + if (state.error != null && state.space != null) { + TextButton(onClick = { model.search() }) { Text("重新加载") } + } + if (state.space != null && state.items.isEmpty() && !state.loading && state.error == null) { + Text(if (state.query.isBlank()) "这里还没有物品" else "没有找到匹配的物品", + color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(vertical = 16.dp)) + } + LazyColumn(contentPadding = PaddingValues(bottom = 20.dp)) { + items(state.items, key = Item::id) { item -> + Row(Modifier.fillMaxWidth().clickable(enabled = !state.busy) { model.open(item) }.padding(vertical = 14.dp), + horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) { + Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) { + Text(item.name, style = MaterialTheme.typography.titleMedium) + Text(item.displayPlace(), style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant) + } + Text("× ${item.quantity}", style = MaterialTheme.typography.bodyMedium) + } + HorizontalDivider() + } + if (state.hasMore) { + item { + TextButton(onClick = { model.search(append = true) }, enabled = !state.loading) { Text("加载更多") } + } + } + } + } + if (showCreateSpace) { + var name by rememberSaveable { mutableStateOf("") } + AlertDialog( + onDismissRequest = { showCreateSpace = false }, + title = { Text("新建空间") }, + text = { + OutlinedTextField(name, { name = it.take(100) }, Modifier.fillMaxWidth(), + label = { Text("空间名称") }, singleLine = true) + }, + confirmButton = { + TextButton(onClick = { + showCreateSpace = false + model.createSpace(name) + }, enabled = name.isNotBlank()) { Text("创建") } + }, + dismissButton = { TextButton(onClick = { showCreateSpace = false }) { Text("取消") } }, + ) + } +} + +@Composable +private fun Detail(state: AtlasState, model: AtlasViewModel, modifier: Modifier) { + Form(modifier) { + Status(state) + val item = state.selected ?: return@Form + Text(item.name, style = MaterialTheme.typography.headlineMedium) + DetailLine("位置", item.displayPlace()) + DetailLine("数量", item.quantity.toString()) + if (item.aliases.isNotEmpty()) DetailLine("别名", item.aliases.joinToString("、")) + if (item.notes.isNotBlank()) DetailLine("备注", item.notes) + if (state.space?.writable == true) { + OutlinedButton(onClick = model::startMove, enabled = !state.busy) { Text("移动物品") } + } + } +} + +@Composable +private fun DetailLine(label: String, value: String) { + Column(Modifier.fillMaxWidth().padding(vertical = 4.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) { + Text(label, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurfaceVariant) + Text(value, style = MaterialTheme.typography.bodyLarge) + } +} + +@Composable +private fun AddItem(state: AtlasState, model: AtlasViewModel, modifier: Modifier) { + var title by rememberSaveable { mutableStateOf("") } + var quantity by rememberSaveable { mutableStateOf("1") } + var aliases by rememberSaveable { mutableStateOf("") } + var notes by rememberSaveable { mutableStateOf("") } + var placeId by rememberSaveable { mutableStateOf(null) } + val place = state.places.firstOrNull { it.id == placeId } + Form(modifier) { + OutlinedTextField(title, { title = it.take(150) }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("名称") }, singleLine = true) + OutlinedTextField(quantity, { quantity = it.filter(Char::isDigit).take(4) }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("数量") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)) + PlacePicker(state.places, place?.path ?: "未设置位置", !state.busy) { placeId = it?.id } + OutlinedTextField(aliases, { aliases = it }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("别名,可用逗号分隔") }) + OutlinedTextField(notes, { notes = it.take(1500) }, Modifier.fillMaxWidth(), enabled = !state.busy, + label = { Text("备注") }, minLines = 2) + Status(state) + Button(onClick = { model.create(title, quantity, place, aliases, notes) }, + enabled = title.isNotBlank() && !state.busy && (placeId == null || place != null), + modifier = Modifier.fillMaxWidth()) { Text("保存物品") } + } +} + +@Composable +private fun MoveItem(state: AtlasState, model: AtlasViewModel, modifier: Modifier) { + val item = state.selected ?: return + var placeId by rememberSaveable(item.id) { mutableStateOf(item.locationId) } + val place = state.places.firstOrNull { it.id == placeId } + Form(modifier) { + Text(item.name, style = MaterialTheme.typography.titleLarge) + DetailLine("当前位置", item.displayPlace()) + val pickedLabel = place?.path ?: if (placeId == item.locationId) item.displayPlace() else "未设置位置" + PlacePicker(state.places, pickedLabel, !state.busy) { placeId = it?.id } + Status(state) + Button( + onClick = { model.move(place) }, + enabled = !state.busy && placeId != item.locationId && (placeId == null || place != null), + modifier = Modifier.fillMaxWidth(), + ) { Text("确认移位") } + } +} + +@Composable +private fun PlacePicker(places: List, label: String, enabled: Boolean, onSelect: (Place?) -> Unit) { + var showPicker by remember { mutableStateOf(false) } + OutlinedButton(onClick = { showPicker = true }, enabled = enabled, modifier = Modifier.fillMaxWidth()) { + Text(label) + } + if (showPicker) { + AlertDialog( + onDismissRequest = { showPicker = false }, + title = { Text("选择存放位置") }, + text = { + LazyColumn { + item { + PlaceOption("未设置位置") { + onSelect(null) + showPicker = false + } + } + items(places.sortedBy(Place::path), key = Place::id) { place -> + PlaceOption(place.path) { + onSelect(place) + showPicker = false + } + } + } + }, + confirmButton = { TextButton(onClick = { showPicker = false }) { Text("取消") } }, + ) + } +} + +@Composable +private fun PlaceOption(label: String, pick: () -> Unit) { + Text(label, Modifier.fillMaxWidth().clickable(onClick = pick).padding(vertical = 12.dp)) +} + +@Composable +private fun Status(state: AtlasState) { + if (state.busy) LinearProgressIndicator(Modifier.fillMaxWidth()) + state.error?.let { Text(it, color = MaterialTheme.colorScheme.error) } +} + +@Composable +private fun Form(modifier: Modifier, content: @Composable ColumnScope.() -> Unit) { + Column(modifier.fillMaxWidth().verticalScroll(rememberScrollState()).padding(horizontal = 24.dp, vertical = 18.dp), + verticalArrangement = Arrangement.spacedBy(12.dp), content = content) +} + +private fun Item.displayPlace() = locationPath.ifBlank { "未设置位置" } diff --git a/apps/android/app/src/main/res/drawable-nodpi/brand.png b/apps/android/app/src/main/res/drawable-nodpi/brand.png new file mode 100644 index 0000000..bf8baec Binary files /dev/null and b/apps/android/app/src/main/res/drawable-nodpi/brand.png differ diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..9e6b473 --- /dev/null +++ b/apps/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + 见物 + diff --git a/apps/android/app/src/main/res/values/styles.xml b/apps/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..62054c3 --- /dev/null +++ b/apps/android/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + diff --git a/apps/android/build.gradle.kts b/apps/android/build.gradle.kts new file mode 100644 index 0000000..eb06e70 --- /dev/null +++ b/apps/android/build.gradle.kts @@ -0,0 +1,6 @@ +plugins { + id("com.android.application") version "8.9.2" apply false + kotlin("android") version "2.1.21" apply false + id("org.jetbrains.kotlin.plugin.compose") version "2.1.21" apply false + kotlin("plugin.serialization") version "2.1.21" apply false +} diff --git a/apps/android/gradle.properties b/apps/android/gradle.properties new file mode 100644 index 0000000..97f494e --- /dev/null +++ b/apps/android/gradle.properties @@ -0,0 +1,3 @@ +android.useAndroidX=true +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +kotlin.code.style=official diff --git a/apps/android/gradle/wrapper/gradle-wrapper.jar b/apps/android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/apps/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/apps/android/gradle/wrapper/gradle-wrapper.properties b/apps/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..eb1a55b --- /dev/null +++ b/apps/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,8 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionSha256Sum=f397b287023acdba1e9f6fc5ea72d22dd63669d59ed4a289a29b1a76eee151c6 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/apps/android/gradlew b/apps/android/gradlew new file mode 100755 index 0000000..f5feea6 --- /dev/null +++ b/apps/android/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/apps/android/gradlew.bat b/apps/android/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/apps/android/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/apps/android/settings.gradle.kts b/apps/android/settings.gradle.kts new file mode 100644 index 0000000..b69945e --- /dev/null +++ b/apps/android/settings.gradle.kts @@ -0,0 +1,18 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "ItemAtlas" +include(":app") diff --git a/docs/architecture/clients.md b/docs/architecture/clients.md index 32409ec..bb9ef8c 100644 --- a/docs/architecture/clients.md +++ b/docs/architecture/clients.md @@ -6,13 +6,13 @@ | --- | --- | --- | | H5 | uni-app(Vue 3、TypeScript、Vite),使用 DCloud 的 CLI 模板 | [移动网页](../../apps/h5/README.md)面向手机找物、照片裁剪和快速录入。构建 H5 静态文件,由独立 Nginx 镜像托管。 | | PC 网页 | Vue 3、TypeScript、Vite、Vue Router | [桌面工作台](../../apps/pc/README.md)支持搜索、物品录入、移位和两级平面图。独立 Nginx 镜像。 | -| 管理后台 | Vue 3、TypeScript、Vite、Element Plus | 已有空间查询、删除及图片清理入口。独立 Nginx 镜像。其他管理模块有多页路由需求时接入 Vue Router。 | +| 管理后台 | Vue 3、TypeScript、Vite、Element Plus | [管理后台](../../apps/admin/README.md)支持按名称或 ID 查空间、分页浏览、删除及图片清理。独立 Nginx 镜像。其他管理模块有多页路由需求时接入 Vue Router。 | | iOS | Swift、SwiftUI,最低 iOS 17 | [iOS 应用](../../apps/ios/README.md)接入账号、空间、物品、草稿和相册上传。拍照和录音按后续原生端验收范围补齐。 | -| Android | Kotlin、Jetpack Compose | Gradle 工程。相机、录音走 Android 平台能力,使用同一 HTTPS API。 | +| Android | Kotlin、Jetpack Compose | [Android 应用](../../apps/android/README.md)使用 Gradle,最低 Android 8.0。首版接入原生会话、空间、找物、录入和移位。 | H5 选 uni-app 是为了用贴合移动端的组件和构建方式。正式交付范围只包含网页。微信小程序本期不列入需求、目录或构建目标。PC 和后台要处理高密度列表、桌面键盘交互以及表单,用标准 Vue 网页工程。Web 各端共享合适的 API 类型、校验和文案,H5 的 uni-app 组件单独维护。 [uni-app CLI](https://uniapp.dcloud.net.cn/worktile/CLI.html) · [uni-app Vue 3 TypeScript 模板](https://uniapp.dcloud.net.cn/quickstart-cli.html) · [Vue TypeScript](https://vuejs.org/guide/typescript/overview) · [Vue Router](https://router.vuejs.org/) · [Element Plus](https://element-plus.org/en-US/guide/quickstart) -三个 Web 站点在自己的域名下通过 `/api` 访问网关,原生端连接 `https://api-atlas.tutudog.com`。家庭权限由后端校验,后台接口另验管理角色。模型尚未配置时界面显示状态,凭证从服务环境读取。 +Web 站点使用同源 `/api` 访问网关,原生端连接 `https://api-atlas.tutudog.com`。家庭权限由后端校验,后台接口另验管理角色。模型尚未配置时界面显示状态,凭证从服务环境读取。 各端按自己的导航、拍照、录音及权限规范单独设计。iOS 在 SwiftUI 内提交账号密码,服务端按账号编号核对空间成员。Web 管理后台使用 Keycloak。签名和商店发布在准备分发时配置。 [SwiftUI](https://developer.apple.com/swiftui/) · [Jetpack Compose](https://developer.android.com/compose)