├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.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 │ │ │ └── layout │ │ │ │ ├── activity_repository.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── view_repository.xml │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── kotlinandroidhandson │ │ │ │ ├── model │ │ │ │ ├── Repository.kt │ │ │ │ ├── Page.kt │ │ │ │ └── User.kt │ │ │ │ ├── client │ │ │ │ └── GithubClient.kt │ │ │ │ ├── extensions.kt │ │ │ │ ├── RepositoryListAdapter.kt │ │ │ │ ├── RepositoryActivity.kt │ │ │ │ ├── RepositoryView.kt │ │ │ │ ├── App.kt │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── kotlinandroidhandson │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── kotlinandroidhandson │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── art └── capture.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /art/capture.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/art/capture.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8dp 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/model/Repository.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson.model 2 | 3 | data class Repository(val id: Long) 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngsw-taro/kotlin-android-hands-on/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .idea -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/model/Page.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson.model 2 | 3 | data class Page(val totalCount: Long, 4 | val items: List) -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 18 22:16:14 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.4-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Github Client 3 | Search keywords 4 | Search 5 | ★%d 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/model/User.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson.model 2 | 3 | import android.os.Parcelable 4 | import com.google.gson.annotations.SerializedName 5 | import kotlinx.android.parcel.Parcelize 6 | 7 | @Parcelize 8 | data class User(val id: Long, 9 | @SerializedName("login") val loginId: String, 10 | val avatarUrl: String?) : Parcelable -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/client/GithubClient.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson.client 2 | 3 | import com.example.kotlinandroidhandson.model.Page 4 | import com.example.kotlinandroidhandson.model.Repository 5 | import io.reactivex.Single 6 | import retrofit2.Response 7 | import retrofit2.http.GET 8 | import retrofit2.http.Query 9 | 10 | interface GithubClient { 11 | 12 | @GET("/search/repositories") 13 | fun search(@Query("q") query: String): Single> 14 | } -------------------------------------------------------------------------------- /app/src/test/java/com/example/kotlinandroidhandson/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_repository.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 16 | -------------------------------------------------------------------------------- /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 | 19 | kotlin.incremental=false 20 | kotlin.coroutines=enable -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/extensions.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson 2 | 3 | import android.app.Activity 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.os.Parcelable 7 | import android.support.annotation.IdRes 8 | import android.view.View 9 | import retrofit2.Retrofit 10 | import kotlin.reflect.KClass 11 | 12 | @Suppress("UNCHECKED_CAST") 13 | fun View.findView(@IdRes id: Int): T = findViewById(id) 14 | 15 | fun Retrofit.create(service: KClass): T = create(service.java) 16 | 17 | inline fun Retrofit.create(): T = create(T::class) 18 | 19 | inline fun Context.intent(): Intent = Intent(this, T::class.java) 20 | 21 | operator fun Intent.get(name: String): T? = getParcelableExtra(name) 22 | 23 | val Activity.app: App 24 | get() = application as App -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/RepositoryListAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson 2 | 3 | import android.content.Context 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.BaseAdapter 7 | import com.example.kotlinandroidhandson.model.Repository 8 | 9 | class RepositoryListAdapter(private val context: Context) : BaseAdapter() { 10 | 11 | var repositories: List = emptyList() 12 | 13 | override fun getCount(): Int = repositories.size 14 | 15 | override fun getItem(position: Int): Any = repositories[position] 16 | 17 | override fun getItemId(position: Int): Long = repositories[position].id 18 | 19 | override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View = 20 | (convertView as? RepositoryView ?: RepositoryView(context)).apply { 21 | setRepository(repositories[position]) 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/kotlinandroidhandson/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.kotlinandroidhandson", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/kotlin/com/example/kotlinandroidhandson/RepositoryActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.kotlinandroidhandson 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import android.support.v7.app.AppCompatActivity 7 | import android.webkit.WebView 8 | import com.example.kotlinandroidhandson.model.Repository 9 | 10 | class RepositoryActivity : AppCompatActivity() { 11 | 12 | override fun onCreate(savedInstanceState: Bundle?) { 13 | super.onCreate(savedInstanceState) 14 | setContentView(R.layout.activity_repository) 15 | 16 | // val repository: Repository = intent["repository"] ?: throw IllegalStateException("repositoryがないよ") 17 | // title = repository.fullName 18 | // 19 | // val repositoryView = findViewById(R.id.repository_view) 20 | // repositoryView.setRepository(repository) 21 | // 22 | // val webView = findViewById(R.id.web_view) 23 | // webView.loadUrl(repository.htmlUrl) 24 | } 25 | } -------------------------------------------------------------------------------- /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 /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin Android Hands-on 2 | 3 | ## 題材 4 | 5 | GitHubのリポジトリをキーワード検索するアプリを作成します。 6 | 7 | ![rocket](https://raw.github.com/ntaro/kotlin-android-hands-on/master/art/capture.gif) 8 | 9 | ## 事前準備とスタート 10 | 11 | ハンズオンは[masterブランチ](https://github.com/ntaro/kotlin-android-hands-on)から始めます。 12 | 13 | このブランチは、コードや各種設定が記述済みです。 14 | ハンズオン開始までに **ビルド** と **実行** をしておいてください。 15 | 16 | コードは未完成で、ハンズオンの中で完成させていきます。 17 | 18 | ## 完成形 19 | 20 | [completedブランチ](https://github.com/ntaro/kotlin-android-hands-on/tree/completed)は、完成形です。 21 | 22 | ## ハンズオン課題 23 | 24 | ### `Repository`クラスの定義 25 | 26 | GitHub上に存在するリポジトリを表現するクラスを定義しましょう。 27 | 28 | プロパティ名|型|説明 29 | ---|---|--- 30 | `id`|`Long`|ID 31 | `fullName`|`String`|フルネーム=「ユーザ名/リポジトリ名」 32 | `htmlUrl`|`String`|詳細URL 33 | `stargazersCount`|`Int`|スター数 34 | `owner`|`User`|リポジトリの所有者。Userクラスは定義済み 35 | `description`|`String?`|リポジトリの説明 36 | `language`|`String?`|言語 37 | 38 | ### ダミーデータのリスト表示 39 | 40 | ### インテント生成関数 + リポジトリ詳細画面 41 | 42 | ### Retrofitを使ってAPIアクセス 43 | 44 | ### async/awaitの体験 45 | 46 | ### スター付けた人のリスト表示機能を作る -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 |