GithubHelp home page GithubHelp logo

jenly1314 / mvvmframecomponent Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 5.0 18.79 MB

:european_castle: 基于 MVVMFrame 框架 采用 JetPack (Lifecycle,LiveData,ViewModel,Room) + Dagger + DataBinding + Retrofit + OkHttp + Glide + Kotlin coroutines + ARouter等 为核心基础库构建的组件化方案

License: MIT License

Kotlin 100.00%
component mvvm jetpack android-com architecture-components lifecycle mvvm-component livedata viewmodel dagger2 kotlin-coroutines arouter retrofit2 okhttp3 glide component-architecture components hilt

mvvmframecomponent's Introduction

MVVMFrameComponent

Image

Download API License

基于 MVVMFrame 框架为核心基础库构建的组件化方案

主要使用的核心技术

  • JetPack(Lifecycle,LiveData,ViewModel,Room,Hilt)
  • Dagger
  • DataBinding
  • Retrofit
  • OkHttp
  • Glide
  • Kotlin coroutines
  • ARouter

架构

MVVMFrameComponent 组件化架构图分层如下:

Architecture

因为组件化的核心基础库是基于 MVVMFrame,这里贴出 MVVMFrame 的架构图如下:

Architecture

浅谈组件化

  1. 什么是组件化?

组件化简单概括就是把一个功能完整的 App模块 拆分成多个子模块, 让每个子模块可以独立编译和运行, 也可以作为 library 合并到宿主App组成一个完整的 App进行编译和运行。每个模块即可以不相互依赖,又可以相互交互。

  1. 为什么要组件化?

当一个项目随着时间的推移,需求不断的变更与迭代。各个模块也会变的相对复杂。维护难度也会随之增加,时间久了,可能会引起一些新的问题。这时我们就需要组件化。

  1. 组件化的优势是什么?

当一个App使用组件化开发方案时,主要的优势有:组件化拆分各个模块后,每个子模块都可以独立编译和运行,这样在开发调测某个模块时,可以大大提高编译速度和开发效率。多人开发时,每个人负责独立的模块,更有利于多人团队协作开发。并且各个模块之间的代码边界相对清晰,更易于后期维护。

MVVMFrameComponent 组件化方案

MVVMFrameComponent = MVVMFrame + Component。即 MVVMFrameComponent 采用 MVVM 模式架构的组件化方案。

工程各个 Module 相关说明

app

宿主App:当各个子 Module 作为 library 时,则可将所有组件集成到 宿主App 中。此时 宿主App 则是一个拥有所有组件功能集合的完整的App。

common-base

组件化公共基础库:主要包含 MVVMFrame 快速开发框架,和作为组件化的一些公共的核心基础库,方便快速构建组件化 Project

common-res

组件化公共资源库:主要方便统一管理各个 Module 中的一些公共资源相关。

module-joke

一个简单的笑话功能模块:主要用来展示基于 MVVMFrame 来实现组件化开发,作为组件化开发的 Module 实现示例之一。

module-news

一个简单的新闻功能模块:主要用来展示基于 MVVMFrame 来实现组件化开发,作为组件化开发的 Module 实现示例之一。

其他

特别说明

Project -> build.gradle 内的自定义变量 isBuildModule

自定义变量 isBuildModule 来统一管理各个子 module 方便在 applicationlibrary 之间进行切换

isBuildModule = true 时,表示 各个子 moduleapplication ,即 module 可独立运行 当 isBuildModule = false 时,表示 各个子 modulelibrary ,即 module 作为 library 合并到 宿主App

Project -> module-build.gradle

组件化子 module 通用 build.gradle ,方便统一管理

根据 isBuildModule 来统一管理各个子 moduleapplicationlibrary 之间切换

关于 MVVMFrame

因为 MVVMFrameComponent 的核心基础库是基于 MVVMFrame 的,所以需要对 MVVMFrame 有一定的了解,才能在使用 MVVMFrameComponent 时更加得心应手, 这里不再特意介绍 MVVMFrame 相关的使用,具体介绍你可以直接查看 MVVMFrame

示例

关于各组件/模块共用 Application 初始化

对于模块公用的可以尽量写在 BaseApp 中,对于模块相对独立使用的,可以写在模块对应 IComponentApp 的实现实现类中。

特别说明:对于IComponentApp 的实现只是为你提供对应需求的一种解决方式,是可选的。根据需要使用。

这里贴出各模块的 IComponentApp 实现类示例供参考:

module-jokeIComponentApp 的实现类是 JokeComponentApp

module-newsIComponentApp 的实现类是 NewsComponentApp

下面是 module-joke 中的代码示例

class JokeComponentApp : IComponentApp{

    override fun onCreate(app: BaseApp) {

    }

}

Manifest 中配置 meta-data 对应的IComponentApp实现类,示例如下 :

        <!-- name为:IComponentApp的实现类,value固定为: ComponentApp -->
        <meta-data android:name="com.king.mvvm.joke.JokeComponentApp"
            android:value="ComponentApp"/>

当想要获取各模块的 IComponentApp 实现类时,可通过 BaseAppgetComponentApp 方法获取。

更多使用详情,请查看app中的源码使用示例

更新日志

2021-1-15

  • 使用Hilt简化Dagger依赖注入用法
  • 更新gradle至v4.1.1
  • 更新MVVMFrame至v2.0.0
  • 更新其它第三方依赖库版本

2020-6-23

  • MVVMFrameComponent初始版本

赞赏

如果你喜欢MVVMFrameComponent,或感觉MVVMFrameComponent帮助到了你,可以点右上角“Star”支持一下,你的支持就是我的动力,谢谢 😃

您也可以扫描下面的二维码,请作者喝杯咖啡 ☕

关于我

我的博客 GitHub Gitee CSDN 博客园
Jenly's Blog jenly1314 jenly1314 jenly121 jenly

联系我

微信公众号 Gmail邮箱 QQ邮箱 QQ群 QQ群
Jenly666 jenly1314 jenly1314 20867961 64020761

mvvmframecomponent's People

Contributors

jenly1314 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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.