android mvvm实例,一个快速以MVVM开始做项目的框架 MVVMQuick

0a7df7a7-6b3e-42c4-af97-2b2ea5fc266f.svg

MVVMQuick

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

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

Note

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

该项目参考:

dependencies

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

Use

1.定义ViewModel,继承MQViewModel

@Singleton

public class ProjectListViewModel extends MQViewModel

{

...

}

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

xmlns:app="http://schemas.android.com/apk/res-auto">

name="projectListViewModel"

type="com.xujiaji.learnmvvm.module.projectlist.ProjectListViewModel"/>

...

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

@ActivityScoped

public class ProjectListFragment extends MQFragment

{

@Inject

Lazy 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(); //add

}

5.在AppModule的providesViewModel方法中添加配置

@Singleton

@Provides

static Map, Callable>> 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值