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
@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
@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 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(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
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") | |
@OptIn(ExperimentalMaterial3Api::class) | |
@Composable | |
fun AddProductScreen( | |
modifier: Modifier = Modifier, | |
navController: NavController, | |
viewModel: AddProductViewModel = hiltViewModel(), | |
) { | |
Scaffold( | |
topBar = { |
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 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 |
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 SignUpViewModel @Inject constructor( | |
private val authenticationRepository: AuthenticationRepository | |
) : ViewModel() { | |
private val _email = MutableStateFlow("") | |
val email: Flow<String> = _email | |
private val _password = MutableStateFlow("") | |
val password = _password |
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
@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) }, |
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 SignInViewModel @Inject constructor( | |
private val authenticationRepository: AuthenticationRepository | |
) : ViewModel() { | |
private val _email = MutableStateFlow("") | |
val email: Flow<String> = _email | |
private val _password = MutableStateFlow("") | |
val password = _password |