initial import from openclaw workspace
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled

This commit is contained in:
xiaobai committed 2026-03-04 13:45:32 +08:00
commit 27d0d57b56
59 files changed
+2666

No files matched your search

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity
android:exported="true"
android:windowSoftInputMode="adjustResize"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,320 @@
package com.example.minishop
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
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.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.minishop.cart.CartState
import com.example.minishop.cart.CartStore
import com.example.minishop.data.FakeProductRepository
import com.example.minishop.data.FavoriteStore
import com.example.minishop.model.Product
private enum class Tab { Home, Favorites, Cart }
@Composable
fun App() {
MaterialTheme {
val repo = remember { FakeProductRepository() }
val cartStore = remember { CartStore() }
val favoriteStore = remember { FavoriteStore() }
var currentTab by remember { mutableStateOf(Tab.Home) }
var selected by remember { mutableStateOf<Product?>(null) }
var inDetail by remember { mutableStateOf(false) }
var tick by remember { mutableStateOf(0) }
var query by remember { mutableStateOf("") }
val allProducts = remember { repo.getProducts() }
val products = remember(query, tick) {
allProducts.filter {
it.title.contains(query, ignoreCase = true) ||
it.description.contains(query, ignoreCase = true)
}
}
val favorites = remember(tick) { favoriteStore.all() }
val cartState = remember(tick) { cartStore.state() }
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
when {
inDetail -> "商品详情"
currentTab == Tab.Home -> "Mini Shopping"
currentTab == Tab.Favorites -> "收藏夹"
else -> "购物车"
}
)
},
actions = {
if (inDetail) {
TextButton(onClick = { inDetail = false }) { Text("返回") }
}
}
)
},
bottomBar = {
if (!inDetail) {
NavigationBar {
NavigationBarItem(
selected = currentTab == Tab.Home,
onClick = { currentTab = Tab.Home },
icon = { Text("🏠") },
label = { Text("首页") }
)
NavigationBarItem(
selected = currentTab == Tab.Favorites,
onClick = { currentTab = Tab.Favorites },
icon = { Text("❤️") },
label = { Text("收藏(${favorites.size})") }
)
NavigationBarItem(
selected = currentTab == Tab.Cart,
onClick = { currentTab = Tab.Cart },
icon = { Text("🛒") },
label = { Text("购物车(${cartState.totalCount})") }
)
}
}
}
) { padding ->
Box(Modifier.padding(padding).fillMaxSize()) {
when {
inDetail -> ProductDetailScreen(
product = selected,
isFavorite = selected?.let { favoriteStore.isFavorite(it.id) } == true,
onBack = { inDetail = false },
onToggleFavorite = {
selected?.let {
favoriteStore.toggle(it.id)
tick++
}
},
onAdd = {
cartStore.add(it)
tick++
}
)
currentTab == Tab.Home -> ProductListScreen(
products = products,
query = query,
onQueryChange = { query = it },
isFavorite = { favoriteStore.isFavorite(it) },
quantityOf = { cartState.quantityOf(it) },
onToggleFavorite = { id ->
favoriteStore.toggle(id)
tick++
},
onClick = {
selected = it
inDetail = true
}
)
currentTab == Tab.Favorites -> FavoriteScreen(
products = allProducts.filter { favoriteStore.isFavorite(it.id) },
quantityOf = { cartState.quantityOf(it) },
onOpen = {
selected = it
inDetail = true
},
onAdd = {
cartStore.add(it)
tick++
}
)
else -> CartScreen(
cartState = cartState,
onInc = { id -> cartStore.increase(id); tick++ },
onDec = { id -> cartStore.decrease(id); tick++ },
onRemove = { id -> cartStore.remove(id); tick++ },
onClear = { cartStore.clear(); tick++ }
)
}
}
}
}
}
@Composable
private fun ProductListScreen(
products: List<Product>,
query: String,
onQueryChange: (String) -> Unit,
isFavorite: (String) -> Boolean,
quantityOf: (String) -> Int,
onToggleFavorite: (String) -> Unit,
onClick: (Product) -> Unit
) {
Column(Modifier.fillMaxSize().padding(12.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = query,
onValueChange = onQueryChange,
singleLine = true,
label = { Text("搜索课程") },
placeholder = { Text("输入标题或描述") }
)
if (products.isEmpty()) {
EmptyState("没有匹配的商品")
} else {
LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(products) { p ->
ElevatedCard(onClick = { onClick(p) }, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Text(p.title, style = MaterialTheme.typography.titleMedium)
Text("¥${formatPrice(p.price)}")
}
Text(p.description, style = MaterialTheme.typography.bodySmall)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OutlinedButton(onClick = { onToggleFavorite(p.id) }) {
Text(if (isFavorite(p.id)) "已收藏" else "收藏")
}
val q = quantityOf(p.id)
if (q > 0) Text("已加购 x$q", style = MaterialTheme.typography.bodySmall)
}
}
}
}
}
}
}
}
@Composable
private fun ProductDetailScreen(
product: Product?,
isFavorite: Boolean,
onBack: () -> Unit,
onToggleFavorite: () -> Unit,
onAdd: (Product) -> Unit
) {
if (product == null) {
EmptyState("商品不存在")
return
}
Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text(product.title, style = MaterialTheme.typography.headlineSmall)
Text("价格:¥${formatPrice(product.price)}")
Text(product.description)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(onClick = onBack) { Text("返回") }
Button(onClick = { onAdd(product) }) { Text("加入购物车") }
OutlinedButton(onClick = onToggleFavorite) {
Text(if (isFavorite) "取消收藏" else "收藏")
}
}
}
}
@Composable
private fun CartScreen(
cartState: CartState,
onInc: (String) -> Unit,
onDec: (String) -> Unit,
onRemove: (String) -> Unit,
onClear: () -> Unit
) {
Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
if (cartState.items.isNotEmpty()) {
OutlinedButton(onClick = onClear) { Text("清空购物车") }
}
if (cartState.items.isEmpty()) {
EmptyState("购物车为空")
} else {
LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(cartState.items) { item ->
Card(Modifier.fillMaxWidth()) {
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
Text(item.product.title)
Text("¥${formatPrice(item.product.price * item.quantity)}")
}
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
OutlinedButton(onClick = { onDec(item.product.id) }) { Text("-") }
Text("数量 ${item.quantity}")
OutlinedButton(onClick = { onInc(item.product.id) }) { Text("+") }
OutlinedButton(onClick = { onRemove(item.product.id) }) { Text("移除") }
}
}
}
}
}
Text("总件数:${cartState.totalCount}")
Text("合计:¥${formatPrice(cartState.totalPrice)}", style = MaterialTheme.typography.titleMedium)
}
}
}
@Composable
private fun FavoriteScreen(
products: List<Product>,
quantityOf: (String) -> Int,
onOpen: (Product) -> Unit,
onAdd: (Product) -> Unit
) {
if (products.isEmpty()) {
EmptyState("你还没有收藏课程")
} else {
LazyColumn(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(products) { p ->
ElevatedCard(onClick = { onOpen(p) }, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text(p.title, style = MaterialTheme.typography.titleMedium)
Text("¥${formatPrice(p.price)}")
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(onClick = { onAdd(p) }) { Text("加入购物车") }
val q = quantityOf(p.id)
if (q > 0) Text("已加购 x$q")
}
}
}
}
}
}
}
@Composable
private fun EmptyState(text: String) {
Box(Modifier.fillMaxSize().padding(24.dp)) {
Text(text, style = MaterialTheme.typography.bodyLarge)
}
}
private fun formatPrice(price: Double): String = "%.2f".format(price)
@@ -0,0 +1,14 @@
package com.example.minishop
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
App()
}
}
}
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@@ -0,0 +1,16 @@
<resources>
<string name="app_name">Mini Shopping</string>
<string name="label_title">Title</string>
<string name="label_artist">Artist</string>
<string name="label_date">Date</string>
<string name="label_dimensions">Dimensions</string>
<string name="label_medium">Medium</string>
<string name="label_department">Department</string>
<string name="label_repository">Repository</string>
<string name="label_credits">Credits</string>
<string name="back">Back</string>
<string name="no_data_available">No data available</string>
</resources>