core-arch-annotations
是注解库,配合注解编译库 core-arch-processor
使用,实现 Application 多模块共存。
2. 数据总线 core-eventbus
core-eventbus
在 EventBus
基础上添加 Tag 功能,配合注解编译库 core-eventbus-processor
使用,提高效率。
3. 框架核心 core-arch
-
依赖
core-arch-annotations、core-eventbus。 - 依赖第三方框架 Dagger 、 RxJava 、 Androidx.Core 、 Androidx.Appcompat 、 Androidx.Lifecycle 。
3.1 核心接口
-
RxSubscriberView实现该接口的 View,RxFlux根据其生命周期自动注册订阅、取消订阅,接收core-eventbus发送的通知。 -
RxFluxView<T extends ViewModel>实现该接口的 View,可获取对应的 Store 并关联 View 的生命周期。 -
RxAppLifecycleApplication 生命周期代理接口。
3.2 核心类
-
RxApp继承DaggerApplication,为使用@ContributesAndroidInjector注解的 Activity 自动生成依赖注入器。使用反射获取编译生成类RxAppLifecycleImpl,实现 Application 多模块共存。 -
RxFlux管理 View 生命周期,关联 View 与 Store,使用@Inject标注构造方法注入。 -
RxDispatcher使用core-eventbus对 View 和 Store 注册订阅、发送通知、取消订阅,使用@Inject标注构造方法注入。 -
RxActionManager管理RxAction与io.reactivex.disposables.Disposable对应关系,使用@Inject标注构造方法注入。 -
RxStoreFactory实现ViewModelProvider.Factory,为 View 提供 Store,使用@Inject标注构造方法注入。 -
RxActionCreator所有 ActionCreator 的父类,封装RxDispatcher和RxActionManager,为子类提供公共方法。 -
RxFluxModule全局依赖注入仓库,提供ViewModelProvider.Factory的实现类RxStoreFactory实例对象,提供Context的子类Application实例对象。
3.3 核心View
-
RxFluxActivity<T>、RxFluxFragment<T>、RxFluxDialog<T>实现RxFluxView<T>、RxSubscriberView接口方法,是所有 View 的父类。 -
RxFluxActivity<T>实现dagger.android.supportHasSupportFragmentInjector接口,为使用@ContributesAndroidInjector注解的 Fragment 自动生成依赖注入器。
通用库
core-common
封装自定义父类和自定义常用 工具 方法,添加通用依赖,使用时可按自己编程习惯重新编写。
-
依赖核心库
core-arch,唯一不可变动,其余依赖都可替换。 -
依赖
core-image、core-utils、core-progress、core-cookie。 - 依赖第三方框架 Arouter 、 ButterKnife 、 OkHttp 、 Retrofit 、 Logger 、 Gson 、 LeakCanary 、 BaseRecyclerViewAdapterHelper 。
1. 包 base
-
BaseApp继承RxApp,全局使用的Application,初始化全局使用的方法工具。 -
BaseView自定义 View 接口。 -
BaseActivity<T>实现BaseView,继承RxFluxActivity<T>,使用 ButterKnife ,自定义全局响应RxLoading、RxError、RxRetry。 -
BaseFragment<T>实现BaseView,继承RxFluxFragment<T>,使用 ButterKnife ,自定义ToolBar、Menu。 -
BaseDialog<T>实现BaseView,继承RxFluxDialog<T>,使用 ButterKnife 。
2. 包 common
-
CommonActionCreator可全局使用的 ActionCreator,使用@Inject标注构造方法注入。 -
CommonLoadingDialog可全局使用的进度弹框,使用@Inject标注构造方法注入。 -
CommonHttpInterceptor可全局使用的 OkHttp 拦截器,使用@Inject标注构造方法注入。 -
CommonException自定义异常。 -
CommonModule通用全局依赖注入仓库,依赖RxFluxModule。 -
CommonUtils常用自定义工具。 -
CommonLoadMoreView自定义 BaseRecyclerViewAdapterHelper 加载样式。
功能库
1. 图片解析 core-image
core-image
封装 Glide
,解析图片。
2. 常用工具 core-utils
-
ActivityUtils自定义 Activity 中常用方法。 -
LocalStorageUtils封装 Fastjson 的工具类,使用@Inject标注构造方法注入。
3. 下载进度提醒 core-progress
core-progress
使用 OkHttp
、 Retrofit
,依赖核心库 core-arch
,完成下载进度提醒,使用 @Inject
标注构造方法注入。
4. 缓存Cookie core-cookie
core-cookie
接口认证使用 Cookie 缓存,使用 @Inject
标注构造方法注入。
壳模块
壳模块 module-app
中 SimpleApplication
继承 BaseApp
,使用依赖注入器 SimpleComponent
,实现依赖注入。
@RxAppBody
public class SimpleApplication extends BaseApp {
@Override
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerSimpleComponent.builder().application(this).build();
}
}
复制代码
SimpleComponent
中添加业务模块依赖注入仓库、通用全局依赖注入仓库 CommonModule
、Dagger.Android支持仓库 AndroidSupportInjectionModule
。
@Singleton
@Component(modules = {
GanAppModule.class,
WanAppModule.class,
com.huyingbao.module.wan.kotlin.module.WanAppModule.class,
CommonModule.class,
AndroidSupportInjectionModule.class})
public interface SimpleComponent extends AndroidInjector<SimpleApplication> {
@Component.Builder
interface Builder {
@BindsInstance
SimpleComponent.Builder application(Application application);
SimpleComponent build();
}
}
复制代码
业务模块
业务模块 module-wan
依赖注入仓库 WanAppModule
,包含 WanInjectActivityModule
和 WanStoreModule
。
-
WanInjectActivityModule通过注解@ContributesAndroidInjector,自动生成 Activity 的依赖注入器。 -
WanStoreModule提供 Store 对象仓库,Store 使用@Inject标注构造方法注入。
每个 Activity 的注入器中添加 WanInjectFragmentModule
, WanInjectFragmentModule
通过注解 @ContributesAndroidInjector
,自动生成 Fragment 的依赖注入器。
@Module
public abstract class WanInjectActivityModule {
@ActivityScope
@ContributesAndroidInjector(modules = WanInjectFragmentModule.class)
abstract ArticleActivity injectArticleActivity();
@ActivityScope
@ContributesAndroidInjector(modules = WanInjectFragmentModule.class)
abstract LoginActivity injectLoginActivity();
}
复制代码
源码
开源模块化解耦框架 RxFluxArchitecture ,欢迎大家点赞Fork,更欢迎点评指导。
以上所述就是小编给大家介绍的《模块化解耦框架RxFluxArchitecture4-依赖库与依赖注入》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Mechanics of Web Handling
David R. Roisum
This unique book covers many aspects of web handling for manufacturing, converting, and printing. The book is applicable to any web including paper, film, foil, nonwovens, and textiles. The Mech......一起来看看 《The Mechanics of Web Handling》 这本书的介绍吧!