• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

kiuchikeisuke/Android-Studio-CleanArchitecture-template-forKotlin: CleanArchitec ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

kiuchikeisuke/Android-Studio-CleanArchitecture-template-forKotlin

开源软件地址(OpenSource Url):

https://github.com/kiuchikeisuke/Android-Studio-CleanArchitecture-template-forKotlin

开源编程语言(OpenSource Language):

FreeMarker 56.6%

开源软件介绍(OpenSource Introduction):

Android-Studio-CleanArchitecture-template-forKotlin

This is an Android-Studio Template for CleanArchitecture Template & Kotlin

This repository is made with reference to Android-Studio-MVP-template. So, the repository configuration is similar.

It is inspired Android-CleanArchitecture and android-architecture-component

Support androidX ONLY

V2.X is supported androidX ONLY!!.

So, if your project don't migrate to androidX,please do it first!!

Or,please use V1.X templates

Hierarchy

Here's the hierarchy it follows:

<Root>
    +--- buildSrc
    |     +--- main
    |           +--- kotlin
    |                  - Dependencies.kt
    |                  - common-library.gradle.kts
    |                  - android-application.gradle.kts
    |  
    |- android-application.gradle.kts
    |- build.gradle.kts
    |
    +--- proguard
          - XXX.pro
          - YYY.pro
          - ...


com.company.app
    +--- data
    |     +--- datasource
    |     |
    |     +--- utils
    |     |     +--- extensions
    |     |            - Observable
    |     |
    |     | - ApiModules
    |     | - RepositoryModules
    |
    +--- domain
    |     +--- entity
    |     |
    |     +--- repository
    |     |
    |     +--- usecase
    |     |
    |     +--- utils
    |     |     +--- commons
    |     |            - ExecutionThreads
    |     |            - UseCase
    |     |
    |     | - UseCaseModules
    |
    +--- presenter
    |     +--- utils
    |     |     +--- annotations
    |     |     |      - ActivityScope
    |     |     |      - ViewModelKey
    |     |     +--- commons
    |     |     |      - BasePresenter
    |     |     |      - BaseView
    |     |     |      - ViewModelFactory
    |     |     |
    |     |     +--- di
    |     |     |      - Injectable
    |     |     |
    |     |     +--- extensions
    |     |            - Activity
    |     |            - Fragment
    |     |            - LiveDataReactiveStreams
    |     |
    |     | - BindingModules
    |
    | - ApplicationModule
    | - MainApplication
    | - RootComponent

res
 +--- layout
 |    - base_activity.xml

Prerequisites

You must satisfy the following conditions.

Support Main Libraries, Service, Layout,

Installation

For Mac:

  • If you have a standard Android Studio installation:

Just run the install script at the root of this repository:

./install.sh
  • Manual installation:

Just copy all 5 directories

  • BaseCleanArchitectureTemplateKotlin
  • DataTemplateKotlin
  • DomainTemplateKotlin
  • PresenterActivityTemplateKotlin
  • PresenterFragmentTemplateKotlin
  • PresenterServiceTemplateKotlin
  • PresenterBroadcastReceiverTemplateKotlin

and paste to $ANDROID_STUDIO_FOLDER$/Contents/plugins/android/lib/templates/activities/

For Windows:

Just copy all 5 directories

  • BaseCleanArchitectureTemplateKotlin
  • DataTemplateKotlin
  • DomainTemplateKotlin
  • PresenterActivityTemplateKotlin
  • PresenterFragmentTemplateKotlin
  • PresenterServiceTemplateKotlin
  • PresenterBroadcastReceiverTemplateKotlin

and paste to $ANDROID_STUDIO_FOLDER$\plugins\android\lib\templates\activities\

How to Use

1. Generate Base template

First of all, create the base hierarchy and classes using CleanArchitectureTemplate from the root package folder. This needs to be done only once per project: CleanArchitectureTemplate

Or if you create a new project, please select CleanArchitectureTemplate on this screen.

Android Studio 3.3 maybe unsupport to add original Template to Create a new Project Selection..

Next, you set project config.

  • Application Class Name -> Set Root ApplicationClass Name
  • Create kotlin src dir? -> Please check if you have not previously created the kotlin folder
  • Need Realm? -> Please check this when using Realm
  • Need Retrofit2? -> Please check this when using Retrofit2
  • Use Swagger? -> Please check this if the Retrofit API was created by Swagger(RxJava2 used)

