diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0fe3258 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +release +target +build +.settings +.project +.classpath +.idea +.DS_Store +bin +gen +proguard +.pmd +*~ +*.iml +tmp +gen-external-apklibs +out +tmp +MeituanUri +coverage +build/ +.gradle/ +local.properties +gradle/ +gradlew +gradlew.bat +.gradletasknamecache +keystore diff --git a/README.md b/README.md index 1c16448..0090a69 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,325 @@ -# MVVMLight -A toolkit help to build Android MVVM Application +# MVVM Light Toolkit +A toolkit help to build Android MVVM Application,We have more +attributes for Data Binding of View(like Uri for ImageView) ,we create some command for deal with event( like click of Button),also have a global message pipe to communicate with other ViewModel. +##Download## + +```groovy + compile 'com.kelin.mvvmlight:library:0.6.0' +``` + +requires at least android gradle plugin 1.5.0. + +##Usage## +--- +###Data Binding### + + +Binding URI to the ImageView with bind:uri will make it loading bitmap from URI and render to ImageView automatically. + + ```xml + + ``` + + --- + + **Example** + + ![image.gif](http://upload-images.jianshu.io/upload_images/966283-2e13447dfd5028a1.gif?imageMogr2/auto-orient/strip) + + --- + +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. + + ```xml + itemViewModel = new ObservableArrayList<>(); + public final ItemView itemView = ItemView.of(BR.viewModel, R.layout.layoutitem_list_view); + ``` + + Adapter,ViewHolder ..is Not Required: + + --- + + **Example** + + ![listview_databinding.gif](http://upload-images.jianshu.io/upload_images/966283-fb4ae1cdc79ff478.gif?imageMogr2/auto-orient/strip) + + --- + **Other attributes supported:** + + - *ImageView* + + ```xml + + + + + + + ``` + + - *ListView*、*ViewPager*、*RecyclerView* + + ```xml + + + + + + + + + + + + ``` + + - *ViewGroup* + + ```xml + + + + + ``` + + - *EditText* + + ```xml + + + ``` + + - *SimpleDraweeView* + + ```xml + + + ``` + + - *WebView* + + ```xml + + + ``` + + +###Command Binding### +--- + +When RecyclerView scroll to end of list,we have onLoadMoreCommand to deal with event. + + ```xml + + ``` + +In ViewModel define a ReplyCommand field to deal with this event. + + ```java + public final ReplyCommand loadMoreCommand = new ReplyCommand<>( + (count) -> { + /*count: count of list items*/ + int page=count / LIMIT +1; + loadData(page) + }); + ``` + + --- + + **Example** + + ![listview load more](http://upload-images.jianshu.io/upload_images/966283-4774960c95b4e1e5.gif?imageMogr2/auto-orient/strip) + + --- + + Deal with click event of View is more convenient: + + ```xml +