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
Let's refactoring my old app with new android t...
Search
hammer0802
December 16, 2021
1
320
Let's refactoring my old app with new android tech !
at 【YUMEMI x Sansan Tech Meetup】Android開発におけるチャレンジを語る, 2021/12/16
hammer0802
December 16, 2021
Tweet
Share
More Decks by hammer0802
See All by hammer0802
Flutter Riverpodのすゝめ
hammer0802
3
1.4k
Featured
See All Featured
Statistics for Hackers
jakevdp
796
220k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Music & Morning Musume
bryan
46
6.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
KATA
mclloyd
29
14k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
A better future with KSS
kneath
238
17k
Optimising Largest Contentful Paint
csswizardry
33
3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Transcript
ۦ͚ग़͠ͷࠒ࡞ͬͨAndroidΞϓϦΛ ࠷৽ٕज़ͰϦϑΝΫλϦϯάͯ͠Έͨ Takanori Sato@ YUMEMI Inc. 2021/12/16 ʲYUMEMI x Sansan
Tech MeetupʳAndroid։ൃʹ͓͚ΔνϟϨϯδΛޠΔ
ࣗݾհ 2
ࠤ౻ɹوൣ ✦ Μ·ʔͱ͍͏HNͰ׆ಈ ✦ 20198݄גࣜձࣾΏΊΈத్ೖࣾ ✦ લ৬͕ϝΠϯϑϨʔϜΤϯδχΞ(ҟۀछ͔Βస৬) ✦ AndroidΤϯδχΞྺ3 ✦
1ࣇͷύύ👶 ✦ Twitter : @watashi_desu_82 ✦ Qiita : @hammer0802 3
ࠓ͢͜ͱ ✦ۦ͚ग़࣌͠ʹ࡞ͬͯ์ஔͨ͠ΞϓϦͷϦϑΝΫλϦϯάʹ νϟϨϯδͨ͠ ✦ͦͷࡍʹಘͨ࠷৽ٕज़ͷݟtips ✦Jetpack Compose, Dagger HiltͳͲ ✦ࠓճͷνϟϨϯδͰײͨ͜͡ͱ 4
લஔ͖ 5
6 օ͞Μɺۦ͚ग़͠ΤϯδχΞͷࠒͲΜͳ ίʔυΛॻ͍͍͔ͯͨࢥ͍ग़ͤ·͔͢ʁ
7 ͲΜͳ͜ͱΛ͍͔ͬͯͨࢥ͍ग़ͤͯɺͲΜͳ ίʔυ͔ͩͬͨखݩʹͳ͍ͱࢥ͍ग़ͤͳ͍Ͱ͢ΑͶ
8 ࢲɺΘ͔Γ·͢(ެ։ͯ͠·͢)
SUBWAYγϛϡϨʔλʔ ✦Google Play Store ✦https://play.google.com/store/apps/ details?id=com.hammer.app.subwaysimulator ✦GitHub ✦https://github.com/hammer0802/SubwaySimulator ✦SUBWAYͷαϯυΟονͷϨγϐΛ࡞͢ΔΞϓϦ ✦લ৬(ඇϓϩάϥϚʔ৬)࣌ʹݸਓͰ։ൃ
✦ΞΠίϯؤுͬͯඳ͍ͨ 9
10 ΞϓϦެ։·Ͱ͍͚ͨ͠ɺศརػೳೖΕΒΕͨ ॳΊͯͷΞϓϦ։ൃʹ্ͯ͠ग़དྷͩΖ͏ (ࣗըࣗࢍ) ࣌ͷࢲ͜͏ࢥ͍ͬͯͨʜ
ποίϛͲ͜Ζ͔͠ͳ͍ σʔλߏ શ ෦xm lͰ ॻ ͘ ε τ ϩ
ϯ ά ε λ Π ϧ Ϩ Π Ξ τ શͯͷॲཧΛߦ͏ ਆActivity apply͕ σ Χ ա ͗ Μ ͩ Ζ ʜ 11 ͦͯ͠ݱࡏ ࢲݱ࣮Λͬͨ ΞʔΩςΫνϟ͕ ଘࡏ͠ͳ͍ੈքઢ มʹࣈೖΕͪΌ͏
12 աڈͱܾผ͢ΔͨΊ ಆ͍(ϦϑΝΫλϦϯά)࢝·ͬͨʜ
ຊ 13
ͷચ͍ग़͠(Ұ෦) ✦ΞʔΩςΫνϟ͕ͳ͍ ✦ActivityͰը໘ॲཧҎ֎ʹσʔλอଘͳͲશॲཧͬͯΔ ✦ભҠ͕શ෦startActivity ✦େͰࡶͳϨΠΞτ ✦etc… 14
ରԠࡦͷݕ౼ - ࠓͬΆͦ͏ͳͷΛย͔ͬΒ͍ͬͯ͘ ✦ΞʔΩςΫνϟ͕ͳ͍ ✦AAC(Android Architecture Component)ϥΠϒϥϦ܈Λ༻ͨ͠MVVM ✦ActivityͰը໘ॲཧҎ֎ʹσʔλอଘͳͲશॲཧͬͯΔ ✦ViewModel, RoomͳͲΛ༻ͯ͠ॲཧΛ
✦DIDagger HiltΛ࠾༻ ✦ભҠ͕શ෦startActivity ✦NavigationͰભҠॲཧ ✦େͰࡶͳϨΠΞτ ✦Jetpack ComposeΛͬͯϨΠΞτߏங 15
ૣϦϑΝΫλϦϯά։࢝ʂ …ͱࢥͬͨΒ 16 TargetSdkVersion্͛ͨΒ support library͔Β AndroidXʹҠߦ͠ΖͱݴΘ ΕͯΔɻϨΠΞτͷྔଟ ͍͠ɺେมͦ͏ͩͳ͊ʜ
؆୯ͩͬͨ 17 ίʔυϨΠΞτࣗಈͰAndroidXʹҠߦ ΄΅खमਖ਼ແ͠ͰϏϧυͰ͖ͨ🎉
18 σʔλߏͷमਖ਼σΟϨΫτϦߏͷݟ͠ͳ ͲɺϥΠϒϥϦʔΛΘͳ͍मਖ਼লུͯ͠ʜ
Step1. ϨΠΞτΛ࠶ߏங ✦Jetpack ComposeΛ͏ ✦એݴతUI ✦ϨΠΞτϑΝΠϧ(xml)ෆཁ ✦20217݄ʹstable🎉 19
Jetpack Composeͷجຊతͳ͍ํ ✦setContent ϒϩοΫʹίϯϙʔβϒϧΛݺͼग़ ͯ͠ϨΠΞτΛఆٛ͢Δ ✦onCreateҎ֎ʹɺComposeView͔Β setͰ͖Δ ✦ίϯϙʔβϒϧͱ @Composable Λ͚ͭͨؔ
✦@Preview Λ͚ͭΔͱӈʹϓϨϏϡʔදࣔ ✦Modifier ͰαΠζͳͲΛௐ͠ɺϨΠΞτΛߏ ͢Δ 20
Ϧετදࣔʜ ࣌Α͘Θ͔Βͳ͍··࣮͍ͯͨ͠RecyclerViewॲཧ 21
LazyColumnͰͱͯγϯϓϧʹʂ 22
ঢ়ଶΛίϯϙʔβϒϧʹ͢͜ͱͰঢ়ଶʹԠ͡ ͨߋ৽͕Ͱ͖Δ ✦remember Λͬͯঢ়ଶΛ ࠶ίϯϙʔζޙอଘ ✦LiveDataFlowͳͲͷ observableͳܕ͔ΒStateΛ ࡞Մೳ 23
AndroidViewΛͬͯComposeͰ·ͩར༻Ͱ͖ͳ ͍UIཁૉΛදࣔͰ͖Δ ✦AdViewMapViewͳͲ ·ͩར༻Ͱ͖ͳ͍ ✦AndroidViewͷfactoryΛ ͬͯදࣔՄೳ 24
Step2. ViewModelΛಋೖ ✦Dagger HiltΛ׆༻͍ͨ͠ ✦DI(Dependency Injection)ϥΠϒϥϦʔ ✦DIͷఆ൪ͩͬͨDagger2 Λ͞Βʹվྑ ✦20215݄ʹstable🎉 25
DIͷϋʔυϧ͕֨ஈʹԼ͕ͬͨ ✦ApplicationΫϥεʹ@HiltAndroidApp Λ͚ͭΔ ✦ݺͼग़͠ଆͷActivityͳͲͰ @AndroidEntryPointΛ͚ͭΔ ✦Inject͍ͨ͠ͷconstructorͷલʹ @InjectΛ͚ͭΔ ✦ViewModelͷ߹ߋʹ @HiltViewModelΛ͚ͭΔ ✦େମ͜ΕͰͰ͖ͪΌ͏
26
HiltJetpack ComposeͱҰॹʹ͑Δ ✦viewModel()Ͱίϯϙʔβϒϧ ͷҾͰऔΕΔ ✦Composeʹ͓͚ΔHilt NavigationͱϥΠϒϥϦ͕౷߹ ͞Ε͍ͯΔ ✦hilt-navigation-compose 27
Step3. ભҠಋઢͷܨ͗ࠐΈ ✦NavigationͰ֤ը໘ʹભҠ ✦ҎલdestinationΛxml Ͱఆ͍ٛͯͨ͠ ✦ComposeͰKotlinίʔ υͰఆٛͰ͖Δ 28
NavigationΛͬͨભҠ ✦NavHostΛ࣋ͬͨίϯϙʔβϒϧΛఆٛ ✦composableͷrouteͰߦ͖ઌΛࢦఆ ✦hiltViewModelͰ@HiltViewModel ͕͍ͭͨViewModelΛऔಘͰ͖Δ ✦NavHostControllerͰߦ͖ઌ navigate ✦NavHostController͕ࢀর͢Δඞཁ ͕͋Δͯ͢ͷίϯϙʔβϒϧ͕ΞΫ ηεͰ͖ΔҐஔʹஔ͘
29
શը໘ͷಋઢ͕ͭͳ͕ͬͨ🎉 30
ϦϑΝΫλϦϯάνϟϨϯδ Λܦͯ 31
ओʹJetpack ComposeͰײͨ͡ϝϦοτ ✦ϦετͳͲ͔ͳΓ؆ܿʹॻ͚Δ෦͕ଟ͔ͬͨ ✦ίʔυྔ͕શମతʹݮͬͨ(ޙड़) ✦એݴతUI͕ײతͰॳ৺ऀͷϋʔυϧ͕ͦ͏ ✦ࠓճॳΊͯ৮Ε͕ͨͱ͖͍ͬͭ͢ҹͩͬͨ(Flutter͔ͬͯͨΒ͔͠ Εͳ͍͚ΕͲ) ✦طଘΞϓϦͷ1ը໘͚ͩɺ·ͨը໘ͷҰ෦͚ͩJetpack ComposeͰϦϑΝ ΫλϦϯά͕Ͱ͖Δ
✦εΫϥοϓ&ϏϧυͰ1͔Β࡞Βͳ͍͍ͯ͘ 32
ͲΕ͘Β͍ίʔυྔ͕ݮ͔ͬͨ ✦ϨΠΞτϑΝΠϧશ෦ফ͠ ͨͷͰ͍ͩͿݮͬͨ ✦ࠓճؒʹ߹ΘͣʹҰ୴ফͨ͠ ॲཧ͋ΔͷͰɺͦΕΛ෮׆ ͤͨ͞Β݁ߏ૿͑Δʁ ✦͕ͩݮগΛ͑Δ͜ͱͳ͞ ͦ͏ 33
(ݸਓతʹײͨ͡)Jetpack ComposeͷΠϚΠνͳ ✦ͦͷίϯϙʔβϒϧɺͦ͜(Material Design)ʹແ͚Εແ͍Ͱ͢Ͷ ✦SpinnerͳͲੲ͋ͬͨͷΛࣗલͰ࣮͢Δඞཁ͕͋ͬͨ ✦·ͩඍົʹᙱ͍ͱ͜Ζʹಧ͔ͳ͍ ✦TextFieldʹmaxLengthͳͯ͘ڻ͍ͨ ✦Previewؔ࿈ ✦ҰʑϏϧυ͕ඞཁɺFlutterͷHot Reload͕࿀͘͠ͳͬͨ
✦(࣮ͷ͍͔ͤ͠Εͳ͍͕)Previewͷද͕ࣔյΕ͍ͯΔͷ͕͋ͬͨ ✦NavigationͷΞχϝʔγϣϯͳͲɺଟ͘ͷ։ൃऀ͕͍͍ͨͰ͋Ζ͏ػೳ͕·ͩఏڙ͞Ε͍ͯͳ͍ ✦Accompanistͱ͍͏ิॿϥΠϒϥϦʔͰఏڙ͞ΕͯΔ͕ɺʮকདྷతʹػೳ͕ഇࢭ͞ΕΔՄೳੑ͋Γ·͢ʯͱॻ͔ Ε͍ͯͯखΛग़ͮ͠Β͍ ͱݴ͍ͭͭɺ্هͷΛ͑ͨϝϦοτײ͡ΒΕͨʂ 34
ࠓޙͷ༧ఆ ✦ؒʹ߹Θͳ͔ͬͨRoomͷಋೖɺҰ୴ফͨ͠ॲཧΛ෮׆ͤ͞ Δ ✦σβΠϯΛࠓͬΆ͍ͨ͘͠(Material YouͳͲ) ✦ࠓޙ͜ͷΞϓϦΛ৽ٕज़ͷ༡ͼֶशࡐྉͱͭͭ͠ϒϥο γϡΞοϓ͍͖͍ͯͨ͠ 35
ࠓճͷνϟϨϯδͰײͨ͜͡ͱ ✦ੲͷίʔυΛݟͯʮμϝͩͳʙʯͱࢥ͑ΔΑ͏ʹͳͬͨࣗͷ ✦ίʔυͷΫΦϦςΟͱͯ͠ΠϚΠνͰɺΞϓϦϦϦʔε·Ͱ ͍͚࣋ͬͯͨੲͷࣗͷҙ ✦࠷৽ٕज़ʹ৮Εͨ͜ͱʹΑΔAndroidΞϓϦ։ൃͷϞνϕʔ γϣϯΞοϓ ✦AndroidΞϓϦ։ൃɺͬͺΓָ͍͠ʂ 36
37 օ͞Μۦ͚ग़࣌͠ͷίʔυΛݟฦͯ͠ɺ ॳ৺ʹฦͬͯΈ͍͔͕ͯͰ͠ΐ͏͔
38 Fin...?
39 ݸਓΞϓϦͰࢼ͚ͩ͢͡Όͳͯ͘ɺۀͰ ࠷৽ٕज़Λͬͯษڧ͍ͨ͠ͳʙ ※͜ΕCMͰ͢
40 ͦΕɺΏΊΈͰͰ͖·͢Αʁ ※͜ΕCMͰ͢
ΏΊΈͰAndroidͷ࠷৽ٕज़Λ͑ΔɾֶΔػձ͕ͨ͘͞Μʂ ✦ࠓճհͨ͠࠷৽ٕज़Λ࠾༻ͨ͠Ҋ݅ଟ͋Γʂ ✦FlutterΛ׆༻ͨ͠ԽࢧԉΛຊ֨։࢝ʂ ✦֤࠷৽ٕज़ͷϫʔΩϯάάϧʔϓͰࣝΛਂ۷Γʂ ✦ຖ1ͭࣾษڧձΛ։࠵ʂ 41 ※͜ΕCMͰ͢ ͋ͳͨΏΊΈͰര͠·ͤΜ͔ʁ
42 Fin