├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── font
│ │ │ │ ├── manropemedium.ttf
│ │ │ │ └── manroperegular.ttf
│ │ │ ├── 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
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── single_row.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── main_detail.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tayfuncesur
│ │ │ │ └── assistedinjection
│ │ │ │ ├── model
│ │ │ │ ├── CivilizationList.kt
│ │ │ │ └── Civilization.kt
│ │ │ │ ├── state
│ │ │ │ └── Resource.kt
│ │ │ │ ├── di
│ │ │ │ ├── DaggerComponentProvider.kt
│ │ │ │ ├── module
│ │ │ │ │ ├── UIModule.kt
│ │ │ │ │ ├── NetworkModule.kt
│ │ │ │ │ └── PresentationModule.kt
│ │ │ │ ├── ViewModelExt.kt
│ │ │ │ ├── ViewModelFactory.kt
│ │ │ │ └── AppComponent.kt
│ │ │ │ ├── network
│ │ │ │ └── Service.kt
│ │ │ │ ├── App.kt
│ │ │ │ └── ui
│ │ │ │ ├── mainDetail
│ │ │ │ ├── MainDetailActivity.kt
│ │ │ │ └── MainDetailViewModel.kt
│ │ │ │ └── main
│ │ │ │ ├── MainViewModel.kt
│ │ │ │ ├── MainAdapter.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── tayfuncesur
│ │ │ └── assistedinjection
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── tayfuncesur
│ │ └── assistedinjection
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── encodings.xml
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── vcs.xml
├── misc.xml
├── runConfigurations.xml
└── gradle.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/font/manropemedium.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/font/manropemedium.ttf
--------------------------------------------------------------------------------
/app/src/main/res/font/manroperegular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/font/manroperegular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TayfunCesur/AssistedInjection/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/model/CivilizationList.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.model
2 |
3 | class CivilizationList(val civilizations: List)
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AssistedInjection
3 | Selected_civilization
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun May 12 18:34:32 EET 2019
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.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/state/Resource.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.state
2 |
3 | sealed class Resource {
4 | class Loading : Resource()
5 | data class Success(val data: T?) : Resource()
6 | data class Failure(val cause: String?) : Resource()
7 | }
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/DaggerComponentProvider.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di
2 |
3 | import android.app.Activity
4 |
5 | interface DaggerComponentProvider {
6 |
7 | val component: AppComponent
8 | }
9 |
10 | val Activity.injector get() = (application as DaggerComponentProvider).component
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/model/Civilization.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.model
2 |
3 | data class Civilization(
4 | val army_type: String,
5 | val civilization_bonus: List,
6 | val expansion: String,
7 | val id: Int,
8 | val name: String,
9 | val team_bonus: String,
10 | val unique_tech: List,
11 | val unique_unit: List
12 | )
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/module/UIModule.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di.module
2 |
3 | import com.tayfuncesur.assistedinjection.ui.main.MainActivity
4 | import dagger.Module
5 | import dagger.android.ContributesAndroidInjector
6 |
7 | @Module
8 | abstract class UIModule {
9 |
10 | @ContributesAndroidInjector
11 | abstract fun bindMainActivity() : MainActivity
12 |
13 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tayfuncesur/assistedinjection/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection
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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/network/Service.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.network
2 |
3 | import com.tayfuncesur.assistedinjection.model.Civilization
4 | import com.tayfuncesur.assistedinjection.model.CivilizationList
5 | import io.reactivex.Observable
6 | import retrofit2.http.GET
7 | import retrofit2.http.Path
8 |
9 | interface Service {
10 |
11 | @GET("v1/civilizations")
12 | fun getCivilizations(): Observable
13 |
14 | @GET("v1/civilization/{id}")
15 | fun getCivilizationDetail(@Path(value = "id", encoded = true) id: Int): Observable
16 |
17 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tayfuncesur/assistedinjection/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection
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.tayfuncesur.assistedinjection", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/ViewModelExt.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di
2 |
3 | import android.arch.lifecycle.ViewModel
4 | import android.arch.lifecycle.ViewModelProvider
5 | import android.arch.lifecycle.ViewModelProviders
6 | import android.support.v7.app.AppCompatActivity
7 |
8 |
9 | @Suppress("UNCHECKED_CAST")
10 | inline fun AppCompatActivity.getViewModel(crossinline factory: () -> T) = T::class.java.let {
11 | ViewModelProviders.of(this, object : ViewModelProvider.Factory {
12 | override fun create(modelClass: Class) = factory() as T
13 | }).get(it)
14 | }
15 |
16 | inline fun viewModel(activity: AppCompatActivity, crossinline initializer: () -> T) =
17 | lazy(LazyThreadSafetyMode.NONE) { activity.getViewModel { initializer() } }
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # Kotlin code style for this project: "official" or "obsolete":
15 | kotlin.code.style=official
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/module/NetworkModule.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di.module
2 |
3 | import com.google.gson.Gson
4 | import com.tayfuncesur.assistedinjection.network.Service
5 | import dagger.Module
6 | import dagger.Provides
7 | import retrofit2.Retrofit
8 | import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
9 | import retrofit2.converter.gson.GsonConverterFactory
10 | import javax.inject.Singleton
11 |
12 | @Module
13 | object NetworkModule {
14 |
15 | @Provides
16 | @Singleton
17 | @JvmStatic
18 | fun providesRetrofit() : Service{
19 | val retrofit = Retrofit.Builder()
20 | .baseUrl("https://age-of-empires-2-api.herokuapp.com/api/")
21 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
22 | .addConverterFactory(GsonConverterFactory.create(Gson()))
23 | .build()
24 | return retrofit.create(Service::class.java)
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/module/PresentationModule.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di.module
2 |
3 | import android.arch.lifecycle.ViewModel
4 | import android.arch.lifecycle.ViewModelProvider
5 | import com.tayfuncesur.assistedinjection.di.ViewModelFactory
6 | import com.tayfuncesur.assistedinjection.ui.main.MainViewModel
7 | import com.tayfuncesur.assistedinjection.ui.mainDetail.MainDetailViewModel
8 | import dagger.Binds
9 | import dagger.MapKey
10 | import dagger.Module
11 | import dagger.multibindings.IntoMap
12 | import kotlin.reflect.KClass
13 |
14 | @Module
15 | abstract class PresentationModule {
16 |
17 | @Binds
18 | @IntoMap
19 | @ViewModelKey(MainViewModel::class)
20 | abstract fun bindMainViewModel(
21 | mainDetailViewModel: MainViewModel
22 | ): ViewModel
23 |
24 |
25 | @Binds
26 | abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory
27 | }
28 |
29 |
30 | @Target(AnnotationTarget.FUNCTION)
31 | @Retention(AnnotationRetention.RUNTIME)
32 | @MapKey
33 | annotation class ViewModelKey(val value: KClass)
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/App.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection
2 |
3 | import android.app.Activity
4 | import android.app.Application
5 | import com.tayfuncesur.assistedinjection.di.AppComponent
6 | import com.tayfuncesur.assistedinjection.di.DaggerAppComponent
7 | import com.tayfuncesur.assistedinjection.di.DaggerComponentProvider
8 | import dagger.android.AndroidInjector
9 | import dagger.android.DispatchingAndroidInjector
10 | import dagger.android.HasActivityInjector
11 | import javax.inject.Inject
12 |
13 | class App : Application(), DaggerComponentProvider, HasActivityInjector {
14 |
15 | @Inject
16 | lateinit var androidInjector: DispatchingAndroidInjector
17 |
18 | override fun activityInjector(): AndroidInjector {
19 | return androidInjector
20 | }
21 |
22 |
23 | override val component: AppComponent
24 | get() = DaggerAppComponent
25 | .builder()
26 | .application(this)
27 | .build()
28 |
29 | override fun onCreate() {
30 | super.onCreate()
31 | component.inject(this)
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/single_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/ViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di
2 |
3 | import android.arch.lifecycle.ViewModel
4 | import android.arch.lifecycle.ViewModelProvider
5 | import dagger.MapKey
6 | import javax.inject.Inject
7 | import javax.inject.Provider
8 | import javax.inject.Singleton
9 | import kotlin.reflect.KClass
10 |
11 | @Suppress("UNCHECKED_CAST")
12 | @Singleton
13 | open class ViewModelFactory @Inject constructor(
14 | private val creators: Map,
15 | @JvmSuppressWildcards Provider>
16 | ) : ViewModelProvider.Factory {
17 |
18 | override fun create(modelClass: Class): T {
19 | var creator: Provider? = creators[modelClass]
20 | if (creator == null) {
21 | for ((key, value) in creators) {
22 | if (modelClass.isAssignableFrom(key)) {
23 | creator = value
24 | break
25 | }
26 | }
27 | }
28 | if (creator == null) {
29 | throw IllegalStateException("Unknown model class: $modelClass")
30 | }
31 | try {
32 | return creator.get() as T
33 | } catch (e: Exception) {
34 | throw RuntimeException(e)
35 | }
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/di/AppComponent.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.di
2 |
3 | import android.app.Application
4 | import com.squareup.inject.assisted.dagger2.AssistedModule
5 | import com.tayfuncesur.assistedinjection.App
6 | import com.tayfuncesur.assistedinjection.di.module.NetworkModule
7 | import com.tayfuncesur.assistedinjection.di.module.PresentationModule
8 | import com.tayfuncesur.assistedinjection.di.module.UIModule
9 | import com.tayfuncesur.assistedinjection.ui.mainDetail.MainDetailViewModel
10 | import dagger.BindsInstance
11 | import dagger.Component
12 | import dagger.Module
13 | import dagger.android.AndroidInjectionModule
14 | import javax.inject.Singleton
15 |
16 | @Singleton
17 | @Component(modules = [UIModule::class, AndroidInjectionModule::class, PresentationModule::class, NetworkModule::class, AssistedInjectModule::class])
18 | interface AppComponent {
19 |
20 |
21 | @Component.Builder
22 | interface Builder {
23 | @BindsInstance
24 | fun application(application: Application): Builder
25 |
26 | fun build(): AppComponent
27 | }
28 |
29 | val mainDetailViewModelFactory: MainDetailViewModel.Factory
30 |
31 | fun inject(app: App)
32 |
33 |
34 | }
35 |
36 | @AssistedModule
37 | @Module(includes = [AssistedInject_AssistedInjectModule::class])
38 | interface AssistedInjectModule
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/main_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
18 |
19 |
20 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/ui/mainDetail/MainDetailActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.ui.mainDetail
2 |
3 | import android.arch.lifecycle.Observer
4 | import android.os.Bundle
5 | import android.support.v7.app.AppCompatActivity
6 | import android.view.View
7 | import com.tayfuncesur.assistedinjection.R
8 | import com.tayfuncesur.assistedinjection.di.injector
9 | import com.tayfuncesur.assistedinjection.di.viewModel
10 | import com.tayfuncesur.assistedinjection.state.Resource
11 | import kotlinx.android.synthetic.main.main_detail.*
12 |
13 | class MainDetailActivity : AppCompatActivity() {
14 |
15 | private val mainDetailViewModel by viewModel(this) {
16 | injector.mainDetailViewModelFactory.create(intent.getIntExtra(getString(R.string.selected_civilization), -1))
17 | }
18 |
19 | override fun onCreate(savedInstanceState: Bundle?) {
20 | super.onCreate(savedInstanceState)
21 | setContentView(R.layout.main_detail)
22 |
23 | mainDetailViewModel.liveData.observe(this, Observer {
24 | if (it is Resource.Success) {
25 | var string = ""
26 | if (it.data != null) {
27 | string =
28 | " ${it.data.name} \n Expainsion: ${it.data.expansion} \n Army Type: ${it.data.army_type} \n Team Bonus: ${it.data.team_bonus}"
29 | }
30 | detail.text = string
31 | }
32 | progress.visibility = if (it is Resource.Loading) View.VISIBLE else View.GONE
33 | })
34 |
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/ui/main/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.ui.main
2 |
3 | import android.arch.lifecycle.MutableLiveData
4 | import android.arch.lifecycle.ViewModel
5 | import com.tayfuncesur.assistedinjection.model.Civilization
6 | import com.tayfuncesur.assistedinjection.network.Service
7 | import com.tayfuncesur.assistedinjection.state.Resource
8 | import io.reactivex.android.schedulers.AndroidSchedulers
9 | import io.reactivex.disposables.CompositeDisposable
10 | import io.reactivex.schedulers.Schedulers
11 | import javax.inject.Inject
12 |
13 | class MainViewModel @Inject constructor(
14 | private val service: Service
15 | ) : ViewModel() {
16 |
17 | private val compositeDisposable = CompositeDisposable()
18 |
19 | val liveData: MutableLiveData>> = MutableLiveData()
20 |
21 | init {
22 | loadCivilizations()
23 | }
24 |
25 | private fun loadCivilizations() {
26 | liveData.postValue(Resource.Loading())
27 | compositeDisposable.add(
28 | service.getCivilizations()
29 | .subscribeOn(Schedulers.io())
30 | .observeOn(AndroidSchedulers.mainThread())
31 | .subscribe({
32 | liveData.postValue(Resource.Success(it.civilizations))
33 | }, {
34 | liveData.postValue(Resource.Failure(it.localizedMessage))
35 | })
36 | )
37 | }
38 |
39 | override fun onCleared() {
40 | compositeDisposable.clear()
41 | super.onCleared()
42 | }
43 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/ui/main/MainAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.ui.main
2 |
3 | import android.graphics.Color
4 | import android.support.v7.widget.RecyclerView
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import com.tayfuncesur.assistedinjection.R
9 | import com.tayfuncesur.assistedinjection.model.Civilization
10 | import com.thekhaeng.pushdownanim.PushDownAnim
11 | import kotlinx.android.synthetic.main.single_row.view.*
12 |
13 | class MainAdapter(val list: List, val onClick: (Civilization) -> Unit) :
14 | RecyclerView.Adapter() {
15 | override fun onCreateViewHolder(p0: ViewGroup, p1: Int): SingleRow {
16 | return SingleRow(LayoutInflater.from(p0.context).inflate(R.layout.single_row, p0, false))
17 | }
18 |
19 | override fun getItemCount(): Int {
20 | return list.size
21 | }
22 |
23 | override fun onBindViewHolder(p0: SingleRow, p1: Int) {
24 | p0.bind(p1)
25 | }
26 |
27 |
28 | inner class SingleRow(private val view: View) : RecyclerView.ViewHolder(view) {
29 |
30 | fun bind(pos: Int) {
31 | if (pos % 2 == 0) {
32 | view.mainRow.setBackgroundColor(Color.parseColor("#FFFFFF"))
33 | } else {
34 | view.mainRow.setBackgroundColor(Color.parseColor("#E0E0E0"))
35 | }
36 |
37 | view.name.text = list[pos].name
38 |
39 | PushDownAnim.setPushDownAnimTo(view.mainRow).setScale(PushDownAnim.MODE_STATIC_DP, 5F).setOnClickListener {
40 | onClick.invoke(list[pos])
41 | }
42 |
43 | }
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/ui/main/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.ui.main
2 |
3 | import android.arch.lifecycle.Observer
4 | import android.arch.lifecycle.ViewModelProviders
5 | import android.content.Intent
6 | import android.support.v7.app.AppCompatActivity
7 | import android.os.Bundle
8 | import com.tayfuncesur.assistedinjection.R
9 | import com.tayfuncesur.assistedinjection.di.ViewModelFactory
10 | import com.tayfuncesur.assistedinjection.di.injector
11 | import com.tayfuncesur.assistedinjection.di.viewModel
12 | import com.tayfuncesur.assistedinjection.state.Resource
13 | import com.tayfuncesur.assistedinjection.ui.mainDetail.MainDetailActivity
14 | import dagger.android.AndroidInjection
15 | import kotlinx.android.synthetic.main.activity_main.*
16 | import javax.inject.Inject
17 |
18 | class MainActivity : AppCompatActivity() {
19 |
20 | @Inject
21 | lateinit var viewModelFactory: ViewModelFactory
22 |
23 | private lateinit var mainViewModel: MainViewModel
24 |
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | AndroidInjection.inject(this)
28 | setContentView(R.layout.activity_main)
29 |
30 |
31 | mainViewModel = ViewModelProviders.of(this, viewModelFactory).get(MainViewModel::class.java)
32 |
33 | mainViewModel.liveData.observe(this, Observer { it ->
34 | if (it is Resource.Success) {
35 | val mainAdapter = MainAdapter(it.data!!) {
36 | val intent = Intent(this@MainActivity, MainDetailActivity::class.java)
37 | intent.putExtra(getString(R.string.selected_civilization), it.id)
38 | startActivity(intent)
39 | }
40 | mainRecycler.adapter = mainAdapter
41 | }
42 | })
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tayfuncesur/assistedinjection/ui/mainDetail/MainDetailViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.tayfuncesur.assistedinjection.ui.mainDetail
2 |
3 | import android.arch.lifecycle.MutableLiveData
4 | import android.arch.lifecycle.ViewModel
5 | import com.squareup.inject.assisted.Assisted
6 | import com.squareup.inject.assisted.AssistedInject
7 | import com.tayfuncesur.assistedinjection.model.Civilization
8 | import com.tayfuncesur.assistedinjection.network.Service
9 | import com.tayfuncesur.assistedinjection.state.Resource
10 | import io.reactivex.android.schedulers.AndroidSchedulers
11 | import io.reactivex.disposables.CompositeDisposable
12 | import io.reactivex.schedulers.Schedulers
13 |
14 | class MainDetailViewModel @AssistedInject constructor(
15 | private val service: Service,
16 | @Assisted val civilizationId: Int
17 | ) : ViewModel() {
18 |
19 | @AssistedInject.Factory
20 | interface Factory {
21 | fun create(civilizationId: Int): MainDetailViewModel
22 | }
23 |
24 | private val compositeDisposable = CompositeDisposable()
25 |
26 | val liveData: MutableLiveData> = MutableLiveData()
27 |
28 | init {
29 | loadData()
30 | }
31 |
32 | private fun loadData() {
33 | liveData.postValue(Resource.Loading())
34 | compositeDisposable.add(
35 | service.getCivilizationDetail(civilizationId)
36 | .subscribeOn(Schedulers.io())
37 | .observeOn(AndroidSchedulers.mainThread())
38 | .subscribe({
39 | liveData.postValue(Resource.Success(it))
40 | }, {
41 | liveData.postValue(Resource.Failure(it.localizedMessage))
42 | })
43 | )
44 | }
45 |
46 | override fun onCleared() {
47 | compositeDisposable.clear()
48 | super.onCleared()
49 | }
50 |
51 |
52 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/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 28
11 | defaultConfig {
12 | applicationId "com.tayfuncesur.assistedinjection"
13 | minSdkVersion 16
14 | targetSdkVersion 28
15 | versionCode 1
16 | versionName "1.0"
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 |
29 | // Architecture components
30 | implementation 'android.arch.lifecycle:extensions:1.1.1'
31 |
32 | //Dagger
33 | implementation 'com.google.dagger:dagger:2.19'
34 | kapt 'com.google.dagger:dagger-compiler:2.19'
35 | implementation "com.google.dagger:dagger-android:2.19"
36 | implementation "com.google.dagger:dagger-android-support:2.19"
37 | kapt "com.google.dagger:dagger-android-processor:2.19"
38 | compileOnly "org.glassfish:javax.annotation:3.1.1"
39 | compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.3.3'
40 | kapt 'com.squareup.inject:assisted-inject-processor-dagger2:0.3.3'
41 |
42 | //Retrofit
43 | implementation "com.squareup.retrofit2:retrofit:2.5.0"
44 | implementation "com.squareup.retrofit2:adapter-rxjava2:2.5.0"
45 | implementation "com.squareup.retrofit2:converter-gson:2.4.0"
46 | implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
47 |
48 | //Rx
49 | implementation "io.reactivex.rxjava2:rxjava:2.2.6"
50 | implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
51 | implementation "io.reactivex.rxjava2:rxkotlin:2.3.0"
52 |
53 |
54 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
55 | implementation 'com.android.support:appcompat-v7:28.0.0'
56 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
57 | implementation 'com.android.support:recyclerview-v7:28.0.0'
58 | implementation ('com.github.thekhaeng:pushdown-anim-click:1.1.1') {
59 | exclude group: 'com.android.support'
60 | }
61 |
62 |
63 |
64 | testImplementation 'junit:junit:4.12'
65 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
66 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
67 | }
68 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Assisted Injection
2 | Have your ever need to pass some additional parameter into your Viewmodel? But wait, your viewmodel have already some injections? So how can you do this ?
3 |
4 | ***Behold Assisted Injection!***
5 |
6 |
7 |
8 | ### Main use case of Assisted Injection
9 | Here is the main usage. As you can see on the right preview, we have two viewmodel and the second one needs some id of previous selected data. But the second viewmodel has already constructor injections like below.
10 |
11 | ```
12 | class MainDetailViewModel @Inject constructor(
13 | private val service: Service
14 | ) : ViewModel() {
15 | //Some magic works here
16 | }
17 | ```
18 |
19 | So how can we do this? Because if we pass the parameter in constructor of viewmodel, the constructor injection magic will be pointless and force us to make much boilerplate code.
20 |
21 | ## Assisted Inject Constructor
22 | AssistedInject annotations helps us to pass some additional parameters with already constructor injections we did before. Here is the usage,
23 |
24 | ```
25 | class MainDetailViewModel @AssistedInject constructor(
26 | private val service: Service,
27 | @Assisted val civilizationId: Int //Magic here :)
28 | ) : ViewModel() {
29 |
30 | @AssistedInject.Factory
31 | interface Factory {
32 | fun create(civilizationId: Int): MainDetailViewModel
33 | }
34 | // Some magic works here
35 | }
36 | ```
37 |
38 | ## Providing the factory
39 | If we will use this parameter that we passed via @Assisted, we must provide this as usual. Here is the sample usage,
40 | ```
41 | //Our id comes from intent here
42 |
43 | private val mainDetailViewModel by viewModel(this) {
44 | injector.mainDetailViewModelFactory.create(
45 | intent.getIntExtra(getString(R.string.selected_civilization), -1))
46 | }
47 | ```
48 | # Keynotes
49 |
50 | ### Usage in Multi-module project
51 | As far as I tried, in multi-module project, for example you have some presentation layer that contains your Viewmodels, because of your ***@AssistedInject.Factory*** is generated in your Presentation module and you want to use in UI module which is your main layer, Dagger2 can not access that factory class which is generated in other module. I still search the solution. If you know the problem or you have any questions, hit me on [Twitter](https://twitter.com/CesurTayfun35)
52 |
53 | # Core Libraries
54 | - [Android Architecture Components](https://developer.android.com/topic/libraries/architecture/)
55 | - [Dagger2](https://google.github.io/dagger/)
56 | - [Dagger Assisted Inject](https://github.com/square/AssistedInject)
57 | - [Rx2](https://github.com/ReactiveX/RxJava)
58 | - [Retrofit2](http://square.github.io/retrofit/)
59 |
60 |
61 | # Summary
62 | If you have Viewmodels that have already use constructor injection and you need to pass additional parameter through them, ***[Assisted Injection](https://github.com/square/AssistedInject)*** is all you ever need. Please have a look! If you have any question why we need to pass the parameter via constructor, please try to rotate your phone and you will see you make network request again. ***Because you should make your request in your ViewModel's init function.***
63 |
64 | ### Greetings
65 | If you have any questions, hit me on [Twitter](https://twitter.com/CesurTayfun35)
66 |
67 | ## Licence
68 | ```
69 | Copyright 2019 Tayfun CESUR
70 |
71 | Licensed under the Apache License, Version 2.0 (the "License");
72 | you may not use this file except in compliance with the License.
73 | You may obtain a copy of the License at
74 |
75 | http://www.apache.org/licenses/LICENSE-2.0
76 |
77 | Unless required by applicable law or agreed to in writing, software
78 | distributed under the License is distributed on an "AS IS" BASIS,
79 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
80 | See the License for the specific language governing permissions and
81 | limitations under the License.
82 | ```
83 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------