Skip to content

Instantly share code, notes, and snippets.

View hieuwu's full-sized avatar
🌞
Free

Hieu Vu hieuwu

🌞
Free
View GitHub Profile
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 {
@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
@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() }) {
@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("")
@OptIn(ExperimentalCoilApi::class)
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
fun ProductDetailsScreen(
modifier: Modifier = Modifier,
viewModel: ProductDetailsViewModel = hiltViewModel(),
navController: NavController,
productId: String?,
) {
val snackBarHostState = remember { SnackbarHostState() }
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddProductScreen(
modifier: Modifier = Modifier,
navController: NavController,
viewModel: AddProductViewModel = hiltViewModel(),
) {
Scaffold(
topBar = {
@HiltViewModel
class AddProductViewModel @Inject constructor(
private val productRepository: ProductRepository,
) : ViewModel() {
private val _isLoading = MutableStateFlow(false)
val isLoading: Flow<Boolean> = _isLoading
private val _showSuccessMessage = MutableStateFlow(false)
val showSuccessMessage: Flow<Boolean> = _showSuccessMessage
@HiltViewModel
class SignUpViewModel @Inject constructor(
private val authenticationRepository: AuthenticationRepository
) : ViewModel() {
private val _email = MutableStateFlow("")
val email: Flow<String> = _email
private val _password = MutableStateFlow("")
val password = _password
@Composable
fun SignUpScreen(
modifier: Modifier = Modifier,
navController: NavController,
viewModel: SignUpViewModel = hiltViewModel()
) {
val snackBarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
Scaffold(
snackbarHost = { androidx.compose.material.SnackbarHost(snackBarHostState) },
@HiltViewModel
class SignInViewModel @Inject constructor(
private val authenticationRepository: AuthenticationRepository
) : ViewModel() {
private val _email = MutableStateFlow("")
val email: Flow<String> = _email
private val _password = MutableStateFlow("")
val password = _password