Pro Yearly is on sale from $80 to $50! »

開発 4 年目のアプリへの Kotlin 導入

開発 4 年目のアプリへの Kotlin 導入

DroidKaigi Prelude #dk_prelude

Dd17014e380450cfed5d55ff20fa3dfd?s=128

Ryutaro Miyashita

January 26, 2018
Tweet

Transcript

  1. ։ൃ೥໨ͷΞϓϦ΁ͷ,PUMJOಋೖ %SPJE,BJHJ1SFMVEF!%F/"

  2. ٶԼཽେ࿠ $IBU8PSLגࣜձࣾ ΫϥΠΞϯτΞϓϦέʔγϣϯ։ൃ෦ !SZVHPP@

  3. ,PUMJO

  4. ։ൃ೥໨ͷΞϓϦ΁ͷ,PUMJOಋೖ ‣ ೥ͷ(PPHMF*0Ͱެࣜ։ൃݴޠԽͨ͠  Ҏલ͔Βಋೖ͸ݕ౼͍ͯͨ͠  ެࣜαϙʔτ͕ಘΒΕͨ͜ͱͰ҆৺Λಘͨ  ཌ೔͔ΒಋೖΛ։࢝ͨ͠ʜ͔͠͠ʜ ‣

    طଘͷΞϓϦ΁ͷಋೖ͸Ͳ͏ͨ͠Βྑ͍ͷ͔ʁ  Ͳ͔͜Βʁ  શͯॻ͖׵͑Δʁ  ϋοΩϦ͍ͯ͠ͳ͍͕ɺ΍ͬͯΈΑ͏
  5. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ ಋೖ౰ॳ͸શͯΛ,PUMJOԽ͢Δ༧ఆ͸ແ͔ͬͨ  ͸͡Ί͸৽ن%JBMPH'SBHNFOU͔Β։࢝  ࣍ʹطଘͷ"DUJWJUZΛ,PUMJOԽ  ͦͷޙɺ৽نίʔυΛ,PUMJOͰ௥Ճ ‣

    +BWBͱͷͭͳ͗ࠐΈ͕ωοΫʹͳ͍ͬͯ͘  !+WN'JFME!+WN4UBUJD!+WN0WFSMPBET  SFUVSO6OJU*/45"/$&  1MBUGPSN5ZQFT
  6. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ !+WN'JFME!+WN4UBUJD!+WN0WFSMPBET  DPNQBOJPOPCKFDUதʹॻ͘ͱTUBUJDʹల։ class SomeFragment : Fragment() {

    companion object { @JvmField val TAG: String = SomeFragment::class.java.simpleName } }
  7. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ !+WN'JFME!+WN4UBUJD!+WN0WFSMPBET  DPNQBOJPOPCKFDUதʹॻ͘ͱTUBUJDʹల։ class SomeFragment : Fragment() {

    companion object { @JvmStatic fun newInstance() = SomeFragment() } }
  8. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ !+WN'JFME!+WN4UBUJD!+WN0WFSMPBET  σϑΥϧτҾ਺͕͋Δ਺͚ͩΦʔόʔϩʔυ class SomeFragment : Fragment() {

    companion object { @JvmStatic @JvmOverloads fun newInstance(id: Long, name: String = "") = SomeFragment() } }
  9. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ SFUVSO6OJU*/45"/$&  ؔ਺ΛҾ਺ʹऔΔॲཧΛ+BWB͔Βݺͼग़͢ͱʁ class Model { fun async(callback:

    () -> Unit) { // Some asynchronous processing callback() } }
  10. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ SFUVSO6OJU*/45"/$&  lWPJEz͸ͳ͍ͷͰɺl6OJUzΛฦ͢ඞཁ͕͋Δ Model model = new Model();

    model.async(() -> { // Some callback processing return Unit.INSTANCE; });
  11. IUUQTEJTDVTTLPUMJOMBOHPSHUKBWBJOUFSPQVOJUDMPTVSFTSFRVJSFEUPSFUVSOLPUMJOVOJU !+WN7PJEͷఏҊ ೥ʹಉ͡໰୊ఏى

  12. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ 1MBUGPSN5ZQFT  /PO/VMM·ͨ͸/VMMBCMF͔΋͠Εͳ͍ܕ  "OESPJE4%,͸جຊతʹ1MBUGPSN5ZQFT  !/PO/VMM!/VMMBCMF͕෇͍͍ͯΕ͹ϋοϐʔ val

    inflater = LayoutInflater.from(this) ˡฦΓ஋ʹlz͕෇͍͍ͯΔ
  13. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ "OESPJE4%,Ͱ͋Ε͹த਎ΛݟΔ public static LayoutInflater from(Context context) { LayoutInflater

    LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { throw new AssertionError("LayoutInflater not found."); } return LayoutInflater; } val inflater: LayoutInflater = LayoutInflater.from(this) ˡͲ͏΍ΒOVMMʹ͸ͳΒͳ͍Β͍͠ ˣ/PO/VMMܕͱͯ͠ѻ͏Α͏ʹ͢Δ
  14. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ "OESPJE4%,Ͱ͋Ε͹த਎ΛݟΔ  lTPVSDFTz͕͋ΔͳΒ͹"OESPJE4UVEJPͰ  $ISPNFͷ"OESPJE4%,4FBSDI΋Φεεϝ ‣ IUUQCJUMZBOESPJETELTFBSDI

  15. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ "OESPJE4%,Ͱ͋Ε͹த਎ΛݟΔ  lTPVSDFTz͕͋ΔͳΒ͹"OESPJE4UVEJPͰ  $ISPNFͷ"OESPJE4%,4FBSDI΋Φεεϝ ‣ IUUQCJUMZBOESPJETELTFBSDI ˡιʔεϑΝΠϧ΁ͷϦϯΫ͕෇͘

  16. ݁࿦શͯ,PUMJOԽͨ͠ํ͕ϝϦοτ͕େ͖͍ ‣ ࣗ෼ୡ͕ॻ͍ͨίʔυ͸ʁ  !/PO/VMM!/VMMBCMFΛ෇͚͍ͯ͘ʁ  ͍ͬͦͷ͜ͱ,PUMJOʹͯ͠͠·ͬͨํ͕ʁ ‣ ͭͣͭ,PUMJOԽ͍ͯ͘͠ 

    ؔ࿈͢Δ+BWBʹ͸Ξ ϊςʔγϣϯΛ෇͚Δ  যΒͣɺΏͬ͘ΓͱͰ΋શͯΛ,PUMJOԽ͢Δ
  17. ݱঢ়

  18. +BWBͷΛ,PUMJOԽ ‣ ϲ݄Ͱ೥ؒʹॻ͍ͨ+BWBͷ͕,PUMJOԽ ‣ ϑΝΠϧ਺  ,PUMJO  +BWB

  19. +BWBͷΛ,PUMJOԽ ‣ ϲ݄Ͱ೥ؒʹॻ͍ͨ+BWBͷ͕,PUMJOԽ ‣ νʔϜ΁ͷޮՌ  /PO/VMM/VMMBCMFΛڧ͘ҙࣝ͢ΔΑ͏ʹͳͬͨ ‣ !/PO/VMM!/VMMBCMFΞ ϊςʔγϣϯͷ෇͚๨Ε͕ͳ͍

    ‣ ݴޠػೳʹ/VMMTBGFUZ͕͋Δํ͕๨Εͳ͍͠ҙࣝ͢Δ ‣ ͜Ε·Ͱ΋+BWBͰ0QUJPOBM"1*΋࢖͍ͬͯͨ ‣ ͨͩɺ0QUJPOBMΛ࢖͍ͬͯΔͱ,PUMJOଆͰ໘౗ʜʜ
  20. +BWBͷΛ,PUMJOԽ ‣ ϲ݄Ͱ೥ؒʹॻ͍ͨ+BWBͷ͕,PUMJOԽ ‣ νʔϜ΁ͷޮՌ  ޿ൣғͷWBSΛආ͚ΔΑ͏ʹͳͬͨ ‣ ΠϯελϯεϓϩύςΟ͸Ͱ͖Δ͚ͩWBM ‣

    ϝιου಺ͳͲڱ͍ൣғͰ͸WBS΋࢖͍ͬͯΔ ‣ -JTU.VUBCMF-JTUͳͲ΋ҙࣝతʹ࢖͍෼͚Λ͍ͯ͠Δ
  21. ͓͠·͍ %SPJE,BJHJ1SFMVEF!%F/"