This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalCoilApi::class) | |
@SuppressLint("UnusedMaterialScaffoldPaddingParameter") | |
@Composable | |
fun ProductDetailsScreen( | |
modifier: Modifier = Modifier, | |
viewModel: ProductDetailsViewModel = hiltViewModel(), | |
navController: NavController, | |
productId: String?, | |
) { | |
val snackBarHostState = remember { SnackbarHostState() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class ProductDetailsViewModel @Inject constructor( | |
private val productRepository: ProductRepository, | |
savedStateHandle: SavedStateHandle, | |
) : ViewModel() { | |
private val _product = MutableStateFlow<Product?>(null) | |
val product: Flow<Product?> = _product | |
private val _name = MutableStateFlow("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterialApi::class) | |
@Composable | |
fun ProductListScreen( | |
modifier: Modifier = Modifier, | |
navController: NavController, | |
viewModel: ProductListViewModel = hiltViewModel(), | |
) { | |
val isLoading by viewModel.isLoading.collectAsState(initial = false) | |
val swipeRefreshState = rememberSwipeRefreshState(isRefreshing = isLoading) | |
SwipeRefresh(state = swipeRefreshState, onRefresh = { viewModel.getProducts() }) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class ProductListViewModel @Inject constructor( | |
private val productRepository: ProductRepository, | |
) : ViewModel() { | |
private val _productList = MutableStateFlow<List<Product>?>(listOf()) | |
val productList: Flow<List<Product>?> = _productList | |
private val _isLoading = MutableStateFlow(false) | |
val isLoading: Flow<Boolean> = _isLoading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface AuthenticationRepository { | |
suspend fun signIn(email: String, password: String): Boolean | |
suspend fun signUp(email: String, password: String): Boolean | |
suspend fun signInWithGoogle(): Boolean | |
} | |
class AuthenticationRepositoryImpl @Inject constructor( | |
private val goTrue: GoTrue | |
) : AuthenticationRepository { | |
override suspend fun signIn(email: String, password: String): Boolean { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ProductRepository { | |
suspend fun createProduct(product: Product): Boolean | |
suspend fun getProducts(): List<ProductDto>? | |
suspend fun getProduct(id: String): ProductDto | |
suspend fun deleteProduct(id: String) | |
suspend fun updateProduct( | |
id: String, name: String, price: Double, imageName: String, imageFile: ByteArray | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Product( | |
val id: String, | |
val name: String, | |
val price: Double, | |
val image: String? | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Serializable | |
data class ProductDto( | |
@SerialName("name") | |
val name: String, | |
@SerialName("price") | |
val price: Double, | |
@SerialName("image") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@InstallIn(SingletonComponent::class) | |
@Module | |
object SupabaseModule { | |
@Provides | |
@Singleton | |
fun provideSupabaseClient(): SupabaseClient { | |
return createSupabaseClient( | |
supabaseUrl = BuildConfig.SUPABASE_URL, | |
supabaseKey = BuildConfig.SUPABASE_ANON_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation "com.google.dagger:hilt-android:$hilt_version" | |
annotationProcessor "com.google.dagger:hilt-compiler:$hilt_version" | |
implementation "androidx.hilt:hilt-navigation-compose:1.0.0" |