Last active
June 9, 2020 20:24
-
-
Save Zhuinden/6b5ce666a2d900c816f642001cb00a7e to your computer and use it in GitHub Desktop.
Single-Activity: Create Login Credentials (Jetpack Navigation)
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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/root" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.fragment.app.FragmentContainerView | |
android:id="@+id/nav_host" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:defaultNavHost="true" | |
app:navGraph="@navigation/navigation"/> | |
</FrameLayout> |
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 CreateLoginCredentialsFragment : Fragment(R.layout.create_login_credentials_fragment) { | |
private val viewModel by navGraphSavedStateViewModels(R.id.registration_graph) { handle -> // ViewModelUtils.kt | |
Injector.get().registrationViewModelFactory().create(handle) // Dagger + AssistedInject | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val binding = CreateLoginCredentialsFragmentBinding.bind(view) | |
// ... |
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 | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment