Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AndroidでKotlinフル活用プログラミング #Kotlin_Sansan
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
3k
Kotlin Contracts #m3kt
ntaro
4
4.4k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
570
Other Decks in Programming
See All in Programming
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
190
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
Foundation Models frameworkで画像分析
ryodeveloper
1
600
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
1
250
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
350
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
160
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
260
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
150
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
150
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
330
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Making Projects Easy
brettharned
120
6.7k
How to Talk to Developers About Accessibility
jct
2
490
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Automating Front-end Workflow
addyosmani
1370
210k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
WCS-LA-2024
lcolladotor
0
790
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!