EAS - Sayurbox App
🥬 SayurBox App - Aplikasi Belanja Sayur Online
SayurBox adalah aplikasi mobile e-commerce yang memfokuskan pada penjualan sayur-sayuran dan produk segar secara online. Aplikasi ini menyediakan platform yang mudah digunakan untuk berbelanja kebutuhan sayur-mayur dengan fitur lengkap seperti katalog produk, keranjang belanja, sistem favorit, dan manajemen pesanan yang terintegrasi.
class AuthViewModel : ViewModel() { private val _authState = MutableStateFlow(AuthState()) val authState: StateFlow<AuthState> = _authState.asStateFlow() fun signUp(email: String, password: String, name: String) { _authState.value = _authState.value.copy(isLoading = true) viewModelScope.launch { try { val user = userRepository.createUser( email = email, password = password, fullName = name ) _authState.value = _authState.value.copy( isLoading = false, user = user, isAuthenticated = true ) } catch (e: Exception) { _authState.value = _authState.value.copy( isLoading = false, errorMessage = e.message ) } } } }
🔐 Authentication System
AuthViewModel mengelola proses sign up dan sign in dengan validasi email, password, no telp dan nama lengkap. Menggunakan Repository pattern untuk abstraksi data layer dan error handling.
data class Product( val id: String, val name: String, val description: String, val price: Double, val imageUrl: String, val category: ProductCategory, val stock: Int, val isFavorite: Boolean = false ) class ProductViewModel : ViewModel() { private val _products = MutableStateFlow<List<Product>>(emptyList()) val products: StateFlow<List<Product>> = _products.asStateFlow() private val _searchQuery = MutableStateFlow("") val searchQuery: StateFlow<String> = _searchQuery.asStateFlow() val filteredProducts = combine(products, searchQuery) { products, query -> if (query.isBlank()) { products } else { products.filter { it.name.contains(query, ignoreCase = true) || it.description.contains(query, ignoreCase = true) } } }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5000), initialValue = emptyList() ) }
🛍️ Product Management
Product data class mendefinisikan struktur produk sayur dengan informasi lengkap. ViewModel menggunakan combine() untuk reactive search filtering dan StateIn untuk efficient state sharing.
data class CartItem( val product: Product, val quantity: Int ) class CartViewModel : ViewModel() { private val _cartItems = MutableStateFlow<List<CartItem>>(emptyList()) val cartItems: StateFlow<List<CartItem>> = _cartItems.asStateFlow() val totalPrice = cartItems.map { items -> items.sumOf { it.product.price * it.quantity } }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5000), initialValue = 0.0 ) fun addToCart(product: Product, quantity: Int = 1) { val currentItems = _cartItems.value.toMutableList() val existingItemIndex = currentItems.indexOfFirst { it.product.id == product.id } if (existingItemIndex >= 0) { currentItems[existingItemIndex] = currentItems[existingItemIndex].copy( quantity = currentItems[existingItemIndex].quantity + quantity ) } else { currentItems.add(CartItem(product, quantity)) } _cartItems.value = currentItems } }
🛒 Shopping Cart
CartViewModel mengelola item di keranjang dengan automatic total calculation. Logic addToCart() menangani penambahan item baru atau update quantity untuk item yang sudah ada di cart.
class FavoriteViewModel : ViewModel() { private val _favoriteProducts = MutableStateFlow<Set<String>>(emptySet()) val favoriteProducts: StateFlow<Set<String>> = _favoriteProducts.asStateFlow() fun toggleFavorite(productId: String) { val currentFavorites = _favoriteProducts.value.toMutableSet() if (currentFavorites.contains(productId)) { currentFavorites.remove(productId) } else { currentFavorites.add(productId) } _favoriteProducts.value = currentFavorites // Save to local storage viewModelScope.launch { favoriteRepository.saveFavorites(currentFavorites.toList()) } } fun isFavorite(productId: String): Boolean { return _favoriteProducts.value.contains(productId) } }
❤️ Favorite System
FavoriteViewModel menggunakan Set untuk efficient lookup dan toggle operations. Data favorit disimpan ke local storage untuk persistence across app sessions.
data class Order( val id: String, val items: List<CartItem>, val totalAmount: Double, val orderDate: Long, val status: OrderStatus, val deliveryAddress: String ) enum class OrderStatus { PENDING, CONFIRMED, PROCESSING, SHIPPED, DELIVERED, CANCELLED } class OrderViewModel : ViewModel() { private val _orders = MutableStateFlow<List<Order>>(emptyList()) val orders: StateFlow<List<Order>> = _orders.asStateFlow() fun createOrder(cartItems: List<CartItem>, deliveryAddress: String) { val order = Order( id = generateOrderId(), items = cartItems, totalAmount = cartItems.sumOf { it.product.price * it.quantity }, orderDate = System.currentTimeMillis(), status = OrderStatus.PENDING, deliveryAddress = deliveryAddress ) viewModelScope.launch { orderRepository.createOrder(order) loadOrders() } } }
📦 Order Management
Order system dengan status tracking lengkap dari pending hingga delivered. ViewModel mengelola order creation, status updates, dan order history dengan data persistence.
@Composable fun SearchBar( query: String, onQueryChange: (String) -> Unit, modifier: Modifier = Modifier ) { OutlinedTextField( value = query, onValueChange = onQueryChange, modifier = modifier.fillMaxWidth(), placeholder = { Text("Cari sayur-sayuran...") }, leadingIcon = { Icon( imageVector = Icons.Default.Search, contentDescription = "Search", tint = Color(0xFF22c55e) ) }, trailingIcon = { if (query.isNotEmpty()) { IconButton(onClick = { onQueryChange("") }) { Icon( imageVector = Icons.Default.Clear, contentDescription = "Clear" ) } } }, shape = RoundedCornerShape(12.dp), colors = OutlinedTextFieldDefaults.colors( focusedBorderColor = Color(0xFF4caf50), unfocusedBorderColor = Color(0xFF81c784) ) ) }
🔍 Search Functionality
SearchBar component dengan real-time filtering. Menggunakan Material Design principles dengan custom SayurBox green colors dan user-friendly interactions.
Core Features
- User Authentication (Sign Up & Sign In)
- Product Catalog dengan kategori
- Shopping Cart management
- Favorite products system
- Order tracking & history
- Real-time product search
Technical Stack
- Jetpack Compose UI
- ViewModel & StateFlow
- Repository Pattern
- Local Data Storage
- Reactive Programming
- Material Design 3
-
1. Authentication SystemSistem registrasi dan login yang aman dengan validasi email, no telp, dan password
-
2. Product CatalogKatalog produk sayur-sayuran dengan kategorisasi dan deskripsi detail produk
-
3. Shopping CartKeranjang belanja dengan automatic price calculation
-
4. Favorite ProductsSistem wishlist untuk menyimpan produk favorit pengguna dengan quick access dan easy management untuk pembelian di masa depan.
-
5. Order ManagementSistem pemesanan lengkap dengan order tracking, status updates, dan order history
-
6. Search FunctionalityPencarian produk untuk menemukan produk dengan cepat.
Secure sign up & sign in system
Fruits and vegetables product list
Smart cart management system
Personal product wishlist
Order tracking and history
Product discovery
📂 Access Source Code
🔗 View on GitHubComplete source code untuk SayurBox App dengan fitur e-commerce lengkap
Comments
Post a Comment