├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── farshidabz │ │ └── gettingstartkoin │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── farshidabz │ │ │ └── gettingstartkoin │ │ │ ├── GettingStartApplication.kt │ │ │ ├── data │ │ │ ├── model │ │ │ │ └── PicSumResponseModel.kt │ │ │ ├── remote │ │ │ │ └── ImagesApi.kt │ │ │ └── repository │ │ │ │ └── ImagesRepo.kt │ │ │ ├── di │ │ │ ├── AppInjector.kt │ │ │ ├── NetworkModule.kt │ │ │ ├── RepositoryModule.kt │ │ │ └── ViewModelModule.kt │ │ │ ├── utils │ │ │ ├── LocationHandler.kt │ │ │ ├── extentions │ │ │ │ └── DataBindings.kt │ │ │ └── imageloader │ │ │ │ ├── ApplicationGlideModule.kt │ │ │ │ └── ImageLoader.kt │ │ │ └── view │ │ │ └── main │ │ │ ├── MainActivity.kt │ │ │ ├── MainActivityViewModel.kt │ │ │ └── adapter │ │ │ └── ImagesAdapter.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item_image.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── farshidabz │ └── gettingstartkoin │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.apk 2 | *.ap_ 3 | *.aab 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | release/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # IntelliJ 37 | *.iml 38 | .idea/* 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/assetWizardSettings.xml 43 | .idea/dictionaries 44 | .idea/libraries 45 | # Android Studio 3 in .gitignore file. 46 | .idea/caches 47 | .idea/modules.xml 48 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 49 | .idea/navEditor.xml 50 | 51 | # Keystore files 52 | # Uncomment the following lines if you do not want to check your keystore files in. 53 | #*.jks 54 | #*.keystore 55 | 56 | # External native build folder generated in Android Studio 2.2 and later 57 | .externalNativeBuild 58 | 59 | # Freeline 60 | freeline.py 61 | freeline/ 62 | freeline_project_description.json 63 | 64 | # fastlane 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots 68 | fastlane/test_output 69 | fastlane/readme.md 70 | 71 | # Version control 72 | vcs.xml 73 | 74 | # lint 75 | lint/intermediates/ 76 | lint/generated/ 77 | lint/outputs/ 78 | lint/tmp/ 79 | # lint/reports/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StartWithKoin 2 | A sample of how to use Koin with android view model 3 | 4 | Read more about koin and dagger in: 5 | https://blog.usejournal.com/android-koin-with-mvvm-and-retrofit-e040e4e15f9d 6 | 7 | 8 | * Sorry, but i don’t have time to write tests, if you want please contribute for writing test for this example 9 | * If you can please provide a sample for SharedViewModel 10 | * Do any one have experience with multiple module app developing using Koin? it could be helpful for everyone 11 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | *.apk 2 | *.ap_ 3 | *.aab 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | release/ 16 | 17 | # Gradle files 18 | .gradle/ 19 | build/ 20 | 21 | # Local configuration file (sdk path, etc) 22 | local.properties 23 | 24 | # Proguard folder generated by Eclipse 25 | proguard/ 26 | 27 | # Log Files 28 | *.log 29 | 30 | # Android Studio Navigation editor temp files 31 | .navigation/ 32 | 33 | # Android Studio captures folder 34 | captures/ 35 | 36 | # IntelliJ 37 | *.iml 38 | .idea/workspace.xml 39 | .idea/tasks.xml 40 | .idea/gradle.xml 41 | .idea/assetWizardSettings.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | # Android Studio 3 in .gitignore file. 45 | .idea/caches 46 | .idea/modules.xml 47 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 48 | .idea/navEditor.xml 49 | 50 | # Keystore files 51 | # Uncomment the following lines if you do not want to check your keystore files in. 52 | #*.jks 53 | #*.keystore 54 | 55 | # External native build folder generated in Android Studio 2.2 and later 56 | .externalNativeBuild 57 | 58 | # Freeline 59 | freeline.py 60 | freeline/ 61 | freeline_project_description.json 62 | 63 | # fastlane 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | fastlane/readme.md 69 | 70 | # Version control 71 | vcs.xml 72 | 73 | # lint 74 | lint/intermediates/ 75 | lint/generated/ 76 | lint/outputs/ 77 | lint/tmp/ 78 | # lint/reports/ -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-kapt' 4 | 5 | android { 6 | compileSdkVersion 29 7 | buildToolsVersion "29.0.0" 8 | defaultConfig { 9 | applicationId "com.farshidabz.gettingstartkoin" 10 | minSdkVersion 19 11 | targetSdkVersion 29 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | 23 | compileOptions { 24 | sourceCompatibility JavaVersion.VERSION_1_8 25 | targetCompatibility JavaVersion.VERSION_1_8 26 | } 27 | 28 | dataBinding { 29 | enabled = true 30 | } 31 | } 32 | 33 | ext { 34 | retrofit_version = '2.5.0' 35 | okhttp_version = '3.9.1' 36 | 37 | glide_version = "4.8.0" 38 | 39 | ktx_version = "1.2.0-alpha02" 40 | koin_version = "2.0.1" 41 | } 42 | 43 | dependencies { 44 | implementation fileTree(dir: 'libs', include: ['*.jar']) 45 | 46 | // Androidx Libs 47 | implementation 'androidx.appcompat:appcompat:1.0.2' 48 | implementation 'androidx.cardview:cardview:1.0.0' 49 | implementation 'androidx.recyclerview:recyclerview:1.0.0' 50 | //don't update to 2.0.0-beta2 51 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1' 52 | 53 | // kotlin 54 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 55 | implementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" 56 | implementation "org.koin:koin-android-viewmodel:$koin_version" 57 | 58 | // RETROFIT 59 | implementation "com.squareup.retrofit2:retrofit:$retrofit_version" 60 | implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" 61 | implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version" 62 | 63 | //Glide 64 | implementation "com.github.bumptech.glide:glide:$glide_version" 65 | kapt "com.github.bumptech.glide:compiler:$glide_version" 66 | 67 | implementation 'androidx.appcompat:appcompat:1.0.2' 68 | implementation 'androidx.core:core-ktx:1.0.2' 69 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 70 | testImplementation 'junit:junit:4.12' 71 | androidTestImplementation 'androidx.test:runner:1.2.0' 72 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 73 | } 74 | -------------------------------------------------------------------------------- /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/androidTest/java/com/farshidabz/gettingstartkoin/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.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.farshidabz.gettingstartkoin", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/GettingStartApplication.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin 2 | 3 | import android.app.Application 4 | import com.farshidabz.gettingstartkoin.di.networkModule 5 | import com.farshidabz.gettingstartkoin.di.repositoryModule 6 | import com.farshidabz.gettingstartkoin.di.viewModelModule 7 | import org.koin.android.ext.koin.androidContext 8 | import org.koin.android.ext.koin.androidLogger 9 | import org.koin.core.context.startKoin 10 | 11 | 12 | /** 13 | * Created by farshid.abazari since 2019-07-31 14 | * 15 | * Usage: 16 | * 17 | * How to call: 18 | * 19 | * Useful parameter: 20 | * 21 | */ 22 | 23 | class GettingStartApplication : Application() { 24 | override fun onCreate() { 25 | super.onCreate() 26 | 27 | startKoin { 28 | androidLogger() 29 | androidContext(this@GettingStartApplication) 30 | modules(listOf(repositoryModule, networkModule, viewModelModule)) 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/data/model/PicSumResponseModel.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.data.model 2 | 3 | 4 | /** 5 | * Created by farshid.abazari since 2019-07-30 6 | * 7 | * Usage: 8 | * 9 | * How to call: 10 | * 11 | * Useful parameter: 12 | * 13 | */ 14 | 15 | data class ImagesResponseModel(var images: ArrayList) 16 | 17 | data class ImageModel(var url: String? = "") -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/data/remote/ImagesApi.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.data.remote 2 | 3 | import com.farshidabz.gettingstartkoin.data.model.ImagesResponseModel 4 | import retrofit2.Call 5 | import retrofit2.http.GET 6 | 7 | /** 8 | * Created by farshid.abazari since 12/27/18 9 | * 10 | * Usage: a interface to define end points 11 | * 12 | * How to call: just add in appInjector and repositoryImpl that you wanna use 13 | * 14 | */ 15 | interface ImagesApi { 16 | @GET("images/search?query=l") 17 | fun getImages() : Call 18 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/data/repository/ImagesRepo.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.data.repository 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import androidx.lifecycle.MutableLiveData 6 | import com.farshidabz.gettingstartkoin.data.model.ImageModel 7 | import com.farshidabz.gettingstartkoin.data.model.ImagesResponseModel 8 | import com.farshidabz.gettingstartkoin.data.remote.ImagesApi 9 | import retrofit2.Call 10 | import retrofit2.Callback 11 | import retrofit2.Response 12 | 13 | 14 | /** 15 | * Created by farshid.abazari since 12/27/18 16 | * 17 | * Usage: Authentication repository class to handle auth tasks 18 | * 19 | * How to call: just create a single object in AppInjector and pass it to viewModel 20 | * 21 | * Context is a sample to see how you can pass arguments with Koin 22 | * 23 | */ 24 | class ImagesRepo(private val context: Context, private val imagesApi: ImagesApi) { 25 | 26 | fun getImages(data: MutableLiveData) { 27 | imagesApi.getImages().enqueue(object : Callback { 28 | override fun onFailure(call: Call, t: Throwable) { 29 | Log.e("onFailure", t.message.toString()) 30 | } 31 | 32 | override fun onResponse( 33 | call: Call, 34 | response: Response 35 | ) { 36 | if (response.isSuccessful) { 37 | data.value = response.body() 38 | } else { 39 | data.value = ImagesResponseModel(arrayListOf(ImageModel())) 40 | } 41 | } 42 | }) 43 | } 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/di/AppInjector.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.di 2 | 3 | import com.farshidabz.gettingstartkoin.data.remote.ImagesApi 4 | import org.koin.dsl.module 5 | import retrofit2.Retrofit 6 | 7 | 8 | /** 9 | * Created by farshid.abazari since 12/27/18 10 | * 11 | * Usage: this methods handle DI 12 | * 13 | * How to call: just startActivityForResult koin in application class 14 | * 15 | */ 16 | 17 | private val retrofit: Retrofit = createNetworkClient() 18 | 19 | 20 | private val IMAGES_API: ImagesApi = retrofit.create(ImagesApi::class.java) 21 | 22 | val networkModule = module { 23 | single { IMAGES_API } 24 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/di/NetworkModule.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.di 2 | 3 | import com.farshidabz.gettingstartkoin.BuildConfig 4 | import okhttp3.Interceptor 5 | import okhttp3.OkHttpClient 6 | import okhttp3.logging.HttpLoggingInterceptor 7 | import retrofit2.Retrofit 8 | import retrofit2.converter.gson.GsonConverterFactory 9 | import java.util.concurrent.TimeUnit 10 | 11 | 12 | /** 13 | * Created by farshid.abazari since 12/27/18 14 | * 15 | * Usage: functions to create network requirements such as okHttpClient 16 | * 17 | * How to call: just call [createNetworkClient] in AppInjector 18 | * 19 | */ 20 | 21 | 22 | private val sLogLevel = 23 | if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE 24 | 25 | private const val baseUrl = "http://www.splashbase.co/api/v1/" 26 | 27 | private fun getLogInterceptor() = HttpLoggingInterceptor().apply { level = sLogLevel } 28 | 29 | fun createNetworkClient() = 30 | retrofitClient(baseUrl, okHttpClient(true)) 31 | 32 | private fun okHttpClient(addAuthHeader: Boolean) = OkHttpClient.Builder() 33 | .addInterceptor(getLogInterceptor()).apply { setTimeOutToOkHttpClient(this) } 34 | .addInterceptor(headersInterceptor(addAuthHeader)).build() 35 | 36 | private fun retrofitClient(baseUrl: String, httpClient: OkHttpClient): Retrofit = 37 | Retrofit.Builder() 38 | .baseUrl(baseUrl) 39 | .client(httpClient) 40 | .addConverterFactory(GsonConverterFactory.create()) 41 | .build() 42 | 43 | fun headersInterceptor(addAuthHeader: Boolean) = Interceptor { chain -> 44 | chain.proceed( 45 | chain.request().newBuilder() 46 | .addHeader("Content-Type", "application/json") 47 | .also { 48 | if (addAuthHeader) { 49 | // it.addHeader("Authorization", wrapInBearer(UserInfoPref.bearerToken)) 50 | } 51 | } 52 | .build() 53 | ) 54 | } 55 | 56 | private fun setTimeOutToOkHttpClient(okHttpClientBuilder: OkHttpClient.Builder) = 57 | okHttpClientBuilder.apply { 58 | readTimeout(30L, TimeUnit.SECONDS) 59 | connectTimeout(30L, TimeUnit.SECONDS) 60 | writeTimeout(30L, TimeUnit.SECONDS) 61 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/di/RepositoryModule.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.di 2 | 3 | import com.farshidabz.gettingstartkoin.data.repository.ImagesRepo 4 | import com.farshidabz.gettingstartkoin.utils.LocationHandler 5 | import org.koin.android.ext.koin.androidContext 6 | import org.koin.dsl.module 7 | 8 | 9 | /** 10 | * Created by farshid.abazari since 4/9/19 11 | * 12 | * Usage: 13 | * 14 | * How to call: 15 | * 16 | * Useful parameter: 17 | * 18 | */ 19 | 20 | val repositoryModule = module { 21 | single { ImagesRepo(androidContext(), imagesApi = get()) } 22 | 23 | single { LocationHandler() } 24 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/di/ViewModelModule.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.di 2 | 3 | import com.farshidabz.gettingstartkoin.view.main.MainActivityViewModel 4 | import org.koin.android.viewmodel.dsl.viewModel 5 | import org.koin.dsl.module 6 | 7 | /** 8 | * Created by farshid.abazari since 4/9/19 9 | * 10 | * Usage: 11 | * 12 | * How to call: 13 | * 14 | * Useful parameter: 15 | * 16 | */ 17 | 18 | val viewModelModule = module { 19 | viewModel { MainActivityViewModel(get()) } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/utils/LocationHandler.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.utils 2 | 3 | /** 4 | * Created by farshid.abazari since 4/11/19 5 | * 6 | * Usage: a class to show how you can inject it in your activity or fragment 7 | * 8 | * How to call: inject it in your class 9 | * 10 | * Useful parameter: you can pass any parameter in repoModule 11 | * 12 | */ 13 | 14 | class LocationHandler { 15 | 16 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/utils/extentions/DataBindings.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.utils.extentions 2 | 3 | import android.widget.ImageView 4 | import androidx.databinding.BindingAdapter 5 | 6 | 7 | /** 8 | * Created by Amir Hossein Ghasemi since 3/11/19 9 | * 10 | * Usage: 11 | * 12 | * How to call: 13 | * 14 | * Useful parameter: 15 | * 16 | */ 17 | 18 | @BindingAdapter("srcUrl") 19 | fun loadImage(view: ImageView, imageUrl: String?) { 20 | if (imageUrl == null) return 21 | com.farshidabz.gettingstartkoin.utils.imageloader.loadImage(imageUrl, view) 22 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/utils/imageloader/ApplicationGlideModule.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.utils.imageloader 2 | 3 | import com.bumptech.glide.annotation.GlideModule 4 | import com.bumptech.glide.module.AppGlideModule 5 | 6 | 7 | /** 8 | * Created by farshid.abazari since 12/26/18 9 | */ 10 | 11 | @GlideModule 12 | class ApplicationGlideModule : AppGlideModule() { 13 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/utils/imageloader/ImageLoader.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.utils.imageloader 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.graphics.drawable.Drawable 6 | import android.view.View 7 | import android.widget.ImageView 8 | import android.widget.ProgressBar 9 | import com.bumptech.glide.load.DataSource 10 | import com.bumptech.glide.load.engine.DiskCacheStrategy 11 | import com.bumptech.glide.load.engine.GlideException 12 | import com.bumptech.glide.load.resource.bitmap.CenterCrop 13 | import com.bumptech.glide.load.resource.bitmap.RoundedCorners 14 | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions 15 | import com.bumptech.glide.request.RequestListener 16 | import com.bumptech.glide.request.RequestOptions 17 | import com.bumptech.glide.request.target.Target 18 | 19 | 20 | /** 21 | * Created by farshid.abazari since 12/26/18 22 | * 23 | * Usage: image manager is a function to load images with Glide from remote and locale 24 | * 25 | * How to call: just call [loadImage] 26 | * 27 | * Useful parameter: placeHolder to show a image while image is loading, 28 | * options to set options after loading images like show image as circle view or round image see [circleCropTransform] 29 | * progress bar to show progress while loading image 30 | * callback that returns loaded images as drawable and a boolean field for result of loading image 31 | * 32 | */ 33 | 34 | @SuppressLint("CheckResult") 35 | fun loadImage( 36 | imageUrl: String?, 37 | imageViewToLoad: ImageView, 38 | placeHolderId: Int = 0, 39 | options: RequestOptions? = null, 40 | progressBar: ProgressBar? = null, 41 | forceOriginalSize: Boolean = false, 42 | diskCacheStrategy: DiskCacheStrategy = DiskCacheStrategy.AUTOMATIC, 43 | callback: ((Drawable?, Boolean) -> Unit)? = null 44 | ) { 45 | val glideRequest = getGlideRequest(imageViewToLoad.context, imageUrl) 46 | setPlaceHolder(glideRequest, placeHolderId) 47 | setOptions(glideRequest, options) 48 | setGlideListener(glideRequest, progressBar, callback) 49 | 50 | progressBar?.visibility = View.VISIBLE 51 | 52 | glideRequest.diskCacheStrategy(diskCacheStrategy) 53 | 54 | glideRequest.transition(DrawableTransitionOptions.withCrossFade()) 55 | if (forceOriginalSize) 56 | glideRequest.override(Target.SIZE_ORIGINAL) 57 | glideRequest.into(imageViewToLoad) 58 | } 59 | 60 | @SuppressLint("CheckResult") 61 | private fun setGlideListener( 62 | glideRequest: GlideRequest, 63 | progressBar: ProgressBar?, 64 | callback: ((Drawable?, Boolean) -> Unit)? 65 | ) { 66 | glideRequest.listener(object : RequestListener { 67 | override fun onLoadFailed( 68 | e: GlideException?, 69 | model: Any?, 70 | target: Target?, 71 | isFirstResource: Boolean 72 | ): Boolean { 73 | callback?.invoke(null, false) 74 | progressBar?.visibility = View.GONE 75 | return false 76 | } 77 | 78 | override fun onResourceReady( 79 | resource: Drawable?, 80 | model: Any?, 81 | target: Target?, 82 | dataSource: DataSource?, 83 | isFirstResource: Boolean 84 | ): Boolean { 85 | callback?.invoke(resource, true) 86 | progressBar?.visibility = View.GONE 87 | return false 88 | } 89 | }) 90 | } 91 | 92 | private fun setOptions(glideRequest: GlideRequest, options: RequestOptions?) { 93 | options?.let { 94 | glideRequest.apply(options) 95 | } 96 | } 97 | 98 | @SuppressLint("CheckResult") 99 | private fun setPlaceHolder(glideRequest: GlideRequest, placeHolderId: Int) { 100 | if (placeHolderId > 0) { 101 | glideRequest.placeholder(placeHolderId) 102 | } 103 | } 104 | 105 | private fun getGlideRequest(context: Context, imageUrl: String?) = 106 | GlideApp.with(context).load(imageUrl).centerCrop() 107 | 108 | fun circleCropTransform() = RequestOptions.circleCropTransform() 109 | fun roundCornerTransform(cornerRadius: Int) = 110 | RequestOptions().transforms(CenterCrop(), RoundedCorners(cornerRadius)) 111 | -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/view/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.view.main 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.databinding.DataBindingUtil 6 | import androidx.lifecycle.Observer 7 | import com.farshidabz.gettingstartkoin.R 8 | import com.farshidabz.gettingstartkoin.data.model.ImageModel 9 | import com.farshidabz.gettingstartkoin.databinding.ActivityMainBinding 10 | import com.farshidabz.gettingstartkoin.view.main.adapter.ImagesAdapter 11 | import org.koin.android.viewmodel.ext.android.viewModel 12 | 13 | class MainActivity : AppCompatActivity() { 14 | 15 | private val mainViewModel: MainActivityViewModel by viewModel() 16 | private val adapter = ImagesAdapter() 17 | 18 | lateinit var binding: ActivityMainBinding 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | binding = DataBindingUtil.setContentView( 23 | this, 24 | R.layout.activity_main 25 | ) 26 | 27 | configureViewModel() 28 | configureViews() 29 | 30 | mainViewModel.getImages() 31 | } 32 | 33 | private fun configureViewModel() { 34 | mainViewModel.imageResponseLiveData.observe( 35 | this, 36 | Observer { onImagesReceived(it.images) }) 37 | } 38 | 39 | private fun configureViews() { 40 | binding.lifecycleOwner = this 41 | 42 | binding.imagesRecyclerView.adapter = adapter 43 | } 44 | 45 | private fun onImagesReceived(imageList: ArrayList) { 46 | imageList.let { 47 | adapter.setData(it) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/view/main/MainActivityViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.view.main 2 | 3 | import androidx.lifecycle.MutableLiveData 4 | import androidx.lifecycle.ViewModel 5 | import com.farshidabz.gettingstartkoin.data.model.ImagesResponseModel 6 | import com.farshidabz.gettingstartkoin.data.repository.ImagesRepo 7 | 8 | 9 | /** 10 | * Created by farshid.abazari since 2019-07-30 11 | * 12 | * Usage: 13 | * 14 | * How to call: 15 | * 16 | * Useful parameter: 17 | * 18 | */ 19 | 20 | class MainActivityViewModel(private val imagesRepo: ImagesRepo) : ViewModel() { 21 | var imageResponseLiveData = MutableLiveData() 22 | 23 | fun getImages() { 24 | imagesRepo.getImages(imageResponseLiveData) 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/java/com/farshidabz/gettingstartkoin/view/main/adapter/ImagesAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin.view.main.adapter 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.databinding.DataBindingUtil 6 | import androidx.recyclerview.widget.RecyclerView 7 | import com.farshidabz.gettingstartkoin.R 8 | import com.farshidabz.gettingstartkoin.data.model.ImageModel 9 | import com.farshidabz.gettingstartkoin.databinding.ItemImageBinding 10 | 11 | 12 | /** 13 | * Created by farshid.abazari since 2019-07-31 14 | * 15 | * Usage: 16 | * 17 | * How to call: 18 | * 19 | * Useful parameter: 20 | * 21 | */ 22 | 23 | class ImagesAdapter : RecyclerView.Adapter() { 24 | 25 | private var items = ArrayList() 26 | 27 | fun setData(items: ArrayList) { 28 | this.items = items 29 | notifyDataSetChanged() 30 | } 31 | 32 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImagesViewHolder { 33 | val binding: ItemImageBinding = DataBindingUtil.inflate( 34 | LayoutInflater.from(parent.context), R.layout.item_image, parent, 35 | false 36 | ) 37 | return ImagesViewHolder(binding) 38 | } 39 | 40 | override fun getItemCount() = items.size 41 | 42 | override fun onBindViewHolder(holder: ImagesViewHolder, position: Int) { 43 | holder.binding.imageUrl = items[position].url 44 | } 45 | } 46 | 47 | class ImagesViewHolder(var binding: ItemImageBinding) : RecyclerView.ViewHolder(binding.root) -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 17 | 18 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #172435 4 | #172435 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GettingStartKoin 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/test/java/com/farshidabz/gettingstartkoin/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.farshidabz.gettingstartkoin 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.41' 5 | repositories { 6 | google() 7 | jcenter() 8 | 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.4.2' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /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 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FarshidABZ/StartWithKoin/df2087da9f5eb9089de37301d30497247533d0ba/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 30 18:15:01 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-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------