728x90

Kotlin 12

[Android] Kotlin Delegates in Android: Android ๊ฐœ๋ฐœ์— Properties Delegate ํ™œ์šฉํ•˜๊ธฐ

์ž‘์„ฑ์ผ: 2019.12.02 ์›๋ฌธ Kotlin Delegates in Android: Utilizing the power of Delegated Properties in Android development์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. Delegate์— ๋Œ€ํ•œ ์„ค๋ช…๊ณผ ํ•จ๊ป˜ Android ๊ฐœ๋ฐœ์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ฝ”๋“œ๋“ค์„ ์˜ˆ์ œ๋กœ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด์ค๋‹ˆ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ฝ”๋“œ๋“ค์„ Delegate๋ฅผ ํ†ตํ•ด ๊ฐœ์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ™‚ Kotlin์€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ๋„์›€์ด ๋˜๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ ์•„์ฃผ ๋ฉ‹์ง„ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ํ•˜๋‚˜๊ฐ€ Delegate Propertis์ž…๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ Delegate๊ฐ€ ์•ˆ๋“œ๋กœ์ด๋“œ ๊ฐœ๋ฐœ์— ์–ด๋–ค ๋„์›€์ด ๋˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Basics Fragment arguments SharedPreferences del..

[Android] Kotlin Extension Function์„ ์‚ฌ์šฉํ•˜์—ฌ ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€ํ•˜๊ธฐ

์ž‘์„ฑ์ผ: 2019.11.28 ์ฝ”ํ‹€๋ฆฐ ํ™•์žฅ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด View ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณดํ†ต ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ํŠน์ • ์‹œ๊ฐ„์„ ์ •ํ•ด๋‘๊ณ  ํ•œ ๋ฒˆ ํด๋ฆญ ํ›„ ํ•ด๋‹น ์‹œ๊ฐ„ ์ด๋‚ด์˜ ํด๋ฆญ ์ด๋ฒคํŠธ๋Š” ๋ฌด์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ง์ ‘ ์ „์—ญ Util ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ RxBinding์˜ throttle์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Util ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ onClick()๋งˆ๋‹ค boilerplate๊ฐ€ ์ƒ๊ธฐ๊ฒŒ ๋˜๊ณ , ๊นœ๋นกํ•˜๊ณ  ์ถ”๊ฐ€๋ฅผ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๋„ ์ƒ๊ธฐ๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค. backButton.setOnClickListener { if (ExampleUtils.isDoubleClick()) return@setOnClickListener onBackPressed() } RxBinding ์‚ฌ์šฉ ๋˜ํ•œ ..