Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AndroidでKotlinフル活用プログラミング #Kotlin_Sansan
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Taro Nagasawa
January 15, 2016
Programming
2.9k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AndroidでKotlinフル活用プログラミング #Kotlin_Sansan
AndroidでKotlin勉強会 @ Sansan で発表したスライドです。
http://connpass.com/event/22189/
Taro Nagasawa
January 15, 2016
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
1.8k
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.4k
#Ubie 狂気の認知施策と選考設計
ntaro
14
14k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.2k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.7k
Kotlinでサーバサイドを始めよう!
ntaro
1
1.1k
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
3.1k
Kotlin Contracts #m3kt
ntaro
4
4.4k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
590
Other Decks in Programming
See All in Programming
Verilogで学ぶCPU自作入門.pdf
uyuki234
1
430
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
380
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
120
AHC070解法紹介
eijirou
0
130
wkhtmltopdfの次どうするか問題2026
willnet
2
1.6k
Security issues being discussed on Web Platforms
petamoriken
0
1k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
550
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
270
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
850
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
190
iOSDC2026登壇資料.pdf
riofujimon
0
170
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
320
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
410
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
550
We Are The Robots
honzajavorek
0
380
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
A Soul's Torment
seathinner
8
3.6k
4 Signs Your Business is Dying
shpigford
187
23k
Become a Pro
speakerdeck
PRO
31
6.3k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
The browser strikes back
jonoalderson
0
1.7k
Transcript
AndroidでKotlin フル活用プログラミング 2016-01-15 AndroidでKotlin勉強会 @ Sansan 長澤 太郎 @ngsw_taro
自己紹介 • 長澤 太郎 @ngsw_taro • 仕事ではAndroidメイン、Java, Scala, Railsなど •
Kotlinエバンジェリスト(自称) ◦ 講演や執筆などの実績多数 • 27歳、蟹座、ビール大好き
私のブログ
アプリカティブなんとかみたいなやつ val minus = { a: Int -> { b:
Int -> a - b } } fun <T, R> T.bind(f: ((T)->R)?): R? = f?.invoke(this) y?.bind(x?.bind(minus)) fun <T, R> ((T)->R).apply(n: T?): R? = n?.bind(this) val sub: Int? = minus.apply(x)?.apply(y) http://taro.hatenablog.jp/entry/2014/04/06/144811
メソッド参照みたいなやつ val <A, B> (A.()->B).tof: (A)->B get() = { a:
A -> a.this() } listOf("a", "bb", "ccc").map(String::length.tof) http://taro.hatenablog.jp/entry/2015/02/24/215413
Extensionで なんでもするマン
AndroidでKotlin Extensionプログラミング 2016-01-15 AndroidでKotlin勉強会 @ Sansan 長澤 太郎 @ngsw_taro
RxLifecycle面倒
RxLifecycleを使う // in RxAppCompatActivity apiAccesss() .compose(bindToLifecycle<MyData>()) .subscribe { ... }
省略できないっぽい
こうしたい: 拡張関数使えばできそう // in RxAppCompatActivity apiAccesss() .bindToLifecycle() .subscribe { ...
}
こういうの作る // in RxAppCompatActivity fun <T> Observable<T>.bindToLifecycle() = compose<T>(self.bindToLifecycle()) いい感じ!
共通部品化したい
こういう提案 interface RxLifecycleFeature: ActivityLifecycleProvider { fun <T> Observable<T>.bindToLifecycle() = compose<T>(
[email protected]
())
}
使用側のアクティビティ class MyActivity: RxAppCompatActivity(), RxLifecycleFeature { fun go() { apiAccess()
.bindToLifecycle() .subscribe {...} } }
明示的Activity起動の問題
よくあるやつ: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(c: Context, data: String) = Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } }
よくあるやつ: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(this, data)) } }
よくあるやつ: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(this, data)) } } thisを書きたくない! 簡単には拡張関数に できなさそう...
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } }
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } } Contextを取らなくなった
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } } Context -> Intentな 関数を返す
イマイチな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(data)(this)) } }
よさげな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” TargetActivity.intent(data).start() } fun ((Context)->Intent).start() { startActivity(this(applicationContext)) } }
よさげな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” TargetActivity.intent(data).start() } fun ((Context)->Intent).start() { startActivity(this(applicationContext)) } } ここからthisが消えた
共通部品化する for 遷移先 inline fun <reified T : Activity> intentBuilder(crossinline
init: Intent.() -> Unit) = { context: Context -> Intent(context, T::class.java).apply { init() } }
共通部品を使う: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = intentBuilder<TargetActivity> { putExtra(“data”, data) } } }
共通部品化する for 遷移元 interface IntentFeature { fun startActivity(intent: Intent) fun
getApplicationContext() fun ((Context)->Intent).start() { startActivity(this(getApplicationContext())) } } インタフェースを継承するので はなく、抽象メソッドを定義して おく
共通部品を使う: 遷移元 class SourceActivity: Activity(), IntentFeature { fun go() {
val data = “hogefuga” TargetActivity.intent(data).start() } }
おまけ: M11以前 trait IntentFeature: Activity { fun ((Context)->Intent).start() { startActivity(this(getApplicationContext()))
} } 実装する側のクラスを 指定できた
Thank you, Enjoy Kotlin!