Project Config

When all settings are completed click the Finish button!!

2.FIX build.gradles!!

Completed to generate Base classes, it will added FIXME_merge_to_build.gradle files. FIXME_merge_to_build

Open these files and merge to original build.gradle files.

End of merge, execute gradle sync!!

Use CleanArchitecture Template

Some templates need your work.

DataTemplateKotlin

This template create data-layer template. dataLayerTemplate

This template will add DataSourceClass and DataRepositoryClass.

And then, please see DataSourceClass.The following notice is written there.

/*    FIXME MUST add below method to RepositoryModules */
//    @Binds abstract fun bindSomeDataSource(repository: SomeRepository):SomeDataSource

So, Copy @Binds abstract fun bindSomeDataSource(repository: SomeRepository):SomeDataSource to RepositoryModules

This Layer Provide Interface to domain.

DomainTemplateKotlin

This template create domain-layer template. domainUsecaseTemplate

This template will add IoUsecaseClass or InputOnlyUseCaseClass or OutputOnlyUseCaseClass or SimpleUseCaseClass.

This Layer Provide Bussiness Logic and connect DataLayer to PresentationLayer.

PresenterActivityTemplateKotlin

This template create presenter-layer template. presenterActivityTemplate

This template will add ContractClass, ModuleClass, PresenterViewModelClass, ActivityClass, FragmentClass and fragment.xml.

And then, please see ModuleClass. The following notice is written there.

/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeModule::class]) @ActivityScope abstract fun contributeSomeActivityInjector(): SomeActivity

So, Copy @ContributesAndroidInjector(modules = [SomeModule::class]) @ActivityScope abstract fun contributeSomeActivityInjector(): SomeActivity to BindingModules.

This Layer Provides UserInterface(Activity & Fragment). And presenterClass communicate domain-layer.

PresenterFragmentTemplateKotlin

This template create presenter-layer template. presenterFragmentTemplate

This template will add ContractClass, PresenterViewModelClass, FragmentClass and fragment.xml.

And then, please see FragmentClass. The following notice is written there.

/* FIXME MUST add below method to Parent Activity's Module */
//    @Binds @IntoMap @ViewModelKey(SomePresenterViewModel::class) abstract fun bindSomePresenterViewModel(viewModel: SomePresenterViewModel): ViewModel
//    @ContributesAndroidInjector abstract fun contributeSomeFragment():SomeFragment

So, Copy @Binds @IntoMap @ViewModelKey(SomePresenterViewModel::class) abstract fun bindSomePresenterViewModel(viewModel: SomePresenterViewModel): ViewModel and @ContributesAndroidInjector abstract fun contributeSomeFragment():SomeFragment to Parent activity's module.

This Layer Provides UserInterface(Fragment). And presenterClass communicate domain-layer.

PresenterServiceTemplateKotlin

This template create presenter-layer template. presenterServiceTemplate

This template will add ContractClass, ModuleClass, PresenterClass and ServiceClass.

And then, please see ModuleClass. The following notice is written there.

/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeServiceModule::class]) abstract fun contributeSomeServiceServiceInjector(): SomeServiceService

So, Copy @ContributesAndroidInjector(modules = [SomeServiceModule::class]) abstract fun contributeSomeServiceServiceInjector(): SomeServiceService to BindingModules.

This Layer Provides UserInterface(Service). And presenterClass communicate domain-layer.

PresenterBroadCastReceiverTemplateKotlin

This template create presenter-layer template. presenterBroadCastReceiverTemplate

This template will add ContractClass, ModuleClass, PresenterClass and ReceiverClass.

And then, please see ModuleClass. The following notice is written there.

/* FIXME MUST add below method to BindingModules */
// @ContributesAndroidInjector(modules = [SomeReceiverModule::class]) abstract fun contributeSomeReceiverReceiverInjector(): SomeReceiverReceiver

So, Copy @ContributesAndroidInjector(modules = [SomeReceiverModule::class]) abstract fun contributeSomeReceiverReceiverInjector(): SomeReceiverReceiver to BindingModules.

This Layer Provides UserInterface(BroadCastReceiver). And presenterClass communicate domain-layer.

Example

Very simple example is in the Example folder.

日本語の説明

Qiitaに以下の記事を公開したのでそちらを参照

Kotlin用のCleanArchitectureのテンプレート作ったよ!

Reference URL

Licence

Copyright 2017- kiuchi keisuke

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人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap