README/中文文档
You can create a new Kotgo template project fast by using the following command. Just paste and execute it at a terminal prompt. Have fun!
python -c "$(curl -fsSL https://raw.githubusercontent.com/nekocode/kotgo/master/project_creator.py)"
Of course, you can also download the python script to your local disk to run it. It depends on the requests
lib.
Kotgo is an android development framework using MVP architecture. It is built with pure Kotlin.
com.nekocode.baseframework
├─ data
│ ├─ dto
│ ├─ exception
│ ├─ model
│ └─ service
│
├─ presentation
│ └─ screen_one
│ ├─ Presenter.kt
│ └─ Activity.kt
│
├─ App.kt
└─ Config.kt
- Data Layer: It likes the traditional Model Layer, includes
dto
(Data Transfer Object),service
,model
,exception
or other element directories. It uses the dtos or other meta object to interact with the Presenter Layer. - View Layer: Including
activity
,adapter
,fragment
,view
. Only concerned with the user interaction, as well as view manipulation (animation, interface input, output and update, etc.). - Presenter Layer: Control logic layer. Contains the logic to respond to the events, updates the model (both the business logic and the application data), and alters the state of the view.
- kotlin version:
1.0.0
- anko:
0.8.3
- rxkotlin:
0.40.1
- retrofit:
2.0.0-beta4
- picasso:
2.5.2
- hawk:
1.22
Thanks to gank.io. The sample App fetchs beautiful girl photos' information from it.
You can only use the kotgo's component library with gradle. It provides many useful tools to help you to build a MVP project fast and simply. Just add the JitPack repository to your root build.gradle:
repositories {
maven { url "https://jitpack.io" }
}
And then add the dependency to your sub build.gradle:
dependencies {
compile 'com.github.nekocode:kotgo:<lastest-version>'
}
It helps you to bind the RxJava subscriptions into the lifecycle of Activity and Fragment. It will terminate the RxJava subscription when the activity or fragment is destorying or detaching. And the most importent thing is that it can be used anywhere (such in Prensenter), It's more flexible then the RxLifecycle.
MeiziModel.getMeizis(50, 1).onUIInLifecycle(view) {
view.refreshMeizis(it)
}
It simulates the Event Bus by RxJava. It uses many syntax sugar of Kotlin to make subscribing the Bus's events easier. And it is also binded into the lifecyle of Activity and Fragment automatically, you can just subscribe events in the bus
block without worrying about any accidents!
bus {
subscribe(String::class.java) {
showToast(it)
}
subscribe(Int::class.java) {
showToast(it.toString())
}
}
It helps you create an Activity with one single Toolbar and one single Fragment fast. You just need to inherit the toolbarLayoutId
and fragmentClass
properties. And set the toolbarLayoutId
to null if you don't need Toolbar.
class MainActivity: SingleFragmentActivity() {
override val toolbarLayoutId = R.layout.toolbar
override val fragmentClass = MainFragment::class.java
}
It also contains some other useful tools and extensions (such as KotterKnife). Check the util package for more details.