Code Monkey home page Code Monkey logo

ktarmor's Introduction

前言

学习了Kotlin有一段时间了, 每次写项目/Demo的时候, 总是用到网络请求MVPMVVM常用工具类通用自定义View, 索性把这些整合到一起, 搭成一个Android的脚手架——KtArmor.

什么是KtArmor ?

KtArmor 寓意着 为Android 赋予战斗装甲, 方便开发者快速进行Android 开发。节约开发者开发时间。为了满足开发者需求, 我整合了两个分支, 分别对应着 MVP, MVVM.

  • MVP
    • 架构模式: MVP + Kotlin
    • 网络请求: Retrofit + Okhttp + Coroutine
    • 功能:
    • 架构模式: MVP + Kotlin
    • 网络请求: Retrofit + Okhttp + Coroutine
    • 代码:简洁优雅, 易扩展
    • 文档: 有相关的KtArmor-MVP 系列文档说明
    • 插件:对应 KtArmor-MVP 模板代码生成插件
    • 功能:
      • 基本BaseActivityBaseFragmentToolbarActivity封装
      • MVP框架封装 MvpActivityMvpFragmentBasePresenterBaseModel封装
      • 网络请求封装 BaseOkHttpClientBaseRetrofitRetrofitFactory
      • 常用控件PlaceHolderView(占位布局)LoadingView(加载框)
      • 常用扩展封装(SharedPreferencesStartActivityLogToast(不重复显示))等
      • MVP代码模板(ActivityPresenterContractModel)生成插件
      • ....

MVP框架引入

先在 build.gradle(Project:XXXX) 的 repositories 添加:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

然后在 build.gradle(Module:app) 的 dependencies 添加:

implementation 'com.github.hyzhan43:KtArmor:mvp-1.0.4'  // 根据github 引入最新版本即可

快速上手

在Application 中初始化KtArmor 框架。新建一个application 类, 如 BaseApplication, 在 BaseApplication 中, 调用KtArmor的 init 方法, 进行初始化, 参数如下:

  • 第一个参数是application,
  • 第二个参数是对应RetrofitConfig 配置。
class BaseApplication: Application(){

    override fun onCreate() {
        super.onCreate()

        // 初始化KtArmor
        KtArmor.init(this, MyRetrofitConfig())
    }
}

再新建一个 RetrofitConfig 配置类, 继承 BaseRetrofitConfig. 并复写 baseUrl 属性, 添加自己的 baseUrl。

class MyRetrofitConfig : BaseRetrofitConfig() {

    override val baseUrl: String
        get() = API.BASE_URL
}

这样你就创建好了一个拥有Kotlin + Retrofit + Okhttp + Coroutine项目了。然后就可以愉快编写自己的业务代码了(●'◡'●)

更多用法

未完待续

ktarmor's People

Contributors

hyzhan43 avatar

Watchers

James Cloos 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.