├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── list_item_pokemon.xml
│ │ ├── kotlin
│ │ │ └── xyz
│ │ │ │ └── ivankocijan
│ │ │ │ └── kotlinexample
│ │ │ │ ├── mvp
│ │ │ │ ├── interactor
│ │ │ │ │ ├── BaseInteractor.kt
│ │ │ │ │ ├── PokemonListInteractor.kt
│ │ │ │ │ └── impl
│ │ │ │ │ │ └── PokemonListInteractorImpl.kt
│ │ │ │ ├── presenter
│ │ │ │ │ ├── BasePresenter.kt
│ │ │ │ │ ├── PokemonListPresenter.kt
│ │ │ │ │ └── impl
│ │ │ │ │ │ └── PokemonListPresenterImpl.kt
│ │ │ │ ├── listener
│ │ │ │ │ ├── BaseListener.kt
│ │ │ │ │ └── PokemonListListener.kt
│ │ │ │ └── view
│ │ │ │ │ ├── BaseView.kt
│ │ │ │ │ └── PokemonListView.kt
│ │ │ │ ├── model
│ │ │ │ └── PokeDex.kt
│ │ │ │ ├── dagger
│ │ │ │ ├── setup
│ │ │ │ │ ├── module
│ │ │ │ │ │ ├── GsonModule.kt
│ │ │ │ │ │ ├── LoggerModule.kt
│ │ │ │ │ │ ├── GsonConverterModule.kt
│ │ │ │ │ │ ├── HostModule.kt
│ │ │ │ │ │ ├── AppContextModule.kt
│ │ │ │ │ │ ├── RetrofitModule.kt
│ │ │ │ │ │ └── ClientModule.kt
│ │ │ │ │ └── component
│ │ │ │ │ │ └── AppComponent.kt
│ │ │ │ ├── component
│ │ │ │ │ └── PokemonListComponent.kt
│ │ │ │ └── module
│ │ │ │ │ └── PokemonListModule.kt
│ │ │ │ ├── PokemonService.kt
│ │ │ │ ├── Pokemon.kt
│ │ │ │ ├── extensions
│ │ │ │ └── PokemonExtensions.kt
│ │ │ │ ├── PokemonApplication.kt
│ │ │ │ ├── adapter
│ │ │ │ └── PokemonAdapter.kt
│ │ │ │ └── activities
│ │ │ │ ├── BaseActivity.kt
│ │ │ │ └── PokemonListActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── xyz
│ │ │ └── ivankocijan
│ │ │ └── kotlinexample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── xyz
│ │ └── ivankocijan
│ │ └── kotlinexample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ikocijan/Kotlin-Dagger2-Retrofit2-example/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KotlinExample
3 | Please wait…
4 | An error occured. Please try again
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/interactor/BaseInteractor.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.interactor
2 |
3 | /**
4 | * @author Koc
5 | * ivan.kocijan@infinum.hr
6 | * @since 20/03/16
7 | */
8 | interface BaseInteractor {
9 | fun cancel()
10 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/presenter/BasePresenter.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.presenter
2 |
3 | /**
4 | * @author Koc
5 | * ivan.kocijan@infinum.hr
6 | * @since 20/03/16
7 | */
8 | interface BasePresenter {
9 |
10 | fun cancel()
11 |
12 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/listener/BaseListener.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.listener
2 |
3 | /**
4 | * @author Koc
5 | * ivan.kocijan@infinum.hr
6 | * @since 20/03/16
7 | */
8 | interface BaseListener {
9 |
10 | fun onFailure(message: String)
11 |
12 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/presenter/PokemonListPresenter.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.presenter
2 |
3 | /**
4 | * @author Koc
5 | * ivan.kocijan@infinum.hr
6 | * @since 20/03/16
7 | */
8 | interface PokemonListPresenter : BasePresenter {
9 |
10 | fun loadPokemonList()
11 |
12 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/view/BaseView.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.view
2 |
3 | /**
4 | * @author Koc
5 | * ivan.kocijan@infinum.hr
6 | * @since 19/03/16
7 | */
8 | interface BaseView {
9 |
10 | fun showProgress()
11 |
12 | fun hideProgress()
13 |
14 | fun showMessage(message: String = "There has been an error")
15 |
16 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/view/PokemonListView.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.view
2 |
3 | import xyz.ivankocijan.kotlinexample.Pokemon
4 |
5 | /**
6 | * @author Koc
7 | * ivan.kocijan@infinum.hr
8 | * @since 20/03/16
9 | */
10 | interface PokemonListView : BaseView {
11 |
12 | fun showPokemonList(listItem: List)
13 |
14 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/model/PokeDex.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.model
2 |
3 | import com.google.gson.annotations.SerializedName
4 | import xyz.ivankocijan.kotlinexample.Pokemon
5 |
6 | /**
7 | * @author Koc
8 | * ivan.kocijan@infinum.hr
9 | * @since 20/03/16
10 | */
11 | data class PokeDex(@SerializedName("pokemon") val pokemonList: List)
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/listener/PokemonListListener.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.listener
2 |
3 | import xyz.ivankocijan.kotlinexample.model.PokeDex
4 |
5 | /**
6 | * @author Koc
7 | * ivan.kocijan@infinum.hr
8 | * @since 20/03/16
9 | */
10 | interface PokemonListListener : BaseListener {
11 |
12 | fun onSuccess(pokeDex: PokeDex)
13 |
14 | }
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Kotlin-Dagger2-Retrofit2-example
2 | An example project showing how to use Kotlin with Dagger 2 and Retrofit 2. It uses [Pokeapi](http://pokeapi.co/docsv2/) to show a list of pokemons with details(Details part still in progress).
3 |
4 | This is a port of another example project to Kotlin. If you want to check the original project, written in java, you can find it [here](https://github.com/infinum/Dagger-2-Example)
5 |
--------------------------------------------------------------------------------
/app/src/test/java/xyz/ivankocijan/kotlinexample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/interactor/PokemonListInteractor.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.interactor
2 |
3 | import xyz.ivankocijan.kotlinexample.mvp.listener.PokemonListListener
4 |
5 | /**
6 | * @author Koc
7 | * ivan.kocijan@infinum.hr
8 | * @since 20/03/16
9 | */
10 | interface PokemonListInteractor : BaseInteractor {
11 |
12 | fun loadPokemonList(pokemonListListener: PokemonListListener)
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/xyz/ivankocijan/kotlinexample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/GsonModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import com.google.gson.Gson
4 | import com.google.gson.GsonBuilder
5 | import dagger.Module
6 | import dagger.Provides
7 | import javax.inject.Singleton
8 |
9 | /**
10 | * @author Koc
11 | * ivan.kocijan@infinum.hr
12 | * @since 20/03/16
13 | */
14 | @Module
15 | class GsonModule {
16 |
17 | @Provides
18 | @Singleton
19 | fun provideGson(): Gson = GsonBuilder().create()
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/PokemonService.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample
2 |
3 | import retrofit2.Call
4 | import retrofit2.http.GET
5 | import retrofit2.http.Path
6 | import xyz.ivankocijan.kotlinexample.model.PokeDex
7 |
8 | /**
9 | * @author Koc
10 | * ivan.kocijan@infinum.hr
11 | * @since 20/03/16
12 | */
13 | interface PokemonService {
14 |
15 | @GET("/api/v1/pokedex/1") fun getPokedex(): Call
16 |
17 | @GET("/{resource_uri}") fun getPokemon(@Path("resource_uri") resourceUri: String): Call
18 |
19 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/component/PokemonListComponent.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.component
2 |
3 | import dagger.Subcomponent
4 | import xyz.ivankocijan.kotlinexample.activities.PokemonListActivity
5 | import xyz.ivankocijan.kotlinexample.dagger.module.PokemonListModule
6 |
7 | /**
8 | * @author Koc
9 | * ivan.kocijan@infinum.hr
10 | * @since 20/03/16
11 | */
12 | @Subcomponent (modules = arrayOf(PokemonListModule::class))
13 | interface PokemonListComponent {
14 |
15 | fun inject(pokemonListActivity: PokemonListActivity)
16 |
17 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/LoggerModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import okhttp3.logging.HttpLoggingInterceptor
6 | import timber.log.Timber
7 |
8 | /**
9 | * @author Koc
10 | * ivan.kocijan@infinum.hr
11 | * @since 20/03/16
12 | */
13 | @Module
14 | class LoggerModule {
15 |
16 | @Provides
17 | fun provideLogger(): HttpLoggingInterceptor {
18 | return HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { message -> Timber.d(message); })
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/GsonConverterModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import com.google.gson.Gson
4 | import dagger.Module
5 | import dagger.Provides
6 | import retrofit2.Converter
7 | import retrofit2.converter.gson.GsonConverterFactory
8 | import javax.inject.Singleton
9 |
10 | /**
11 | * @author Koc
12 | * ivan.kocijan@infinum.hr
13 | * @since 20/03/16
14 | */
15 | @Module
16 | class GsonConverterModule {
17 |
18 | @Provides
19 | @Singleton
20 | fun provideConverter(gson: Gson): Converter.Factory = GsonConverterFactory.create(gson)
21 |
22 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/HostModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import xyz.ivankocijan.kotlinexample.BuildConfig
6 | import javax.inject.Singleton
7 |
8 | /**
9 | * @author Koc
10 | * ivan.kocijan@infinum.hr
11 | * @since 20/03/16
12 | */
13 | @Module
14 | class HostModule {
15 |
16 | val NETWORK_TIMEOUT_SECONDS = 60L
17 |
18 | @Provides
19 | @Singleton
20 | fun provideNetworkTimeout(): Long = NETWORK_TIMEOUT_SECONDS
21 |
22 | @Provides
23 | @Singleton
24 | fun provideBaseUrl(): String = BuildConfig.API_URL
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/Pokemon.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample
2 |
3 | import com.google.gson.annotations.SerializedName
4 |
5 | /**
6 | * @author Koc
7 | * ivan.kocijan@infinum.hr
8 | * @since 20/03/16
9 | */
10 | data class Pokemon(@SerializedName("name") val name: String,
11 | @SerializedName("resource_uri") val resourceUri: String,
12 | @SerializedName("hp") val hp: String,
13 | @SerializedName("attack") val attack: String,
14 | @SerializedName("defense") val defense: String,
15 | @SerializedName("height") val height: String,
16 | @SerializedName("weight") val weight: String) {
17 |
18 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/koc/developer_tools/android_sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/AppContextModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import android.content.Context
4 | import android.content.res.Resources
5 | import dagger.Module
6 | import dagger.Provides
7 | import xyz.ivankocijan.kotlinexample.PokemonApplication
8 | import javax.inject.Singleton
9 |
10 | /**
11 | * @author Koc
12 | * ivan.kocijan@infinum.hr
13 | * @since 20/03/16
14 | */
15 | @Module
16 | class AppContextModule {
17 |
18 | @Provides
19 | @Singleton
20 | fun provideContext(): Context = PokemonApplication.instance
21 |
22 | @Provides
23 | @Singleton
24 | fun provideResources(context: Context): Resources = context.getResources()
25 |
26 | }
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/component/AppComponent.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.component
2 |
3 | import dagger.Component
4 | import xyz.ivankocijan.kotlinexample.dagger.component.PokemonListComponent
5 | import xyz.ivankocijan.kotlinexample.dagger.module.PokemonListModule
6 | import xyz.ivankocijan.kotlinexample.dagger.setup.module.*
7 | import javax.inject.Singleton
8 |
9 | /**
10 | * @author Koc
11 | * ivan.kocijan@infinum.hr
12 | * @since 20/03/16
13 | */
14 | @Singleton
15 | @Component(modules = arrayOf(
16 | AppContextModule::class,
17 | RetrofitModule::class,
18 | ClientModule::class,
19 | GsonConverterModule::class,
20 | GsonModule::class,
21 | HostModule::class,
22 | LoggerModule::class
23 | ))
24 | interface AppComponent {
25 |
26 | fun plus(pokemonListModule: PokemonListModule): PokemonListComponent
27 |
28 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/extensions/PokemonExtensions.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.extensions
2 |
3 | import android.content.Context
4 | import android.text.TextUtils
5 | import android.widget.Toast
6 | import xyz.ivankocijan.kotlinexample.Pokemon
7 |
8 | /**
9 | * @author Koc
10 | * ivan.kocijan@infinum.hr
11 | * @since 20/03/16
12 | */
13 |
14 | fun Pokemon.id(): Int {
15 |
16 | try {
17 | val tokens = TextUtils.split(resourceUri, "/")
18 | val id =
19 | if (TextUtils.isEmpty(tokens[tokens.size - 1])) {
20 | tokens[tokens.size - 2]
21 | } else {
22 | tokens[tokens.size - 1]
23 | }
24 | return Integer.parseInt(id)
25 | } catch (e: Exception) {
26 | return 0
27 | }
28 |
29 |
30 | }
31 |
32 | fun Context.myToast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
33 | Toast.makeText(this, message, duration).show()
34 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/PokemonApplication.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample
2 |
3 | import android.app.Application
4 | import timber.log.Timber
5 | import xyz.ivankocijan.kotlinexample.dagger.setup.component.AppComponent
6 | import xyz.ivankocijan.kotlinexample.dagger.setup.component.DaggerAppComponent
7 |
8 | /**
9 | * @author Koc
10 | * ivan.kocijan@infinum.hr
11 | * @since 20/03/16
12 | */
13 | class PokemonApplication : Application () {
14 |
15 | companion object {
16 | @JvmStatic lateinit var instance: PokemonApplication
17 | @JvmStatic lateinit var appComponent: AppComponent
18 | }
19 |
20 | override fun onCreate() {
21 | super.onCreate()
22 | Timber.plant(Timber.DebugTree())
23 | instance = this
24 | setupMainComponent();
25 |
26 |
27 | }
28 |
29 | private fun setupMainComponent() {
30 | appComponent = DaggerAppComponent.create();
31 | // appComponent = DaggerAppComponent.create()
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/RetrofitModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import okhttp3.OkHttpClient
6 | import retrofit2.Converter
7 | import retrofit2.Retrofit
8 | import xyz.ivankocijan.kotlinexample.PokemonService
9 | import javax.inject.Singleton
10 |
11 | /**
12 | * @author Koc
13 | * ivan.kocijan@infinum.hr
14 | * @since 20/03/16
15 | */
16 | @Module
17 | class RetrofitModule {
18 |
19 | @Provides
20 | @Singleton
21 | fun provideRetrofit(httpClient: OkHttpClient, baseUrl: String, converter: Converter.Factory): Retrofit {
22 |
23 | return Retrofit.Builder()
24 | .baseUrl(baseUrl)
25 | .addConverterFactory(converter)
26 | .client(httpClient).build()
27 |
28 | }
29 |
30 | @Provides
31 | @Singleton
32 | fun provideService(retrofit: Retrofit): PokemonService {
33 | return retrofit.create(PokemonService::class.java)
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_pokemon.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/setup/module/ClientModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.setup.module
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import okhttp3.OkHttpClient
6 | import okhttp3.logging.HttpLoggingInterceptor
7 | import xyz.ivankocijan.kotlinexample.BuildConfig
8 | import java.util.concurrent.TimeUnit
9 | import javax.inject.Singleton
10 |
11 | /**
12 | * @author Koc
13 | * ivan.kocijan@infinum.hr
14 | * @since 20/03/16
15 | */
16 | @Module
17 | class ClientModule {
18 |
19 | @Provides
20 | @Singleton
21 | fun provideClient(networkTimeoutSecond: Long, logger: HttpLoggingInterceptor): OkHttpClient {
22 |
23 | val okHttpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
24 | okHttpClientBuilder.readTimeout(networkTimeoutSecond, TimeUnit.SECONDS)
25 | okHttpClientBuilder.connectTimeout(networkTimeoutSecond, TimeUnit.SECONDS)
26 |
27 | if (BuildConfig.DEBUG) {
28 |
29 | logger.level = HttpLoggingInterceptor.Level.BODY
30 | okHttpClientBuilder.addInterceptor(logger)
31 | }
32 |
33 | return okHttpClientBuilder.build()
34 |
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/dagger/module/PokemonListModule.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.dagger.module
2 |
3 | import dagger.Module
4 | import dagger.Provides
5 | import xyz.ivankocijan.kotlinexample.mvp.interactor.PokemonListInteractor
6 | import xyz.ivankocijan.kotlinexample.mvp.interactor.impl.PokemonListInteractorImpl
7 | import xyz.ivankocijan.kotlinexample.mvp.presenter.PokemonListPresenter
8 | import xyz.ivankocijan.kotlinexample.mvp.presenter.impl.PokemonListPresenterImpl
9 | import xyz.ivankocijan.kotlinexample.mvp.view.PokemonListView
10 |
11 | /**
12 | * @author Koc
13 | * ivan.kocijan@infinum.hr
14 | * @since 20/03/16
15 | */
16 | @Module
17 | class PokemonListModule {
18 |
19 | val pokemonListView: PokemonListView
20 |
21 | constructor(pokemonListView: PokemonListView) {
22 | this.pokemonListView = pokemonListView
23 | }
24 |
25 | @Provides
26 | fun provideView(): PokemonListView = pokemonListView
27 |
28 | @Provides
29 | fun providePresenter(pokemonListPresenter: PokemonListPresenterImpl): PokemonListPresenter = pokemonListPresenter
30 |
31 | @Provides
32 | fun provideInteractor(pokemonListInteractor: PokemonListInteractorImpl): PokemonListInteractor = pokemonListInteractor
33 |
34 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/adapter/PokemonAdapter.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.adapter
2 |
3 | import android.content.Context
4 | import android.support.v7.widget.RecyclerView
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.TextView
9 | import butterknife.bindView
10 | import xyz.ivankocijan.kotlinexample.Pokemon
11 | import xyz.ivankocijan.kotlinexample.R
12 | import xyz.ivankocijan.kotlinexample.extensions.id
13 |
14 | /**
15 | * @author Koc
16 | * ivan.kocijan@infinum.hr
17 | * @since 20/03/16
18 | */
19 | class PokemonAdapter(val listItems: List, val contex: Context) : RecyclerView.Adapter() {
20 |
21 | override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
22 |
23 | val pokemon: Pokemon = listItems[position]
24 | holder?.name?.text = pokemon.name
25 | holder?.pokemonId?.text = "#" + pokemon.id()
26 |
27 | }
28 |
29 | override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder? {
30 | return ViewHolder(LayoutInflater.from(contex).inflate(R.layout.list_item_pokemon, parent, false));
31 | }
32 |
33 | override fun getItemCount(): Int {
34 | return listItems.size
35 | }
36 |
37 |
38 | class ViewHolder(internal var rootView: View) : RecyclerView.ViewHolder(rootView) {
39 |
40 | val name: TextView by bindView(R.id.pokemon_name)
41 |
42 | val pokemonId: TextView by bindView(R.id.pokemon_id)
43 |
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/activities/BaseActivity.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.activities
2 |
3 | import android.app.ProgressDialog
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import xyz.ivankocijan.kotlinexample.PokemonApplication
7 | import xyz.ivankocijan.kotlinexample.R
8 | import xyz.ivankocijan.kotlinexample.dagger.setup.component.AppComponent
9 | import xyz.ivankocijan.kotlinexample.mvp.view.BaseView
10 |
11 | /**
12 | * @author Koc
13 | * ivan.kocijan@infinum.hr
14 | * @since 19/03/16
15 | */
16 | abstract class BaseActivity : AppCompatActivity(), BaseView {
17 |
18 | abstract fun getActivityLayout(): Int
19 |
20 | abstract fun injectDependencies(appComponent : AppComponent)
21 |
22 | var progressDialog: ProgressDialog? = null
23 |
24 | override fun onCreate(savedInstanceState: Bundle?) {
25 | super.onCreate(savedInstanceState)
26 | setContentView(getActivityLayout())
27 | injectDependencies(PokemonApplication.appComponent)
28 | initProgressDialog()
29 |
30 | }
31 |
32 | private fun initProgressDialog() {
33 | progressDialog = ProgressDialog(this)
34 | progressDialog?.setProgressStyle(ProgressDialog.STYLE_SPINNER)
35 | progressDialog?.setMessage(getString(R.string.please_wait))
36 | }
37 |
38 | override fun showProgress() {
39 | progressDialog?.show();
40 | }
41 |
42 | override fun hideProgress() {
43 | progressDialog?.hide();
44 | }
45 |
46 | override fun showMessage(message: String) {
47 |
48 |
49 | }
50 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/activities/PokemonListActivity.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.activities
2 |
3 | import android.os.Bundle
4 | import android.support.v7.widget.LinearLayoutManager
5 | import android.support.v7.widget.RecyclerView
6 | import butterknife.bindView
7 | import xyz.ivankocijan.kotlinexample.Pokemon
8 | import xyz.ivankocijan.kotlinexample.R
9 | import xyz.ivankocijan.kotlinexample.adapter.PokemonAdapter
10 | import xyz.ivankocijan.kotlinexample.dagger.module.PokemonListModule
11 | import xyz.ivankocijan.kotlinexample.dagger.setup.component.AppComponent
12 | import xyz.ivankocijan.kotlinexample.mvp.presenter.PokemonListPresenter
13 | import xyz.ivankocijan.kotlinexample.mvp.view.PokemonListView
14 | import java.util.*
15 | import javax.inject.Inject
16 |
17 | class PokemonListActivity : BaseActivity(), PokemonListView {
18 |
19 | val pokemonListRv: RecyclerView by bindView(R.id.recycler_pokemon_list)
20 |
21 | lateinit var pokemonAdapter: PokemonAdapter
22 | var pokemonList: List = ArrayList()
23 |
24 | @Inject
25 | protected lateinit var presenter: PokemonListPresenter
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 |
30 | presenter.loadPokemonList()
31 |
32 | }
33 |
34 |
35 | override fun injectDependencies(appComponent: AppComponent) {
36 | appComponent.plus(PokemonListModule(this)).inject(this)
37 | }
38 |
39 | override fun getActivityLayout(): Int {
40 | return R.layout.activity_main;
41 | }
42 |
43 | override fun showPokemonList(listItems: List) {
44 | pokemonListRv.layoutManager = LinearLayoutManager(this)
45 | pokemonAdapter = PokemonAdapter(listItems, this)
46 | pokemonListRv.adapter = pokemonAdapter
47 | }
48 |
49 | override fun onStop() {
50 | super.onStop()
51 | presenter.cancel()
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/presenter/impl/PokemonListPresenterImpl.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.presenter.impl
2 |
3 | import xyz.ivankocijan.kotlinexample.Pokemon
4 | import xyz.ivankocijan.kotlinexample.extensions.id
5 | import xyz.ivankocijan.kotlinexample.model.PokeDex
6 | import xyz.ivankocijan.kotlinexample.mvp.interactor.PokemonListInteractor
7 | import xyz.ivankocijan.kotlinexample.mvp.listener.PokemonListListener
8 | import xyz.ivankocijan.kotlinexample.mvp.presenter.PokemonListPresenter
9 | import xyz.ivankocijan.kotlinexample.mvp.view.PokemonListView
10 | import java.util.*
11 | import javax.inject.Inject
12 |
13 | /**
14 | * @author Koc
15 | * ivan.kocijan@infinum.hr
16 | * @since 20/03/16
17 | */
18 | class PokemonListPresenterImpl : PokemonListPresenter {
19 |
20 | val pokemonListView: PokemonListView
21 |
22 | val pokemonListInteractor: PokemonListInteractor
23 |
24 | @Inject
25 | constructor(pokemonListView: PokemonListView, pokemonListInteractor: PokemonListInteractor) {
26 | this.pokemonListView = pokemonListView
27 | this.pokemonListInteractor = pokemonListInteractor
28 | }
29 |
30 | override fun loadPokemonList() {
31 |
32 | pokemonListView.showProgress()
33 |
34 | pokemonListInteractor.loadPokemonList(object : PokemonListListener {
35 |
36 | override fun onSuccess(pokeDex: PokeDex) {
37 |
38 | val pokemonList: List = pokeDex.pokemonList
39 |
40 | Collections.sort(pokemonList) { x, y -> x.id() - y.id() }
41 |
42 | pokemonListView.showPokemonList(pokeDex.pokemonList)
43 | pokemonListView.hideProgress()
44 | }
45 |
46 | override fun onFailure(message: String) {
47 | pokemonListView.hideProgress()
48 | pokemonListView.showMessage(message)
49 |
50 | }
51 | })
52 |
53 |
54 | }
55 |
56 | override fun cancel() {
57 | pokemonListInteractor.cancel()
58 | }
59 |
60 | }
--------------------------------------------------------------------------------
/app/src/main/kotlin/xyz/ivankocijan/kotlinexample/mvp/interactor/impl/PokemonListInteractorImpl.kt:
--------------------------------------------------------------------------------
1 | package xyz.ivankocijan.kotlinexample.mvp.interactor.impl
2 |
3 |
4 | import android.content.Context
5 | import retrofit2.Call
6 | import retrofit2.Callback
7 | import retrofit2.Response
8 | import retrofit2.Retrofit
9 | import xyz.ivankocijan.kotlinexample.PokemonService
10 | import xyz.ivankocijan.kotlinexample.R
11 | import xyz.ivankocijan.kotlinexample.model.PokeDex
12 | import xyz.ivankocijan.kotlinexample.mvp.interactor.PokemonListInteractor
13 | import xyz.ivankocijan.kotlinexample.mvp.listener.PokemonListListener
14 | import javax.inject.Inject
15 |
16 | /**
17 | * @author Koc
18 | * ivan.kocijan@infinum.hr
19 | * @since 20/03/16
20 | */
21 | class PokemonListInteractorImpl : PokemonListInteractor {
22 |
23 | val retrofit: Retrofit
24 |
25 | val pokemonService: PokemonService
26 |
27 | val appContext: Context
28 |
29 | lateinit var call: Call
30 |
31 | @Inject
32 | constructor(retrofit: Retrofit, pokemonService: PokemonService, appContext: Context) {
33 | this.retrofit = retrofit
34 | this.pokemonService = pokemonService
35 | this.appContext = appContext
36 | }
37 |
38 |
39 | override fun loadPokemonList(pokemonListListener: PokemonListListener) {
40 |
41 |
42 | call = pokemonService.getPokedex();
43 | call.enqueue(object : Callback {
44 | override fun onResponse(call: Call?, response: Response?) {
45 |
46 | if (response != null && response.isSuccessful) {
47 | pokemonListListener.onSuccess(response.body())
48 | } else {
49 | pokemonListListener.onFailure(appContext.getString(R.string.error_fetching_data))
50 | }
51 |
52 |
53 | }
54 |
55 | override fun onFailure(call: Call?, t: Throwable?) {
56 | pokemonListListener.onFailure(appContext.getString(R.string.error_fetching_data))
57 | }
58 | })
59 |
60 |
61 | }
62 |
63 | override fun cancel() {
64 | call.cancel()
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io
2 |
3 | ### OSX ###
4 | .DS_Store
5 | .AppleDouble
6 | .LSOverride
7 |
8 | # Icon must end with two \r
9 | Icon
10 |
11 |
12 | # Thumbnails
13 | ._*
14 |
15 | # Files that might appear in the root of a volume
16 | .DocumentRevisions-V100
17 | .fseventsd
18 | .Spotlight-V100
19 | .TemporaryItems
20 | .Trashes
21 | .VolumeIcon.icns
22 |
23 | # Directories potentially created on remote AFP share
24 | .AppleDB
25 | .AppleDesktop
26 | Network Trash Folder
27 | Temporary Items
28 | .apdisk
29 |
30 |
31 | ### Android ###
32 | # Built application files
33 | *.apk
34 | *.ap_
35 |
36 | # Files for the Dalvik VM
37 | *.dex
38 |
39 | # Java class files
40 | *.class
41 |
42 | # Generated files
43 | bin/
44 | gen/
45 |
46 | # Gradle files
47 | .gradle/
48 | build/
49 | /*/build/
50 |
51 | # Local configuration file (sdk path, etc)
52 | local.properties
53 |
54 | # Proguard folder generated by Eclipse
55 | proguard/
56 |
57 | # Log Files
58 | *.log
59 |
60 | ### Android Patch ###
61 | gen-external-apklibs
62 |
63 |
64 | ### Intellij ###
65 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
66 |
67 | *.iml
68 |
69 | ## Directory-based project format:
70 | .idea/
71 | # if you remove the above rule, at least ignore the following:
72 |
73 | # User-specific stuff:
74 | # .idea/workspace.xml
75 | # .idea/tasks.xml
76 | # .idea/dictionaries
77 |
78 | # Sensitive or high-churn files:
79 | # .idea/dataSources.ids
80 | # .idea/dataSources.xml
81 | # .idea/sqlDataSources.xml
82 | # .idea/dynamic.xml
83 | # .idea/uiDesigner.xml
84 |
85 | # Gradle:
86 | # .idea/gradle.xml
87 | # .idea/libraries
88 |
89 | # Mongo Explorer plugin:
90 | # .idea/mongoSettings.xml
91 |
92 | ## File-based project format:
93 | *.ipr
94 | *.iws
95 |
96 | ## Plugin-specific files:
97 |
98 | # IntelliJ
99 | /out/
100 |
101 | # mpeltonen/sbt-idea plugin
102 | .idea_modules/
103 |
104 | # JIRA plugin
105 | atlassian-ide-plugin.xml
106 |
107 | # Crashlytics plugin (for Android Studio and IntelliJ)
108 | com_crashlytics_export_strings.xml
109 | crashlytics.properties
110 | crashlytics-build.properties
111 |
112 | # Proguard
113 | app/class_files.txt
114 | app/mapping.txt
115 | app/seeds.txt
116 | app/unused.txt
117 |
118 | # Profiler output
119 | *.hprof
120 | captures/
121 |
122 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "23.0.2"
8 |
9 |
10 | def API_URL = 'API_URL'
11 | def STRING = 'String'
12 |
13 | defaultConfig {
14 | applicationId "xyz.ivankocijan.kotlinexample"
15 | minSdkVersion 15
16 | targetSdkVersion 23
17 | versionCode 1
18 | versionName "1.0"
19 | buildConfigField STRING, API_URL, '"http://pokeapi.co/"'
20 |
21 | }
22 |
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_7
25 | targetCompatibility JavaVersion.VERSION_1_7
26 | }
27 |
28 | buildTypes {
29 | release {
30 | minifyEnabled false
31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
32 | }
33 | }
34 | sourceSets {
35 | main.java.srcDirs += 'src/main/kotlin'
36 | androidTest.java.srcDirs += 'src/androidTest/kotlin'
37 | }
38 | }
39 |
40 | kapt {
41 | generateStubs = true
42 | }
43 |
44 | dependencies {
45 | compile fileTree(dir: 'libs', include: ['*.jar'])
46 | testCompile 'junit:junit:4.12'
47 | compile 'com.android.support:appcompat-v7:23.2.1'
48 | compile 'com.android.support:recyclerview-v7:23.2.1'
49 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
50 |
51 | compile "org.jetbrains.anko:anko-common:0.8.3"
52 |
53 | compile 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
54 |
55 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
56 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
57 | compile 'com.squareup.retrofit2:retrofit:2.0.0'
58 | compile 'com.squareup.retrofit2:converter-gson:2.0.0'
59 | compile 'com.google.code.gson:gson:2.4'
60 |
61 | compile 'com.jakewharton.timber:timber:4.1.1'
62 | compile 'javax.inject:javax.inject:1'
63 |
64 | compile 'com.google.dagger:dagger:2.0.2'
65 | kapt 'com.google.dagger:dagger-compiler:2.0.2'
66 | compile 'org.glassfish:javax.annotation:10.0-b28'
67 |
68 | }
69 | buildscript {
70 | ext.kotlin_version = '1.0.1'
71 | repositories {
72 | mavenCentral()
73 | }
74 | dependencies {
75 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
76 | }
77 | }
78 | repositories {
79 | mavenCentral()
80 | }
81 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------