-
-
Save PatilShreyas/9934edf1cd121b478869b0030777bec4 to your computer and use it in GitHub Desktop.
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 UserViewModel @Inject constructor( | |
private val sessionManager: SessionManager, | |
private val userRepository: UserRepository, | |
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher // Injected by Hilt module. Used in testing | |
) : ViewModel() { | |
// ... | |
// OTHER CODE HERE | |
// ... | |
/** | |
* Creates a new user with [name] and [email] and sets active session of that created user. | |
*/ | |
fun setUserSession(name: String, email: String) { | |
viewModelScope.launch(defaultDispatcher) { | |
val user = userRepository.add(name, email) | |
sessionManager.setUserSession(user) | |
// Update LiveData/StateFlow/Rx or any other stream | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment