Package 

Class MavericksExtensionsKt

    • Method Detail

      • 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.

      • 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]