Giter Site home page Giter Site logo

xujiaji / mvvmquick Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 5.0 577 KB

🚀使用MVVMQuick快速构建您的MVVM结构项目!(Quickly start projects with MVVMQuick!)

License: Apache License 2.0

Java 100.00%
mvvm mvvm-architecture mvvm-framework mvvm-android mvvm-databing mvvm-sample dagger2 dagger2-android dagger2-mvvm dagger2-multibinding

mvvmquick's Introduction

Version

MVVMQuick

旨在快速以MVVM开始开发项目,其内集成了dagger2、okhttp3、retrofit、BaseRecyclerViewAdapterHelper、lifecycle等常用的框架和一些工具。

将大部分逻辑抽象,希望可以通过几步简单的配置,即可省去重复逻辑的代码。

Note

目前还在测试开发中,有兴趣的朋友可以体验体验给给建议哦!如要运用到项目中请自行下载项目导入mvvm-quik模块,也可直接以该项目开始开发。

该项目参考:

  1. 学习MVVM的实际运用,并且结合Dagger
  2. todo-mvp-dagger
  3. todo-mvvm-live
  4. todo-mvvm-databinding
  5. mvvm-sample-app
  6. LearnMVVM

dependencies

implementation 'com.github.xujiaji:mvvm-quick:0.0.5'

Use

详细使用案例请参考:https://github.com/xujiaji/WanAndroid

1.定义ViewModel,继承MQViewModel

@Singleton
public class ProjectListViewModel extends MQViewModel
{
    ...
}

2.布局文件fragment_project_list以DataBinding的写法

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="projectListViewModel"
            type="com.xujiaji.learnmvvm.module.projectlist.ProjectListViewModel"/>
    </data>
    ...
</layout>

3.ui中的写法,将DataBinding和ViewModel作为泛型配置,MQFragment会自动为您自动实例化

@ActivityScoped
public class ProjectListFragment extends MQFragment<FragmentProjectListBinding, ProjectListViewModel>
{

    @Inject
    Lazy<ProjectAdapter> mAdapter;

    @Inject
    public ProjectListFragment() {}

    @Override
    public void onBinding(FragmentProjectListBinding binding)
    {
        ... 当Binding初始化后会调用
    }

    @Override
    public void onObserveViewModel(ProjectListViewModel viewModel)
    {
        ... 当ViewModel初始化后会调用(在Binding之后初始化)
    }
}

4.在ViewModelSubComponent中添加配置,提供ViewModel实例(实例提供通过Dagger实现)

@Subcomponent
public interface ViewModelSubComponent
{
    ...
    Lazy<ProjectListViewModel> projectListViewModel(); //add
}

5.在AppModuleprovidesViewModel方法中添加配置

    @Singleton
    @Provides
    static Map<Class<?>, Callable<Lazy<? extends ViewModel>>> providesViewModel(ViewModelSubComponent.Builder viewModelSubComponent)
    {
        ...
        creators.put(ProjectListViewModel.class, vmsc::projectListViewModel);//add
        return creators;
    }

License

   Copyright 2018 XuJiaji

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

mvvmquick's People

Contributors

xujiaji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mvvmquick's Issues

程序不能运行

ListItemsBindingAdapter文件缺少 R.drawable.shape_line资源文件

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.