-
public final class MavericksExtensionsKt
-
-
Method Summary
Modifier and Type Method Description final static <T extends Fragment> Object_fragmentArgsProvider(T $self)For internal use only. final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM>fragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)Gets or creates a ViewModel scoped to this Fragment. final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM>parentFragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)Gets or creates a ViewModel scoped to a parent fragment. final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM>targetFragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)Gets or creates a ViewModel scoped to a target fragment. final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM>existingViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)activityViewModel except it will throw IllegalStateException if the ViewModel doesn't already exist. final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM>activityViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)fragmentViewModel except scoped to the current Activity. final static <T extends ComponentActivity, VM extends MavericksViewModel<S>, S extends MavericksState> Lazy<VM>viewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)Gets or creates a ViewModel scoped to the current activity. final static <V extends Any> ReadOnlyProperty<Fragment, V>args()Fragment argument delegate that makes it possible to set fragment args without creating a key for each one. final static <V extends Any> ReadOnlyProperty<Fragment, V>argsOrNull()Fragment argument delegate that makes it possible to set fragment args without creating a key for each one. final static <ERROR CLASS>asMavericksArgs(Serializable $self)Takes anything that is serializable and creates a Mavericks Fragment argument Bundle. final static <ERROR CLASS>asMavericksArgs(Parcelable $self)Takes anything that is Parcelable and creates a Mavericks Fragment argument Bundle. final static <T extends Any> <ERROR CLASS>appendAt(List<T> $self, List<T> other, Integer offset)Helper to handle pagination. -
-
Method Detail
-
_fragmentArgsProvider
final static <T extends Fragment> Object _fragmentArgsProvider(T $self)
For internal use only. Public for inline.
Looks for Mavericks.KEY_ARG on the arguments of the fragments.
-
fragmentViewModel
final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM> fragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
Gets or creates a ViewModel scoped to this Fragment. You will get the same instance every time for this Fragment, even through rotation, or other configuration changes.
If the ViewModel has additional dependencies, implement MavericksViewModelFactory in its companion object. You will be given the initial state as well as a FragmentActivity with which you can access other dependencies to pass to the ViewModel's constructor.
Mavericks will also handle persistence across process restarts. Refer to PersistState for more info.
Use keyFactory if you have multiple ViewModels of the same class in the same scope.
-
parentFragmentViewModel
final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM> parentFragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
Gets or creates a ViewModel scoped to a parent fragment. This delegate will walk up the parentFragment hierarchy until it finds a Fragment that can provide the correct ViewModel. If no parent fragments can provide the ViewModel, a new one will be created in top-most parent Fragment.
-
targetFragmentViewModel
final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM> targetFragmentViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
Gets or creates a ViewModel scoped to a target fragment. Throws IllegalStateException if there is no target fragment.
-
existingViewModel
final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM> existingViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
activityViewModel except it will throw IllegalStateException if the ViewModel doesn't already exist. Use this for screens in the middle of a flow that cannot reasonably be an entry point to the flow.
-
activityViewModel
final static <T extends Fragment, MavericksView, VM extends MavericksViewModel<S>, S extends MavericksState> MavericksDelegateProvider<T, VM> activityViewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
fragmentViewModel except scoped to the current Activity. Use this to share state between different Fragments.
-
viewModel
final static <T extends ComponentActivity, VM extends MavericksViewModel<S>, S extends MavericksState> Lazy<VM> viewModel(T $self, KClass<VM> viewModelClass, Function0<String> keyFactory)
Gets or creates a ViewModel scoped to the current activity. This is similar to fragmentViewModel and actvityViewModel but used when a view model is accessed directly from an activity itself.
-
args
final static <V extends Any> ReadOnlyProperty<Fragment, V> args()
Fragment argument delegate that makes it possible to set fragment args without creating a key for each one.
To create arguments, define a property in your fragment like:
private val listingId: MyArgs by args()Each fragment can only have a single argument with the key Mavericks.KEY_ARG
-
argsOrNull
final static <V extends Any> ReadOnlyProperty<Fragment, V> argsOrNull()
Fragment argument delegate that makes it possible to set fragment args without creating a key for each one.
To create nullable arguments, define a property in your fragment like:
private val listingId: MyArgs? by argsOrNull()Each fragment can only have a single argument with the key Mavericks.KEY_ARG
-
asMavericksArgs
final static <ERROR CLASS> asMavericksArgs(Serializable $self)
Takes anything that is serializable and creates a Mavericks Fragment argument Bundle.
Set this as your Fragment's arguments and you can use the args property delegate in your Fragment to easily retrieve it.
-
asMavericksArgs
final static <ERROR CLASS> asMavericksArgs(Parcelable $self)
Takes anything that is Parcelable and creates a Mavericks Fragment argument Bundle.
Set this as your Fragment's arguments and you can use the args property delegate in your Fragment to easily retrieve it.
-
appendAt
final static <T extends Any> <ERROR CLASS> appendAt(List<T> $self, List<T> other, Integer offset)
Helper to handle pagination. Use this when you want to append a list of results at a given offset. This is safer than just appending blindly to a list because it guarantees that the data gets added at the offset it was requested at.
This will replace all contents starting at the offset with the new list. For example: 1,2,3.appendAt(4, 1) == 1,4]
-
-
-
-