独自設計のAndroidアプリを設計ごとKotlinizeした話

231ca3ad65e9b2ef1172e06ff0e9612c?s=47 Shun Hosaka
December 19, 2017

 独自設計のAndroidアプリを設計ごとKotlinizeした話

R.kt #2の時の登壇資料です。

231ca3ad65e9b2ef1172e06ff0e9612c?s=128

Shun Hosaka

December 19, 2017
Tweet

Transcript

  1. 2.

    ͸͡Ίʹ w อࡔॣ ΄͔͞͠ΎΜ  w ৽ଔ̍೥໨ w (JU)VC 2JJUBͳͲ3FZVSOJCMF

    w ΩοζϦʔͱ͍͏ϓϩμΫτͷ10݉ΤϯδχΞ
 ʢอҭԂ޲͚ͷαʔϏεʣ 2
  2. 9.

    ϦϥΠτͷਐΊํ 9 w ̋ը໘͝ͱʹϦϥΠτ w ૚͝ͱʹϦϥΠτ w ϦϑΝΫλϦϯάϦϥΠτ w ཧ༝ɿ

    w ҰؾʹϦϥΠτ͢ΔͷͰ͸ͳ͘ɺ௕ظతͳϦϥΠτΛ૝ఆͨ͠ w طଘίʔυʹςετ͕ͳ͘ɺͦ΋ͦ΋ϦϑΝΫλϦϯάʹ΋ة ݥ͕͋ͬͨ
  3. 15.

    "DUJWJUZͳͲͷϏϧμʔύλʔϯ 15 ը໘͝ͱͷextensionΛ࡞ͬͨɻ ը໘໊.ktͰτοϓϨϕϧͷextensionΛॻ͍͍ͯΔ // file privateͳͷͰଞ͔Βࢀর͞ΕΔ͜ͱ͸ͳ͍ private object Keys

    { const val hoge = "Sample.hoge" } fun SampleActivity.Companion.createIntent(context: Context, hoge: String): Intent = Intent(context, SampleActivity::class.java).apply { put(Keys.hoge, hoge) } fun SampleFragment.Companion.newInstance(hoge: String): SampleFragment = SampleFragment().apply { arguments = Bundle().apply { putString(Keys.hoge, hoge) } } fun SampleActivity.createFragment(): SampleFragment = SampleFragment.newInstance(intent.getStringExtra(Keys.hoge)) fun SampleFragment.parseHoge(): String = arguments.getString(Keys.hoge) ※SampleActivityͱSampleFragmentʹ͸ɺͦΕͧΕ companion object;ͱ͍͏ܗͷهࡌ͕ඞཁɻ