├── .gitignore ├── .idea └── codeStyleSettings.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ └── ExampleInstrumentedTest.kt │ ├── debug │ └── java │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ ├── data │ │ └── di │ │ │ └── DataModule.kt │ │ └── di │ │ ├── AppModule.kt │ │ └── DebugAppLifecycleCallbacks.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── jp │ │ │ └── satorufujiwara │ │ │ └── kotlin │ │ │ ├── App.kt │ │ │ ├── AppLifecycleCallbacks.kt │ │ │ ├── data │ │ │ ├── api │ │ │ │ └── GitHubService.kt │ │ │ ├── model │ │ │ │ └── Repo.kt │ │ │ └── repository │ │ │ │ └── GitHubRepository.kt │ │ │ ├── di │ │ │ ├── AppComponent.kt │ │ │ ├── AutoInjector.kt │ │ │ ├── UiModule.kt │ │ │ ├── ViewModelFactory.kt │ │ │ ├── ViewModelKey.kt │ │ │ └── module │ │ │ │ └── MainModule.kt │ │ │ ├── ui │ │ │ ├── app │ │ │ │ └── UserViewModel.kt │ │ │ └── main │ │ │ │ ├── MainActivity.kt │ │ │ │ ├── MainFragment.kt │ │ │ │ └── MainViewModel.kt │ │ │ └── util │ │ │ ├── AbsentLiveData.kt │ │ │ └── ext │ │ │ ├── AppCompatActivityExt.kt │ │ │ ├── ArchitectureComponentsExt.kt │ │ │ └── LiveDataReactiveStreamsExt.kt │ └── res │ │ ├── layout │ │ ├── main_activity.xml │ │ ├── main_fragment.xml │ │ └── main_repo_item.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 │ ├── release │ └── java │ │ └── jp │ │ └── satorufujiwara │ │ └── kotlin │ │ ├── data │ │ └── di │ │ │ └── DataModule.kt │ │ └── di │ │ ├── AppModule.kt │ │ └── ReleaseAppLifecycleCallbacks.kt │ └── test │ └── java │ └── jp │ └── satorufujiwara │ └── kotlin │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/tasks.xml 39 | .idea/gradle.xml 40 | .idea/dictionaries 41 | .idea/libraries 42 | .idea 43 | !.idea/codeStyleSettings.xml 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 227 | 229 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | kotlin-architecture-components 2 | ==== 3 | 4 | This is a sample app that uses Android Architecture Components with Kotlin and Dagger 2. 5 | 6 | Architecture Components 7 | --- 8 | Architecture Components version is 1.1.* 9 | 10 | Kotlin 11 | ---- 12 | Kotlin version is 1.2.* 13 | 14 | Dagger2 15 | ---- 16 | Dagger version is 2.15.* 17 | 18 | Using [dagger.android](https://google.github.io/dagger//android.html). 19 | 20 | Other Libraries 21 | --------- 22 | 23 | * DataBinding - https://developer.android.com/topic/libraries/data-binding/index.html 24 | * OkHttp - http://square.github.io/okhttp 25 | * Retrofit - http://square.github.io/retrofit 26 | * Moshi - https://medium.com/square-corner-blog/kotlins-a-great-language-for-json-fcd6ef99256b 27 | * Glide - https://github.com/bumptech/glide 28 | * RxJava - https://github.com/ReactiveX/RxJava 29 | * RxAndroid - https://github.com/ReactiveX/RxAndroid 30 | * Timber - http://github.com/JakeWharton/timber 31 | 32 | Tips 33 | ---- 34 | 35 | #### Multibinding 36 | 37 | To use Multibinding for ViewModel's injection like [this](https://github.com/googlesamples/android-architecture-components/commit/619ef780f2989a1925f05a3801272b3b9d27bf03), 38 | use `@JvmSuppressWildcards` for inject `creators`. 39 | 40 | ```kotlin 41 | class ViewModelFactory @Inject 42 | constructor(private val creators: Map, @JvmSuppressWildcards Provider>) 43 | : ViewModelProvider.Factory { 44 | ``` 45 | [Here](https://github.com/satorufujiwara/kotlin-architecture-components/blob/master/app/src/main/java/jp/satorufujiwara/kotlin/di/ViewModelFactory.kt) is all code. 46 | 47 | #### DataBinding 48 | 49 | To use DataBinding with Kotlin, use `com.android.databinding:compiler` like below. 50 | 51 | ```Groovy 52 | dependencies { 53 | kapt 'com.android.databinding:compiler:3.0.0' 54 | } 55 | ``` 56 | 57 | Thanks 58 | ------ 59 | * Android Architecture Components samples - https://github.com/googlesamples/android-architecture-components 60 | 61 | License 62 | ------- 63 | Copyright 2017 Satoru Fujiwara 64 | 65 | Licensed under the Apache License, Version 2.0 (the "License"); 66 | you may not use this file except in compliance with the License. 67 | You may obtain a copy of the License at 68 | 69 | http://www.apache.org/licenses/LICENSE-2.0 70 | 71 | Unless required by applicable law or agreed to in writing, software 72 | distributed under the License is distributed on an "AS IS" BASIS, 73 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 74 | See the License for the specific language governing permissions and 75 | limitations under the License. 76 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-kapt' 4 | 5 | android { 6 | compileSdkVersion 27 7 | buildToolsVersion '27.0.3' 8 | defaultConfig { 9 | applicationId "jp.satorufujiwara.kotlin" 10 | minSdkVersion 19 11 | targetSdkVersion 27 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | dataBinding { 17 | enabled = true 18 | } 19 | compileOptions { 20 | sourceCompatibility JavaVersion.VERSION_1_8 21 | targetCompatibility JavaVersion.VERSION_1_8 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled true 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | } 30 | 31 | ext.support_version = "27.1.1" 32 | ext.arch_runtime_version = "1.1.1" 33 | ext.arch_version = "1.1.1" 34 | ext.dagger_version = "2.15" 35 | ext.moshi_version = "1.5.0" 36 | ext.retrofit_version = "2.3.0" 37 | ext.okhttp_version = "3.9.0" 38 | ext.glide_version = "4.3.1" 39 | 40 | dependencies { 41 | // kotlin 42 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 43 | 44 | // support libs 45 | implementation "com.android.support:appcompat-v7:$support_version" 46 | implementation "com.android.support:recyclerview-v7:$support_version" 47 | implementation "com.android.support:cardview-v7:$support_version" 48 | implementation "com.android.support:design:$support_version" 49 | implementation "com.android.support.constraint:constraint-layout:1.1.0" 50 | 51 | // architecture components 52 | implementation "android.arch.lifecycle:runtime:$arch_runtime_version" 53 | implementation "android.arch.lifecycle:extensions:$arch_version" 54 | implementation "android.arch.lifecycle:reactivestreams:$arch_version" 55 | kapt "android.arch.lifecycle:compiler:$arch_version" 56 | 57 | // dagger 58 | implementation "com.google.dagger:dagger:$dagger_version" 59 | implementation "com.google.dagger:dagger-android:$dagger_version" 60 | implementation "com.google.dagger:dagger-android-support:$dagger_version" 61 | kapt "com.google.dagger:dagger-compiler:$dagger_version" 62 | kapt "com.google.dagger:dagger-android-processor:$dagger_version" 63 | 64 | // reactive 65 | implementation "io.reactivex.rxjava2:rxjava:2.1.10" 66 | implementation "io.reactivex.rxjava2:rxandroid:2.0.1" 67 | 68 | // data 69 | implementation "com.squareup.moshi:moshi:$moshi_version" 70 | implementation "com.squareup.moshi:moshi-kotlin:$moshi_version" 71 | implementation "com.squareup.retrofit2:retrofit:$retrofit_version" 72 | implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version" 73 | implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0" 74 | implementation "com.github.bumptech.glide:glide:$glide_version" 75 | implementation "com.github.bumptech.glide:okhttp-integration:$glide_version" 76 | implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version" 77 | 78 | implementation "com.jakewharton.timber:timber:4.6.0" 79 | 80 | implementation fileTree(dir: 'libs', include: ['*.jar']) 81 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { 82 | exclude group: 'com.android.support', module: 'support-annotations' 83 | }) 84 | testImplementation 'junit:junit:4.12' 85 | } 86 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /adt-bundle-mac/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | 27 | ## dagger 28 | 29 | # dagger2 https://github.com/google/dagger/issues/645 30 | -dontwarn com.google.errorprone.annotations.* 31 | 32 | ## data 33 | 34 | # moshi 35 | # okhttp3 36 | -dontwarn okio.** 37 | -dontwarn javax.annotation.** 38 | 39 | 40 | # moshi https://github.com/square/moshi 41 | -keepclasseswithmembers class * { 42 | @com.squareup.moshi.* ; 43 | } 44 | -keep @com.squareup.moshi.JsonQualifier interface * 45 | -keepclassmembers class kotlin.Metadata { 46 | public ; 47 | } 48 | 49 | # retrofit2 http://square.github.io/retrofit/ 50 | -dontnote retrofit2.Platform 51 | -dontwarn retrofit2.Platform$Java8 52 | -keepattributes Signature 53 | -keepattributes Exceptions 54 | 55 | # okhttp3 https://github.com/square/okhttp/issues/2230 56 | -dontwarn okhttp3.** 57 | 58 | # glide https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-glide.pro 59 | -keep public class * implements com.bumptech.glide.module.GlideModule 60 | -keep class com.bumptech.glide.integration.okhttp3.OkHttpGlideModule 61 | -keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { 62 | **[] $VALUES; 63 | public *; 64 | } 65 | -------------------------------------------------------------------------------- /app/src/androidTest/java/jp/satorufujiwara/kotlin/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 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("jp.satorufujiwara.kotlin", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/debug/java/jp/satorufujiwara/kotlin/data/di/DataModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.di 2 | 3 | import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory 4 | import com.squareup.moshi.KotlinJsonAdapterFactory 5 | import com.squareup.moshi.Moshi 6 | import dagger.Module 7 | import dagger.Provides 8 | import jp.satorufujiwara.kotlin.data.api.GitHubService 9 | import okhttp3.OkHttpClient 10 | import okhttp3.logging.HttpLoggingInterceptor 11 | import retrofit2.Retrofit 12 | import retrofit2.converter.moshi.MoshiConverterFactory 13 | import javax.inject.Singleton 14 | 15 | @Module 16 | internal object DataModule { 17 | 18 | @Singleton 19 | @Provides 20 | @JvmStatic 21 | fun provideMoshi() = Moshi.Builder() 22 | .add(KotlinJsonAdapterFactory()) 23 | .build() 24 | 25 | @Singleton 26 | @Provides 27 | @JvmStatic 28 | fun providesOkHttp(): OkHttpClient = OkHttpClient.Builder() 29 | .addInterceptor(HttpLoggingInterceptor() 30 | .apply { level = HttpLoggingInterceptor.Level.BODY }) 31 | .build() 32 | 33 | @Singleton 34 | @Provides 35 | @JvmStatic 36 | fun provideRetrofit(oktHttpClient: OkHttpClient, moshi: Moshi): Retrofit = Retrofit.Builder() 37 | .client(oktHttpClient) 38 | .baseUrl("https://api.github.com") 39 | .addConverterFactory(MoshiConverterFactory.create(moshi)) 40 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 41 | .build() 42 | 43 | @Singleton 44 | @Provides 45 | @JvmStatic 46 | fun provideGitHubService(retrofit: Retrofit): GitHubService = retrofit.create(GitHubService::class.java) 47 | 48 | } -------------------------------------------------------------------------------- /app/src/debug/java/jp/satorufujiwara/kotlin/di/AppModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import dagger.Module 4 | import dagger.Provides 5 | import jp.satorufujiwara.kotlin.AppLifecycleCallbacks 6 | import jp.satorufujiwara.kotlin.data.di.DataModule 7 | import javax.inject.Singleton 8 | 9 | @Module(includes = [DataModule::class]) 10 | internal object AppModule { 11 | 12 | @Singleton 13 | @Provides 14 | @JvmStatic 15 | fun provideAppLifecycleCallbacks(): AppLifecycleCallbacks = DebugAppLifecycleCallbacks() 16 | 17 | } -------------------------------------------------------------------------------- /app/src/debug/java/jp/satorufujiwara/kotlin/di/DebugAppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.app.Application 4 | import jp.satorufujiwara.kotlin.AppLifecycleCallbacks 5 | import timber.log.Timber 6 | 7 | class DebugAppLifecycleCallbacks : AppLifecycleCallbacks { 8 | 9 | override fun onCreate(application: Application) { 10 | Timber.plant(Timber.DebugTree()) 11 | } 12 | 13 | override fun onTerminate(application: Application) { 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/App.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import dagger.android.support.DaggerApplication 4 | import jp.satorufujiwara.kotlin.di.DaggerAppComponent 5 | import jp.satorufujiwara.kotlin.di.applyAutoInjector 6 | import jp.satorufujiwara.kotlin.ui.app.UserViewModel 7 | import javax.inject.Inject 8 | 9 | class App : DaggerApplication() { 10 | 11 | @Inject lateinit var appLifecycleCallbacks: AppLifecycleCallbacks 12 | @Inject lateinit var userViewModel: UserViewModel 13 | 14 | override fun applicationInjector() = DaggerAppComponent.builder() 15 | .application(this) 16 | .build() 17 | 18 | override fun onCreate() { 19 | super.onCreate() 20 | applyAutoInjector() 21 | appLifecycleCallbacks.onCreate(this) 22 | userViewModel.loginUserId.value = "satorufujiwara" 23 | } 24 | 25 | override fun onTerminate() { 26 | appLifecycleCallbacks.onTerminate(this) 27 | super.onTerminate() 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/AppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 2 | 3 | import android.app.Application 4 | 5 | interface AppLifecycleCallbacks { 6 | 7 | fun onCreate(application: Application) 8 | 9 | fun onTerminate(application: Application) 10 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/data/api/GitHubService.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.api 2 | 3 | import io.reactivex.Flowable 4 | import jp.satorufujiwara.kotlin.data.model.Repo 5 | import retrofit2.http.GET 6 | import retrofit2.http.Path 7 | 8 | interface GitHubService { 9 | 10 | @GET("/users/{user}/repos") 11 | fun listRepos(@Path("user") user: String): Flowable> 12 | 13 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/data/model/Repo.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.model 2 | 3 | data class Repo(val id: String, val name: String) -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/data/repository/GitHubRepository.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.repository 2 | 3 | import jp.satorufujiwara.kotlin.data.api.GitHubService 4 | import javax.inject.Inject 5 | 6 | class GitHubRepository @Inject constructor(private val gitHubService: GitHubService) { 7 | 8 | fun loadRepos(owner: String) = gitHubService.listRepos(owner) 9 | 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/AppComponent.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import dagger.BindsInstance 4 | import dagger.Component 5 | import dagger.android.AndroidInjector 6 | import dagger.android.support.AndroidSupportInjectionModule 7 | import jp.satorufujiwara.kotlin.App 8 | import javax.inject.Singleton 9 | 10 | @Singleton 11 | @Component(modules = [ 12 | AndroidSupportInjectionModule::class, 13 | AppModule::class, 14 | UiModule::class 15 | ]) 16 | interface AppComponent : AndroidInjector { 17 | 18 | @Component.Builder 19 | interface Builder { 20 | @BindsInstance 21 | fun application(application: App): Builder 22 | 23 | fun build(): AppComponent 24 | } 25 | 26 | override fun inject(app: App) 27 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/AutoInjector.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.app.Activity 4 | import android.app.Application 5 | import android.os.Bundle 6 | import android.support.v4.app.Fragment 7 | import android.support.v4.app.FragmentActivity 8 | import android.support.v4.app.FragmentManager 9 | import dagger.android.AndroidInjection 10 | import dagger.android.support.AndroidSupportInjection 11 | import dagger.android.support.HasSupportFragmentInjector 12 | 13 | 14 | interface Injectable 15 | 16 | fun Application.applyAutoInjector() = registerActivityLifecycleCallbacks( 17 | object : Application.ActivityLifecycleCallbacks { 18 | 19 | override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { 20 | handleActivity(activity) 21 | } 22 | 23 | override fun onActivityStarted(activity: Activity) { 24 | 25 | } 26 | 27 | override fun onActivityResumed(activity: Activity) { 28 | 29 | } 30 | 31 | override fun onActivityPaused(activity: Activity) { 32 | 33 | } 34 | 35 | override fun onActivityStopped(activity: Activity) { 36 | 37 | } 38 | 39 | override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { 40 | 41 | } 42 | 43 | override fun onActivityDestroyed(activity: Activity) { 44 | 45 | } 46 | }) 47 | 48 | private fun handleActivity(activity: Activity) { 49 | if (activity is Injectable || activity is HasSupportFragmentInjector) { 50 | AndroidInjection.inject(activity) 51 | } 52 | if (activity is FragmentActivity) { 53 | activity.supportFragmentManager.registerFragmentLifecycleCallbacks( 54 | object : FragmentManager.FragmentLifecycleCallbacks() { 55 | override fun onFragmentCreated(fm: FragmentManager, f: Fragment, s: Bundle?) { 56 | if (f is Injectable) { 57 | AndroidSupportInjection.inject(f) 58 | } 59 | } 60 | }, true) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/UiModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.arch.lifecycle.ViewModelProvider 4 | import dagger.Binds 5 | import dagger.Module 6 | import dagger.android.ContributesAndroidInjector 7 | import jp.satorufujiwara.kotlin.ui.main.MainActivity 8 | import jp.satorufujiwara.kotlin.di.module.MainModule 9 | 10 | @Module 11 | internal abstract class UiModule { 12 | 13 | @Binds 14 | abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory 15 | 16 | @ContributesAndroidInjector(modules = [MainModule::class]) 17 | internal abstract fun contributeMainActivity(): MainActivity 18 | 19 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/ViewModelFactory.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.arch.lifecycle.ViewModel 4 | import android.arch.lifecycle.ViewModelProvider 5 | import javax.inject.Inject 6 | import javax.inject.Provider 7 | 8 | class ViewModelFactory @Inject constructor( 9 | private val creators: Map, @JvmSuppressWildcards Provider>) 10 | : ViewModelProvider.Factory { 11 | 12 | @Suppress("UNCHECKED_CAST") 13 | override fun create(modelClass: Class): T { 14 | var creator: Provider? = creators[modelClass] 15 | if (creator == null) { 16 | for ((key, value) in creators) { 17 | if (modelClass.isAssignableFrom(key)) { 18 | creator = value 19 | break 20 | } 21 | } 22 | } 23 | if (creator == null) throw IllegalArgumentException("unknown model class " + modelClass) 24 | try { 25 | return creator.get() as T 26 | } catch (e: Exception) { 27 | throw RuntimeException(e) 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/ViewModelKey.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.arch.lifecycle.ViewModel 4 | import dagger.MapKey 5 | import kotlin.reflect.KClass 6 | 7 | @MustBeDocumented 8 | @Target(AnnotationTarget.FUNCTION) 9 | @Retention(AnnotationRetention.RUNTIME) 10 | @MapKey 11 | internal annotation class ViewModelKey(val value: KClass) -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/di/module/MainModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di.module 2 | 3 | import android.arch.lifecycle.ViewModel 4 | import dagger.Binds 5 | import dagger.Module 6 | import dagger.android.ContributesAndroidInjector 7 | import dagger.multibindings.IntoMap 8 | import jp.satorufujiwara.kotlin.di.ViewModelKey 9 | import jp.satorufujiwara.kotlin.ui.main.MainFragment 10 | import jp.satorufujiwara.kotlin.ui.main.MainViewModel 11 | 12 | @Module 13 | internal abstract class MainModule { 14 | 15 | @Binds 16 | @IntoMap 17 | @ViewModelKey(MainViewModel::class) 18 | abstract fun bindMainViewModel(viewModel: MainViewModel): ViewModel 19 | 20 | @ContributesAndroidInjector 21 | abstract fun contributeMainFragment(): MainFragment 22 | 23 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/ui/app/UserViewModel.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.app 2 | 3 | import android.arch.lifecycle.MutableLiveData 4 | import javax.inject.Inject 5 | import javax.inject.Singleton 6 | 7 | @Singleton 8 | class UserViewModel @Inject constructor() { 9 | 10 | val loginUserId = MutableLiveData() 11 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/ui/main/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.arch.lifecycle.ViewModelProvider 4 | import android.os.Bundle 5 | import android.support.v4.app.Fragment 6 | import android.support.v7.app.AppCompatActivity 7 | import dagger.android.DispatchingAndroidInjector 8 | import dagger.android.support.HasSupportFragmentInjector 9 | import jp.satorufujiwara.kotlin.R 10 | import jp.satorufujiwara.kotlin.util.ext.setContentFragment 11 | import javax.inject.Inject 12 | 13 | class MainActivity : AppCompatActivity(), HasSupportFragmentInjector { 14 | 15 | @Inject lateinit var viewModelFactory: ViewModelProvider.Factory 16 | @Inject lateinit var androidInjector: DispatchingAndroidInjector 17 | 18 | override fun supportFragmentInjector() = androidInjector 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.main_activity) 23 | setContentFragment(R.id.containerLayout) { MainFragment.newInstance() } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/ui/main/MainFragment.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.arch.lifecycle.ViewModelProvider 4 | import android.arch.lifecycle.ViewModelProviders 5 | import android.databinding.DataBindingUtil 6 | import android.os.Bundle 7 | import android.support.v4.app.Fragment 8 | import android.support.v7.widget.LinearLayoutManager 9 | import android.support.v7.widget.RecyclerView 10 | import android.view.LayoutInflater 11 | import android.view.View 12 | import android.view.ViewGroup 13 | import jp.satorufujiwara.kotlin.R 14 | import jp.satorufujiwara.kotlin.data.model.Repo 15 | import jp.satorufujiwara.kotlin.databinding.MainFragmentBinding 16 | import jp.satorufujiwara.kotlin.databinding.MainRepoItemBinding 17 | import jp.satorufujiwara.kotlin.di.Injectable 18 | import jp.satorufujiwara.kotlin.ui.app.UserViewModel 19 | import jp.satorufujiwara.kotlin.util.ext.observe 20 | import javax.inject.Inject 21 | 22 | class MainFragment : Fragment(), Injectable { 23 | 24 | @Inject lateinit var viewModelFactory: ViewModelProvider.Factory 25 | @Inject lateinit var userViewModel: UserViewModel 26 | private lateinit var viewModel: MainViewModel 27 | private lateinit var binding: MainFragmentBinding 28 | private val adapter = MainAdapter() 29 | 30 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = 31 | DataBindingUtil.inflate(inflater, R.layout.main_fragment, container, false).also { 32 | binding = it 33 | }.root 34 | 35 | override fun onActivityCreated(savedInstanceState: Bundle?) { 36 | super.onActivityCreated(savedInstanceState) 37 | viewModel = ViewModelProviders.of(activity!!, viewModelFactory).get(MainViewModel::class.java) 38 | binding.recyclerView.adapter = adapter 39 | binding.recyclerView.layoutManager = LinearLayoutManager(activity) 40 | 41 | viewModel.repos.observe(this) { 42 | it ?: return@observe 43 | adapter.run { 44 | items.clear() 45 | items.addAll(it) 46 | notifyDataSetChanged() 47 | } 48 | } 49 | userViewModel.loginUserId.observe(this) { 50 | viewModel.ownerId.value = it 51 | } 52 | } 53 | 54 | companion object { 55 | fun newInstance() = MainFragment() 56 | } 57 | } 58 | 59 | class MainAdapter : RecyclerView.Adapter() { 60 | val items = ArrayList() 61 | 62 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainAdapter.ViewHolder { 63 | return ViewHolder(DataBindingUtil.inflate( 64 | LayoutInflater.from(parent.context), R.layout.main_repo_item, parent, false)) 65 | } 66 | 67 | override fun onBindViewHolder(holder: MainAdapter.ViewHolder, position: Int) { 68 | holder.binding.repo = items[position] 69 | } 70 | 71 | override fun getItemCount() = items.size 72 | 73 | inner class ViewHolder(val binding: MainRepoItemBinding) : RecyclerView.ViewHolder(binding.root) 74 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/ui/main/MainViewModel.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.ui.main 2 | 3 | import android.arch.lifecycle.LiveData 4 | import android.arch.lifecycle.MutableLiveData 5 | import android.arch.lifecycle.ViewModel 6 | import io.reactivex.Flowable 7 | import io.reactivex.android.schedulers.AndroidSchedulers 8 | import io.reactivex.schedulers.Schedulers 9 | import jp.satorufujiwara.kotlin.data.model.Repo 10 | import jp.satorufujiwara.kotlin.data.repository.GitHubRepository 11 | import jp.satorufujiwara.kotlin.util.AbsentLiveData 12 | import jp.satorufujiwara.kotlin.util.ext.switchMap 13 | import jp.satorufujiwara.kotlin.util.ext.toLiveData 14 | import javax.inject.Inject 15 | 16 | class MainViewModel @Inject constructor(private val repository: GitHubRepository) : ViewModel() { 17 | 18 | val ownerId = MutableLiveData() 19 | val repos: LiveData> 20 | 21 | init { 22 | repos = ownerId.switchMap { 23 | if (it.isEmpty()) AbsentLiveData.create() 24 | else repository.loadRepos(it) 25 | .subscribeOn(Schedulers.io()) 26 | .observeOn(AndroidSchedulers.mainThread()) 27 | .onErrorResumeNext(Flowable.empty()) 28 | .toLiveData() 29 | } 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/util/AbsentLiveData.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util 2 | 3 | import android.arch.lifecycle.LiveData 4 | 5 | class AbsentLiveData private constructor() : LiveData() { 6 | init { 7 | postValue(null) 8 | } 9 | 10 | companion object { 11 | fun create(): LiveData { 12 | return AbsentLiveData() 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/util/ext/AppCompatActivityExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.support.v4.app.Fragment 4 | import android.support.v4.app.FragmentActivity 5 | 6 | inline fun FragmentActivity.setContentFragment(containerViewId: Int, f: () -> Fragment): Fragment? { 7 | val manager = supportFragmentManager 8 | val fragment = manager?.findFragmentById(containerViewId) 9 | fragment?.let { return it } 10 | return f().apply { manager?.beginTransaction()?.add(containerViewId, this)?.commit() } 11 | } -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/util/ext/ArchitectureComponentsExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.arch.lifecycle.LifecycleOwner 4 | import android.arch.lifecycle.LiveData 5 | import android.arch.lifecycle.Observer 6 | import android.arch.lifecycle.Transformations 7 | 8 | fun LiveData.observe(owner: LifecycleOwner, observer: (T?) -> Unit) = observe(owner, object : Observer { 9 | override fun onChanged(v: T?) { 10 | observer.invoke(v) 11 | } 12 | }) 13 | 14 | fun LiveData.switchMap(func: (X) -> LiveData) 15 | = Transformations.switchMap(this, func) 16 | -------------------------------------------------------------------------------- /app/src/main/java/jp/satorufujiwara/kotlin/util/ext/LiveDataReactiveStreamsExt.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.util.ext 2 | 3 | import android.arch.lifecycle.LifecycleOwner 4 | import android.arch.lifecycle.LiveData 5 | import android.arch.lifecycle.LiveDataReactiveStreams 6 | import org.reactivestreams.Publisher 7 | 8 | fun Publisher.toLiveData() = LiveDataReactiveStreams.fromPublisher(this) 9 | 10 | fun LiveData.toPublisher(lifecycleOwner: LifecycleOwner) 11 | = LiveDataReactiveStreams.toPublisher(lifecycleOwner, this) 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main_activity.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/main_repo_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 11 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | GitHub 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/release/java/jp/satorufujiwara/kotlin/data/di/DataModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.data.di 2 | 3 | import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory 4 | import com.squareup.moshi.KotlinJsonAdapterFactory 5 | import com.squareup.moshi.Moshi 6 | import dagger.Module 7 | import dagger.Provides 8 | import jp.satorufujiwara.kotlin.data.api.GitHubService 9 | import okhttp3.OkHttpClient 10 | import retrofit2.Retrofit 11 | import retrofit2.converter.moshi.MoshiConverterFactory 12 | import javax.inject.Singleton 13 | 14 | @Module 15 | internal object DataModule { 16 | 17 | @Singleton 18 | @Provides 19 | @JvmStatic 20 | fun provideMoshi() = Moshi.Builder() 21 | .add(KotlinJsonAdapterFactory()) 22 | .build() 23 | 24 | 25 | @Singleton 26 | @Provides 27 | @JvmStatic 28 | fun providesOkHttp(): OkHttpClient = OkHttpClient.Builder() 29 | .build() 30 | 31 | @Singleton 32 | @Provides 33 | @JvmStatic 34 | fun provideRetrofit(oktHttpClient: OkHttpClient, moshi: Moshi): Retrofit = Retrofit.Builder() 35 | .client(oktHttpClient) 36 | .baseUrl("https://api.github.com") 37 | .addConverterFactory(MoshiConverterFactory.create(moshi)) 38 | .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) 39 | .build() 40 | 41 | @Singleton 42 | @Provides 43 | @JvmStatic 44 | fun provideGitHubService(retrofit: Retrofit): GitHubService = retrofit.create(GitHubService::class.java) 45 | 46 | } -------------------------------------------------------------------------------- /app/src/release/java/jp/satorufujiwara/kotlin/di/AppModule.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import dagger.Module 4 | import dagger.Provides 5 | import jp.satorufujiwara.kotlin.AppLifecycleCallbacks 6 | import jp.satorufujiwara.kotlin.data.di.DataModule 7 | import javax.inject.Singleton 8 | 9 | @Module(includes = [DataModule::class]) 10 | internal object AppModule { 11 | 12 | @Singleton 13 | @Provides 14 | @JvmStatic 15 | fun provideAppLifecycleCallbacks(): AppLifecycleCallbacks = ReleaseAppLifecycleCallbacks() 16 | 17 | } -------------------------------------------------------------------------------- /app/src/release/java/jp/satorufujiwara/kotlin/di/ReleaseAppLifecycleCallbacks.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin.di 2 | 3 | import android.app.Application 4 | import jp.satorufujiwara.kotlin.AppLifecycleCallbacks 5 | 6 | class ReleaseAppLifecycleCallbacks : AppLifecycleCallbacks { 7 | 8 | override fun onCreate(application: Application) { 9 | 10 | } 11 | 12 | override fun onTerminate(application: Application) { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/test/java/jp/satorufujiwara/kotlin/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package jp.satorufujiwara.kotlin 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.2.30' 5 | repositories { 6 | maven { url 'https://maven.google.com' } 7 | jcenter() 8 | google() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.1.1' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | mavenCentral() 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/satorufujiwara/kotlin-architecture-components/9d68ff1c5f06f25069d544abed9b5733f9aeb892/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 18 14:58:59 JST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------