MVVM Light Toolkit

Additional

Language
Java
Version
N/A
Created
Jun 2, 2016
Updated
Mar 30, 2017 (Retired)
Owner
KelinHong (Kelin-Hong)
Contributor
KelinHong (Kelin-Hong)
1
Activity
Badge
Generate
Download
Source code
APK file

Commercial

requires at least android gradle plugin 1.5.0.

##Usage##

####中文文档:MVVM Light Toolkit使用指南#### ####引申阅读:如何构建Android MVVM应用程序####

###Data Binding###

Binding URI to the ImageView with bind:uri will make it loading bitmap from URI and render to ImageView automatically.

<ImageView
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignParentRight="true"
  bind:uri="@{viewModel.imageUrl}"
  bind:placeholderImageRes="@{R.drawable.ic_launcher}"/>

Fresco.initialize(this) is require,because of loading image use Fresco default).

  public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Fresco.initialize(this);
   }

Example

AdapterView like ListView、RecyclerView 、ViewPager is convenient, bind it to the collection view with app:items and app:itemView,You should use an ObservableList to automatically update your view based on list changes.

 <android.support.v7.widget.RecyclerView android:layout_width="match_parent"android:layout_height="match_parent"bind:itemView="@{viewModel.itemView}"bind:items="@{viewModel.itemViewModel}"bind:layoutManager="@{LayoutManagers.linear()}"

In ViewModel define itemViewModel and itemView

publicfinalObservableList<ViewModel> itemViewModel =newObservableArrayList<>(); publicfinalItemView itemView =ItemView.of(BR.viewModel, R.layout.layoutitem_list_view);

Adapter,ViewHolder ..is Not Required:

Example

Other attributes supported:

ImageView<attrname="uri" /> <!--width for ResizeOptions (use Fresco to load bitmap). --> <attrname="request_width"format="integer" /> <!--height for ResizeOptions (use Fresco to load bitmap). --> <attrname="request_height"format="integer" /> <attrname="placeholderImageRes"format="reference|color" />
  • ListView、ViewPager、RecyclerView<!-- require ItemView or ItemViewSelector --> <attrname="itemView" /> <!-- require List<ViewModel> bind to ItemView to presentation.--> <attrname="items" /> <!-- require a adapter which type of BindingRecyclerViewAdapter<T> to AdapterView--> <attrname="adapter" /> <attrname="dropDownItemView"format="reference" /> <attrname="itemIds"format="reference" /> <attrname="itemIsEnabled"format="reference" /> <!-- require PageTitles<T>--> <attrname="pageTitles"format="reference" />
  • ViewGroup<!-- require ItemView or ItemViewSelector --> <attrname="itemView" /> <!-- require List<ViewModel> bind to ItemView to presentation.--> <attrname="viewModels"format="reference" />
  • EditText<!-- require boolean value to decide whether requestFocus for view. --> <attrname="requestFocus"format="boolean" />
  • SimpleDraweeView<!-- require String to load Image"--> <attrname="uri" />
  • WebView<!-- require String render to html show in webview--> <attrname="render"format="string" />