Last active
May 21, 2020 04:02
-
-
Save Zhuinden/d76565909387200f68e202084bd8ee20 to your computer and use it in GitHub Desktop.
Using EventEmitter to move Navigation commands into ViewModels
This file contains hidden or 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
class RegistrationViewModel @AssistedInject constructor( | |
private val authenticationManager: AuthenticationManager, | |
@Assisted private val savedStateHandle: SavedStateHandle | |
) : ViewModel() { | |
@AssistedInject.Factory | |
interface Factory { | |
fun create(savedStateHandle: SavedStateHandle): RegistrationViewModel | |
} | |
private val navigationEmitter: EventEmitter<NavigationCommand> = EventEmitter() | |
val navigationCommands: EventSource<NavigationCommand> get() = navigationEmitter | |
fun onEnterProfileNextClicked() { | |
if (fullName.value!!.isNotBlank() && bio.value!!.isNotBlank()) { | |
currentState.value = RegistrationState.COLLECT_USER_PASSWORD | |
navigationEmitter.emit { navController, context -> | |
navController.navigate(R.id.enter_profile_data_to_create_login_credentials) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment