Skip to content

Repository files navigation

Mobi Lab

Mobi Lab MVVM

Mobi Lab MVVM library (mvvm-android) is a library for using the MVVM architecture in your Android application.

Adding the library to a project

Maven Central artifact available from https://central.sonatype.com/search?q=mobi.lab.mvvm

implementation 'mobi.lab.mvvm:mvvm:x.y.z'// Check the latest version from Maven Central

Library contents

The library the following elements:

  1. MvvmLiveDataExtensions interface, MvvmExtensions extensions, and SingleEvent class. These provide convenience methods for handling LiveData contents and SingleEvent is used to handle actions only once.

Creating ViewModels

ViewModels can be easily created by Kotlin extensions provided by "androidx.fragment:fragment-ktx:<version" dependency.

Activity

classMyActivity : AppCompatActivity, MvvmLiveDataExtensions {
// No factoryprivateval viewModel:MainViewModel by viewModels()
// Custom factoryprivateval viewModel:MainViewModel by viewModels { myFactory }
}

Fragment

classMyFragment : Fragment, MvvmLiveDataExtensions {
// No factoryprivateval viewModel:MainViewModel by viewModels()
// Custom factoryprivateval viewModel:MainViewModel by viewModels { myFactory }
// Activity context ViewModelprivateval viewModel:MainViewModel by activityViewModels { myFactory }
// MvvmLiveDataExtensions provides helpful extensions when working with LiveData and Event classesoverridefungetLifecycleOwner(): LifecycleOwner=this// Custom ViewModel instantiation with Mvvm's createViewModel() functionprivateval viewModel:MainViewModel by lazy { ViewModelProvider(this, factory).get(MainViewModel::class.java) }
}

About

A library for using the MVVM architecture in your Android application

Resources

Security policy

Stars

0 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages