项目作者: aprofromindia

项目描述 :
Android MVVM framework helper library.
高级语言: Java
项目地址: git://github.com/aprofromindia/android-mvvm.git
创建时间: 2017-03-03T20:56:41Z
项目社区:https://github.com/aprofromindia/android-mvvm

开源协议:

下载


Android MVVM

Intro

If you are not yet sold on Android Data Binding please click here. Once you start using Android data binding its imperative that you design your apps using the MVVM architecture.

This is where Android MVVM can be helpful. Just extend from our VMActivity / VMFragment and forget about Android Configuration changes. Its all taken care of for you… so just MVVM….

Usage

  • Your Activities should extend the VMActivity<T> class.
  • Your Fragments should extend the VMFragment<T> class.
  • Provide your ViewModel using the T provideViewModel() method.
  • If you don’t want your viewModel to be persisted across Android configuration change set the boolean saveOnConfigChange to false (default - true).
  • Now your viewModel variable should be ready for use; in most cases you would set it to your layout binding class.

Sample Code

  1. public class MainActivity extends VMActivity<MainViewModel> {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. ActivityMainBinding binding = DataBindingUtil
  6. .setContentView(this, R.layout.activity_main);
  7. binding.setViewModel(viewModel);
  8. }
  9. @NonNull
  10. @Override
  11. public MainViewModel provideViewModel() {
  12. return new MainViewModel(VenueRepository.getInstance());
  13. }
  14. }

Download

  1. allprojects {
  2. repositories {
  3. jcenter()
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

and:

  1. dependencies {
  2. compile 'com.github.aprofromindia:android-mvvm:{latest-version}'
  3. }

Latest Version - Release

Note: do not add the jitpack.io repository under buildscript.

Licenses

Released under the Apache 2.0 license.