1 Star 0 Fork 36

丁丁 / MVVMFrame

forked from Jenly / MVVMFrame 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MVVMFrame

Image

Download JitPack CI CircleCI API License Blog QQGroup

MVVMFrame for Android 是一个基于Google官方推出的Architecture Components dependencies (Lifecycle,LiveData,ViewModel,Room)构建的快速开发框架。有了MVVMFrame的加持,从此构建一个MVVM模式的项目变得快捷简单。

架构

Image

Android version

引入

Maven:

<dependency>
  <groupId>com.king.frame</groupId>
  <artifactId>mvvmframe</artifactId>
  <version>1.1.1</version>
  <type>pom</type>
</dependency>

Gradle:

//AndroidX 版本
implementation 'com.king.frame:mvvmframe:1.1.1'

//Android 版本
implementation 'com.king.frame:mvvmframe:1.0.2'

Lvy:

<dependency org='com.king.frame' name='mvvmframe' rev='1.1.1'>
  <artifact name='$AID' ext='pom'></artifact>
</dependency>

引入的库 (具体对应版本请查看Versions

    //appcompat
    compileOnly deps.appcompat

    //retrofit
    api deps.retrofit.retrofit
    api deps.retrofit.gson
    api deps.retrofit.converter_gson

    //lifecycle
    api deps.lifecycle.runtime
    api deps.lifecycle.extensions
    annotationProcessor deps.lifecycle.compiler

    //room
    api deps.room.runtime
    annotationProcessor deps.room.compiler

    //dagger
    api deps.dagger.dagger
    api deps.dagger.android
    api deps.dagger.android_support
    annotationProcessor deps.dagger.android_processor
    annotationProcessor deps.dagger.compiler

    //log
    api deps.timber
如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie)
allprojects {
    repositories {
        maven { url 'https://dl.bintray.com/jenly/maven' }
    }
}

示例

集成步骤代码示例 (示例出自于app中)

Step.1 启用DataBinding,在你项目中的build.gradle的android{}中添加配置:

dataBinding {
    enabled true
}

Step.2 自定义全局配置(继承MVVMFrame中的FrameConfigModule)

/**
 * 自定义全局配置
 * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
 */
public class ConfigModule extends FrameConfigModule {
    @Override
    public void applyOptions(Context context, com.king.frame.mvvmframe.di.module.ConfigModule.Builder builder) {
        builder.baseUrl(Constants.BASE_URL)//TODO 配置Retrofit中的baseUrl
                .retrofitOptions(new RetrofitOptions() {
            @Override
            public void applyOptions(Retrofit.Builder builder) {
                //TODO 配置Retrofit
                //如想使用RxJava
                //builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            }
        })
        .okHttpClientOptions(new OkHttpClientOptions() {
            @Override
            public void applyOptions(OkHttpClient.Builder builder) {
                //TODO 配置OkHttpClient
            }
        })
        .gsonOptions(new GsonOptions() {
            @Override
            public void applyOptions(GsonBuilder builder) {
                //TODO 配置Gson
            }
        });
    }
}

Step.3 在你项目中的AndroidManifest.xml中通过配置meta-data来自定义全局配置

<!-- MVVMFrame 全局配置 -->
<meta-data android:name="com.king.mvvmframe.app.config.ConfigModule"
           android:value="FrameConfigModule"/>

Step.4 用你项目的Application继承MVVMFrame中的BaseApplication

/**
 *  MVVMFrame 框架基于Google官方的Architecture Components dependencies 构建,在使用MVVMFrame时,需遵循一些规范:
 *  1.你的项目中的Application中需初始化MVVMFrame框架相关信息,有两种方式处理:
 *      a.直接继承本类{@link BaseApplication}即可;
 *      b.如你的项目中的Application本身继承了其它第三方的Application,因为Java是单继承原因,导致没法继承本类,可参照{@link BaseApplication}类,
 *      将{@link BaseApplication}中相关代码复制到你项目的Application中,在相应的生命周期中调用即可。
 *
 * @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
 */
public class App extends BaseApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        ApplicationComponent appComponent = DaggerApplicationComponent.builder()
                .appComponent(getAppComponent())
                .build();
        //注入
        appComponent.inject(this);

    }


}

Kotlin Demo

更多使用详情,请查看app中的源码使用示例或直接查看API帮助文档

相关开源项目

KingWeather 一款天气预报APP
EasyChat 一款即时通讯APP

版本记录

v1.1.1:2019-11-4

  • 优化部分细节
  • 更新编译SDK至29
  • 更新Gradle至v5.4.1
  • 更新Lifecycle至v2.2.0-rc01
  • 更新Room至v2.2.1
  • 更新Dagger至v2.25.2
  • 更新Retrofit至v2.6.2
  • 更新Gson至v2.8.6

v1.1.0:2019-7-22

  • 更新Dagger至v2.23.2
  • 更新Gradle至v5.1.1
  • 完全迁移至AndroidX版本

v1.0.2:2019-7-22

  • 更新Dagger至v2.19
  • 为迁移至AndroidX做准备(下一版本将直接发布AndroidX版)

v1.0.1:2019-7-9

  • Retrofit更新至v2.6.0

v1.0.0:2018-12-12

  • MVVMFrame初始版本

赞赏

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

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

关于我

Name: Jenly

Email: jenly1314#gmail.com / jenly1314#vip.qq.com

CSDN: jenly121

博客园: jenly

Github: jenly1314

加入QQ群: 20867961

The MIT License (MIT) Copyright (c) 2017 Jenly Yu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

MVVMFrame for Android 是一个基于Google官方推出的Architecture Components dependencies (Lifecycle,LiveData,ViewModel,Room)构建的快速开发框架,从此构建一个MVVM模式的项目变得快捷简单。 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/dingxinghui/MVVMFrame.git
git@gitee.com:dingxinghui/MVVMFrame.git
dingxinghui
MVVMFrame
MVVMFrame
master

搜索帮助