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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
mrbgem 三角測量 開発
ogom
0
230
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
620
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
580
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
550
AWSに止められる覚悟してますか?
morizo_1984
2
530
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
220
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
3
4.4k
SREの越境 / SRE Collaboration
y0hgi
2
300
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
140
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
Featured
See All Featured
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
620
Being A Developer After 40
akosma
92
590k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
530
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!