├── .gitignore
├── LICENSE
├── README.md
├── api
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── silverlotus
│ │ └── api
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── silverlotus
│ │ │ └── api
│ │ │ ├── Api.kt
│ │ │ ├── model
│ │ │ ├── MangaListModel.kt
│ │ │ └── MangaModel.kt
│ │ │ └── subapi
│ │ │ └── MangaEdenApi.kt
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── silverlotus
│ └── api
│ └── ExampleUnitTest.kt
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── silverlotus
│ │ └── kmvvm
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── silverlotus
│ │ │ └── kmvvm
│ │ │ ├── adapter
│ │ │ └── MangaAdapter.kt
│ │ │ ├── base
│ │ │ ├── App.kt
│ │ │ ├── BaseActivity.kt
│ │ │ ├── BaseFragment.kt
│ │ │ ├── BaseRepository.kt
│ │ │ └── BaseViewModel.kt
│ │ │ ├── repository
│ │ │ └── MangaRepository.kt
│ │ │ ├── room
│ │ │ ├── AppDatabase.kt
│ │ │ ├── dao
│ │ │ │ └── MangaDao.kt
│ │ │ └── entity
│ │ │ │ └── MangaEntity.kt
│ │ │ └── ui
│ │ │ └── main
│ │ │ ├── MainActivity.kt
│ │ │ ├── MainFragment.kt
│ │ │ ├── MainView.kt
│ │ │ └── MainViewModel.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_main.xml
│ │ └── item_manga.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── silverlotus
│ └── kmvvm
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | /.idea
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | # External native build folder generated in Android Studio 2.2 and later
43 | .externalNativeBuild
44 |
45 | # Google Services (e.g. APIs or Firebase)
46 | google-services.json
47 |
48 | # Freeline
49 | freeline.py
50 | freeline/
51 | freeline_project_description.json
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Gian Patrick Quintana
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android-Kotlin-MVVM-Template
2 |
3 | Short Intro:
4 |
5 | Anyways so this is my MVVM template. I use these stuff:
6 | * Kotlin (Because Kotlin is life)
7 | * [Kodein-DI](https://github.com/Kodein-Framework/Kodein-DI) (For dependency injection)
8 | * Examples of Kodein Usages
9 | * [Fuel](https://github.com/kittinunf/Fuel) (Http Client)
10 | * Android Architecture LiveData
11 | * Android Architecture Lifecycle
12 | * Android Architecture Room
13 | * Android Architecture Paging
14 | * [Klaxon](https://github.com/cbeust/klaxon) (JSON Parser)
15 | * [Logger](https://github.com/orhanobut/logger) (Logger)
16 |
17 | Future Updates:
18 | A much more in depth example of this template. For now a more simple example which you can expand easily.
--------------------------------------------------------------------------------
/api/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/api/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 27
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 |
17 | buildTypes {
18 |
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | testOptions {
26 | unitTests{
27 | includeAndroidResources = true
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 |
35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
36 | implementation "com.android.support:appcompat-v7:$support_library_version"
37 |
38 | implementation "com.github.kittinunf.fuel:fuel:$fuel_version"
39 | implementation "com.github.kittinunf.fuel:fuel-android:$fuel_version"
40 | implementation "com.github.kittinunf.fuel:fuel-livedata:$fuel_version"
41 |
42 | implementation 'com.beust:klaxon:2.1.1'
43 | implementation 'com.orhanobut:logger:2.1.1'
44 |
45 | testImplementation 'org.robolectric:robolectric:3.8'
46 | testImplementation 'junit:junit:4.12'
47 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
48 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
49 | }
50 | repositories {
51 | mavenCentral()
52 | }
53 |
--------------------------------------------------------------------------------
/api/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/api/src/androidTest/java/com/silverlotus/api/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api
2 |
3 | import android.content.Context
4 | import android.support.test.InstrumentationRegistry
5 | import android.support.test.runner.AndroidJUnit4
6 |
7 | import org.junit.Test
8 | import org.junit.runner.RunWith
9 |
10 | import org.junit.Assert.*
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see [Testing documentation](http://d.android.com/tools/testing)
16 | */
17 | @RunWith(AndroidJUnit4::class)
18 | class ExampleInstrumentedTest {
19 | @Test
20 | @Throws(Exception::class)
21 | fun useAppContext() {
22 | // Context of the app under test.
23 | val appContext = InstrumentationRegistry.getTargetContext()
24 |
25 | assertEquals("com.silverlotus.api.test", appContext.packageName)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/api/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/api/src/main/java/com/silverlotus/api/Api.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api
2 |
3 | import com.github.kittinunf.fuel.Fuel
4 | import com.github.kittinunf.fuel.core.Request
5 | import com.github.kittinunf.fuel.livedata.liveDataObject
6 | import com.silverlotus.api.model.MangaListModel
7 | import com.silverlotus.api.subapi.MangaEdenApi
8 |
9 | /**
10 | * Created by Gian Patrick Quintana on 2/1/2018.
11 | */
12 |
13 | class Api {
14 |
15 | private fun request(api: Fuel.RequestConvertible): Request {
16 |
17 | return Fuel.request(api)
18 | .timeout(30000)
19 | }
20 |
21 | fun getMangaList() = request(MangaEdenApi.MangaList()).liveDataObject(MangaListModel.Deserializer())
22 | }
--------------------------------------------------------------------------------
/api/src/main/java/com/silverlotus/api/model/MangaListModel.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api.model
2 |
3 | import com.beust.klaxon.Json
4 | import com.beust.klaxon.Klaxon
5 | import com.github.kittinunf.fuel.core.ResponseDeserializable
6 |
7 | /**
8 | * Created by Gian Patrick Quintana on 2/19/2018.
9 | */
10 | data class MangaListModel(
11 | @Json(name = "manga") val listOfMangaData: List = listOf()
12 | ) {
13 | class Deserializer : ResponseDeserializable {
14 | override fun deserialize(content: String) = Klaxon().parse(content)
15 | }
16 | }
--------------------------------------------------------------------------------
/api/src/main/java/com/silverlotus/api/model/MangaModel.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api.model
2 |
3 | import com.beust.klaxon.Json
4 |
5 | /**
6 | * Created by Gian Patrick Quintana on 2/21/2018.
7 | */
8 | data class MangaModel(
9 | @Json(name = "i") val id: String = "",
10 | @Json(name = "t") var title: String = ""
11 | )
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/api/src/main/java/com/silverlotus/api/subapi/MangaEdenApi.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api.subapi
2 |
3 | import com.github.kittinunf.fuel.core.Method
4 | import com.github.kittinunf.fuel.util.FuelRouting
5 |
6 | /**
7 | * Created by Gian Patrick Quintana on 2/19/2018.
8 | */
9 | internal sealed class MangaEdenApi : FuelRouting {
10 |
11 | class MangaList : MangaEdenApi()
12 |
13 | override val basePath: String = "https://www.mangaeden.com/"
14 |
15 | override val headers: Map? = null
16 |
17 | override val method: Method
18 | get() {
19 | when (this) {
20 | is MangaList -> return Method.GET
21 | }
22 | }
23 |
24 | override val params: List>?
25 | get() {
26 | when (this) {
27 | is MangaList -> return null
28 | }
29 | }
30 | override val path: String
31 | get() {
32 | when (this) {
33 | is MangaList -> return "api/list/0/"
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/api/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | api
3 |
4 |
--------------------------------------------------------------------------------
/api/src/test/java/com/silverlotus/api/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.api
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see [Testing documentation](http://d.android.com/tools/testing)
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | @Throws(Exception::class)
15 | fun addition_isCorrect() {
16 | assertEquals(4, (2 + 2).toLong())
17 | }
18 | }
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | apply plugin: 'kotlin-kapt'
8 |
9 | android {
10 | compileSdkVersion 27
11 |
12 | defaultConfig {
13 | applicationId "com.silverlotus.kmvvm"
14 | minSdkVersion 19
15 | targetSdkVersion 27
16 | versionCode 1
17 | versionName "1.0"
18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
19 | }
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 |
26 | buildTypes {
27 |
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 |
34 | testOptions {
35 | unitTests{
36 | includeAndroidResources = true
37 | }
38 | }
39 | }
40 |
41 | dependencies {
42 | implementation fileTree(include: ['*.jar'], dir: 'libs')
43 |
44 | implementation project(':api')
45 |
46 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
47 | implementation 'androidx.core:core-ktx:0.2'
48 |
49 | implementation "com.android.support:appcompat-v7:$support_library_version"
50 | implementation "com.android.support:design:$support_library_version"
51 | implementation "com.android.support:recyclerview-v7:$support_library_version"
52 | implementation "com.android.support:cardview-v7:$support_library_version"
53 | implementation "com.android.support:customtabs:$support_library_version"
54 | implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta6'
55 |
56 | implementation "org.kodein.di:kodein-di-generic-jvm:$kodein_version"
57 | implementation "org.kodein.di:kodein-di-framework-android:$kodein_version"
58 |
59 | implementation "android.arch.lifecycle:extensions:$architecture_version"
60 | implementation "android.arch.lifecycle:common-java8:$architecture_version"
61 |
62 | implementation 'android.arch.persistence.room:runtime:1.1.0-beta1'
63 | kapt "android.arch.persistence.room:compiler:1.1.0-beta1"
64 |
65 | implementation "android.arch.paging:runtime:1.0.0-alpha7"
66 |
67 | implementation "com.github.kittinunf.fuel:fuel:$fuel_version"
68 |
69 | implementation 'com.orhanobut:logger:2.1.1'
70 |
71 | testImplementation 'org.robolectric:robolectric:3.8'
72 | testImplementation 'junit:junit:4.12'
73 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
74 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
75 | }
76 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 | -keepattributes Signature
23 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/silverlotus/kmvvm/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm
2 |
3 | import android.support.test.InstrumentationRegistry
4 | import android.support.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.silverlotus.kmvp", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/adapter/MangaAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.adapter
2 |
3 | import android.support.v7.recyclerview.extensions.ListAdapter
4 | import android.support.v7.util.DiffUtil
5 | import android.support.v7.widget.RecyclerView
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import com.silverlotus.kmvvm.R
10 | import com.silverlotus.kmvvm.room.entity.MangaEntity
11 | import kotlinx.android.synthetic.main.item_manga.view.*
12 |
13 | /**
14 | * Created by Gian Patrick Quintana on 2/24/2018.
15 | */
16 | class MangaAdapter : ListAdapter(MangaItemCallback()) {
17 |
18 | private class MangaItemCallback : DiffUtil.ItemCallback() {
19 |
20 | override fun areItemsTheSame(oldItem: MangaEntity?, newItem: MangaEntity?): Boolean = oldItem?.id == newItem?.id
21 |
22 | override fun areContentsTheSame(oldItem: MangaEntity?, newItem: MangaEntity?): Boolean = oldItem?.title == newItem?.title
23 | }
24 |
25 | fun isLastItemVisible(): Boolean {
26 |
27 | getItem(itemCount - 1)
28 |
29 | return false
30 | }
31 |
32 | override fun onBindViewHolder(holder: MangaViewHolder, position: Int) {
33 | val manga = getItem(position)
34 | if (manga != null)
35 | holder.bind(manga)
36 | }
37 |
38 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaViewHolder =
39 | MangaViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_manga, parent, false))
40 |
41 | inner class MangaViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
42 |
43 | fun bind(manga: MangaEntity?) = with(itemView) {
44 | textTitle.text = manga?.title
45 | }
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/base/App.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.base
2 |
3 | import android.app.Application
4 | import android.arch.persistence.room.Room
5 | import android.content.Context
6 | import android.content.SharedPreferences
7 | import com.orhanobut.logger.AndroidLogAdapter
8 | import com.orhanobut.logger.Logger
9 | import com.silverlotus.api.Api
10 | import com.silverlotus.kmvvm.repository.MangaRepository
11 | import com.silverlotus.kmvvm.room.AppDatabase
12 | import com.silverlotus.kmvvm.room.dao.MangaDao
13 | import org.kodein.di.Kodein
14 | import org.kodein.di.KodeinAware
15 | import org.kodein.di.generic.bind
16 | import org.kodein.di.generic.instance
17 | import org.kodein.di.generic.singleton
18 |
19 | /**
20 | * Created by Gian Patrick Quintana on 1/22/2018.
21 | */
22 | class App : Application(), KodeinAware {
23 |
24 | override val kodein = Kodein.lazy {
25 |
26 | val database: AppDatabase = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "app.db")
27 | .allowMainThreadQueries()
28 | .build()
29 |
30 | bind() with singleton { database.mangaListDao() }
31 | bind() with singleton { MangaRepository(applicationContext) }
32 | bind() with singleton { Api() }
33 | bind() with instance(getSharedPreferences("PREFERENCES", Context.MODE_PRIVATE))
34 | }
35 |
36 | // override val kodein by Kodein.lazy {
37 | //
38 | // val database: AppDatabase = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "app.db")
39 | // .allowMainThreadQueries()
40 | // .build()
41 | //
42 | // bind() with singleton { database.mangaListDao() }
43 | // bind() with singleton { MangaRepository().init(appKodein()) }
44 | // bind() with singleton { Api() }
45 | // }
46 |
47 | override fun onCreate() {
48 | super.onCreate()
49 |
50 | Logger.addLogAdapter(AndroidLogAdapter())
51 | }
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/base/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.base
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import org.kodein.di.Kodein
7 | import org.kodein.di.KodeinAware
8 | import org.kodein.di.KodeinTrigger
9 | import org.kodein.di.android.closestKodein
10 |
11 | /**
12 | * Created by Gian Patrick Quintana on 1/22/2018.
13 | */
14 | @SuppressLint("Registered")
15 | abstract class BaseActivity : AppCompatActivity(), KodeinAware {
16 |
17 | override val kodein: Kodein by closestKodein()
18 | override val kodeinTrigger = KodeinTrigger()
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | kodeinTrigger.trigger()
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/base/BaseFragment.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.base
2 |
3 | import android.os.Bundle
4 | import android.support.v4.app.Fragment
5 | import org.kodein.di.Kodein
6 | import org.kodein.di.KodeinAware
7 | import org.kodein.di.KodeinTrigger
8 | import org.kodein.di.android.closestKodein
9 |
10 | /**
11 | * Created by Gian Patrick Quintana on 1/22/2018.
12 | */
13 | abstract class BaseFragment : Fragment(), KodeinAware {
14 |
15 | override val kodein: Kodein by closestKodein()
16 | override val kodeinTrigger = KodeinTrigger()
17 |
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | kodeinTrigger.trigger()
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/base/BaseRepository.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.base
2 |
3 | import android.content.Context
4 | import org.kodein.di.Kodein
5 | import org.kodein.di.KodeinAware
6 | import org.kodein.di.KodeinTrigger
7 | import org.kodein.di.android.closestKodein
8 |
9 | /**
10 | * Created by Gian Patrick Quintana on 2/23/2018.
11 | */
12 | abstract class BaseRepository(context: Context) : KodeinAware {
13 |
14 | override val kodein: Kodein by closestKodein(context)
15 | override val kodeinTrigger: KodeinTrigger = KodeinTrigger()
16 |
17 | @Suppress("UNCHECKED_CAST")
18 | fun init(): T {
19 |
20 | kodeinTrigger.trigger()
21 | return this as T
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/base/BaseViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.base
2 |
3 | import android.arch.lifecycle.ViewModel
4 | import org.kodein.di.Kodein
5 | import org.kodein.di.KodeinAware
6 | import org.kodein.di.KodeinTrigger
7 |
8 | /**
9 | * Created by Gian Patrick Quintana on 2/23/2018.
10 | */
11 | abstract class BaseViewModel : ViewModel(), KodeinAware {
12 |
13 | override lateinit var kodein: Kodein
14 | override val kodeinTrigger: KodeinTrigger = KodeinTrigger()
15 |
16 | @Suppress("UNCHECKED_CAST")
17 | fun init(kodein: Kodein): T {
18 |
19 | this.kodein = kodein
20 | kodeinTrigger.trigger()
21 | return this as T
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/repository/MangaRepository.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.repository
2 |
3 | import android.arch.paging.LivePagedListBuilder
4 | import android.arch.paging.PagedList
5 | import android.content.Context
6 | import com.silverlotus.api.Api
7 | import com.silverlotus.kmvvm.base.BaseRepository
8 | import com.silverlotus.kmvvm.room.dao.MangaDao
9 | import com.silverlotus.kmvvm.room.entity.MangaEntity
10 | import org.kodein.di.generic.instance
11 |
12 | /**
13 | * Created by Gian Patrick Quintana on 2/22/2018.
14 | */
15 |
16 | class MangaRepository(private val context: Context) : BaseRepository(context = context) {
17 |
18 | private val mangaDao by instance()
19 | private val api by instance()
20 |
21 | val pagingConfig = PagedList.Config.Builder()
22 | .setPageSize(20)
23 | .build()
24 |
25 | fun getMangaList(max: Int) = LivePagedListBuilder(mangaDao.getMangaList(max), pagingConfig).build()
26 |
27 | fun fetchMangaList() {
28 | api.getMangaList().observeForever({ result ->
29 | if (result != null) {
30 | val (data, error) = result
31 | if (data != null)
32 | mangaDao.updateMangaList(MangaEntity.fromMangaList(data))
33 | }
34 | })
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/room/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.room
2 |
3 | import android.arch.persistence.room.Database
4 | import android.arch.persistence.room.RoomDatabase
5 | import com.silverlotus.kmvvm.room.dao.MangaDao
6 | import com.silverlotus.kmvvm.room.entity.MangaEntity
7 |
8 | /**
9 | * Created by Gian Patrick Quintana on 2/21/2018.
10 | */
11 | @Database(entities = [(MangaEntity::class)], version = 1, exportSchema = false)
12 | abstract class AppDatabase : RoomDatabase() {
13 |
14 | abstract fun mangaListDao(): MangaDao
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/room/dao/MangaDao.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.room.dao
2 |
3 | import android.arch.paging.DataSource
4 | import android.arch.persistence.room.Dao
5 | import android.arch.persistence.room.Insert
6 | import android.arch.persistence.room.OnConflictStrategy.REPLACE
7 | import android.arch.persistence.room.Query
8 | import android.arch.persistence.room.Update
9 | import com.silverlotus.kmvvm.room.entity.MangaEntity
10 |
11 | /**
12 | * Created by Gian Patrick Quintana on 2/21/2018.
13 | */
14 | @Dao
15 | interface MangaDao {
16 |
17 | @Query("SELECT * FROM manga_list LIMIT :max")
18 | fun getMangaList(max: Int): DataSource.Factory
19 |
20 | @Insert(onConflict = REPLACE)
21 | fun insertManga(mangaEntity: MangaEntity)
22 |
23 | @Insert(onConflict = REPLACE)
24 | fun updateMangaList(list: List)
25 |
26 | @Update(onConflict = REPLACE)
27 | fun updateManga(mangaEntity: MangaEntity)
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/room/entity/MangaEntity.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.room.entity
2 |
3 | import android.arch.persistence.room.ColumnInfo
4 | import android.arch.persistence.room.Entity
5 | import android.arch.persistence.room.PrimaryKey
6 | import com.silverlotus.api.model.MangaListModel
7 | import com.silverlotus.api.model.MangaModel
8 |
9 | /**
10 | * Created by Gian Patrick Quintana on 2/21/2018.
11 | */
12 | @Entity(tableName = "manga_list")
13 | class MangaEntity {
14 |
15 | @PrimaryKey
16 | @ColumnInfo(name = "id")
17 | var id: String = ""
18 |
19 | @ColumnInfo(name = "title")
20 | var title: String = ""
21 |
22 | fun fromMangaData(manga: MangaModel): MangaEntity {
23 | id = manga.id
24 | title = manga.title
25 | return this
26 | }
27 |
28 | companion object {
29 |
30 | fun fromMangaList(mangaListModel: MangaListModel): List =
31 | mangaListModel.listOfMangaData.map { data -> MangaEntity().fromMangaData(data) }
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/ui/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.ui.main
2 |
3 | import android.os.Bundle
4 | import com.silverlotus.kmvvm.R
5 | import com.silverlotus.kmvvm.base.BaseActivity
6 |
7 | /**
8 | * Created by Gian Patrick Quintana on 1/22/2018.
9 | */
10 | class MainActivity : BaseActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_main)
15 |
16 | supportFragmentManager.beginTransaction()
17 | .add(R.id.fragmentContainer, MainFragment())
18 | .commit()
19 |
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/ui/main/MainFragment.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.ui.main
2 |
3 | import android.arch.lifecycle.Observer
4 | import android.arch.lifecycle.ViewModelProviders
5 | import android.os.Bundle
6 | import android.support.v7.widget.LinearLayoutManager
7 | import android.support.v7.widget.RecyclerView
8 | import android.view.LayoutInflater
9 | import android.view.View
10 | import android.view.ViewGroup
11 | import com.orhanobut.logger.Logger
12 | import com.silverlotus.kmvvm.R
13 | import com.silverlotus.kmvvm.adapter.MangaAdapter
14 | import com.silverlotus.kmvvm.base.BaseFragment
15 | import kotlinx.android.synthetic.main.fragment_main.*
16 |
17 | /**
18 | * Created by Gian Patrick Quintana on 1/22/2018.
19 | */
20 | class MainFragment : BaseFragment(), MainView {
21 |
22 | private lateinit var model: MainViewModel
23 | private val adapter = MangaAdapter()
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | model = ViewModelProviders.of(this).get(MainViewModel::class.java).init(kodein)
28 | }
29 |
30 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
31 | inflater.inflate(R.layout.fragment_main, container, false)
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 |
36 | recyclerMangaTitles.adapter = adapter
37 | val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
38 | recyclerMangaTitles.layoutManager = layoutManager
39 | recyclerMangaTitles.addOnScrollListener(object : RecyclerView.OnScrollListener() {
40 |
41 | override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
42 | super.onScrolled(recyclerView, dx, dy)
43 | Logger.d(layoutManager.findLastCompletelyVisibleItemPosition())
44 | }
45 | })
46 |
47 | buttonGetMangas.setOnClickListener {
48 | showProgressBar()
49 |
50 | if (model.isFirstLoad) {
51 |
52 | model.getMangaList(20).observe(this, Observer { list ->
53 |
54 | adapter.submitList(list)
55 | hideProgressBar()
56 | })
57 |
58 | model.fetchMangaList()
59 | model.isFirstLoad = false
60 | } else
61 | model.getMangaList(20)
62 |
63 | }
64 | }
65 |
66 | override fun showProgressBar() {
67 |
68 | progressBar.visibility = View.VISIBLE
69 | }
70 |
71 | override fun hideProgressBar() {
72 |
73 | progressBar.visibility = View.GONE
74 | }
75 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/ui/main/MainView.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.ui.main
2 |
3 | /**
4 | * Created by Gian Patrick Quintana on 1/22/2018.
5 | */
6 | interface MainView {
7 |
8 | fun showProgressBar()
9 | fun hideProgressBar()
10 |
11 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/silverlotus/kmvvm/ui/main/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm.ui.main
2 |
3 | import android.arch.lifecycle.LiveData
4 | import android.arch.lifecycle.MutableLiveData
5 | import android.arch.paging.PagedList
6 | import com.silverlotus.kmvvm.base.BaseViewModel
7 | import com.silverlotus.kmvvm.repository.MangaRepository
8 | import com.silverlotus.kmvvm.room.entity.MangaEntity
9 | import org.kodein.di.generic.instance
10 |
11 | /**
12 | * Created by Gian Patrick Quintana on 1/22/2018.
13 | */
14 | class MainViewModel : BaseViewModel() {
15 |
16 | private val mangaRepository by instance()
17 | private var liveDaoMangaEntity: LiveData> = MutableLiveData()
18 |
19 | var isFirstLoad = true
20 |
21 | fun getMangaList(max: Int): LiveData> {
22 |
23 | liveDaoMangaEntity = mangaRepository.getMangaList(max)
24 |
25 | return liveDaoMangaEntity
26 | }
27 |
28 | fun fetchMangaList() = mangaRepository.fetchMangaList()
29 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
27 |
28 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_manga.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KMVVM
3 | Get Manga
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/silverlotus/kmvvm/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.silverlotus.kmvvm
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.support_library_version = '27.1.0'
5 | ext.kotlin_version = '1.2.31'
6 | ext.kodein_version = '5.0.0'
7 | ext.fuel_version = '1.12.1'
8 | ext.architecture_version = '1.1.1'
9 | repositories {
10 | google()
11 | jcenter()
12 | }
13 | dependencies {
14 | classpath 'com.android.tools.build:gradle:3.1.0'
15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16 |
17 | // NOTE: Do not place your application dependencies here; they belong
18 | // in the individual module build.gradle files
19 | }
20 | }
21 |
22 | allprojects {
23 | repositories {
24 | google()
25 | jcenter()
26 | maven { url 'https://dl.bintray.com/kodein-framework/Kodein-DI/' } /*TODO Remove once all Kodein dependencies is in jCenter*/
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HirogaKatageri/Android-Kotlin-MVVM-Template/bed2c27005f63ed2ae537be6be04feb02a6d99b3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 27 10:08:57 SGT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':api'
2 |
--------------------------------------------------------------------------------