Slide 1

Slide 1 text

Now in Android Overview ࣾ಺Google I/O LTձ 2022/06/24 Shota Ara

Slide 2

Slide 2 text

Index • What is “Now in Android” • Architecture Overview • Feature of “Now in Android” • Links

Slide 3

Slide 3 text

What is “Now in Android”

Slide 4

Slide 4 text

What is “Now in Android” • ઃܭʢσβΠϯʁʣɺ։ൃͷϕετ ϓϥΫςΟεΛ࠾༻ͨ͠ࢀߟΞϓϦ • ϑϧKotlin / Jetpack Compose • Androidͷχϡʔε͕ݟΕΔ • is not yet available on the Play Store

Slide 5

Slide 5 text

Architecture Overview

Slide 6

Slide 6 text

Architecture Overview MVVM Architecture with Flow • MVVM + Repository • Room, DataStoreͷFlow IFΛ࢖༻ • APIΞΫηε͸ΞϓϦىಈ࣌ͷΈ • ىಈத͸ΩϟογϡΛ࢖༻ • ViewModelͰՃ޻ͨ͠FlowΛ ViewͰcollectAsStateͰߪಡ 6

Slide 7

Slide 7 text

ViewModel /* ؆୯ͷͨΊʹॾʑলུͯ͠·͢ɻ */ class ForYouViewModel { private val followedInterestsState: StateFlow = repository.userDataStream .map { /* Ճ޻ */ } .stateIn(/* ॳظ஋΍είʔϓͳͲ */) val feedState: StateFlow = combine( followedInterestsState, /* ͦͷଞͷRepositoryΞΫηεͳͲ */ ) { /* * - combineͷ֤ཁૉ͕ඞཁͳॲཧ * - UiStateܕʹม׵ */ } } Repositoryͷ஋Λऔಘɾ 
 Ճ޻ͯ͠ViewʹStateFlowΛ ެ։͢Δɻ

Slide 8

Slide 8 text

ViewModel /* ؆୯ͷͨΊʹॾʑলུͯ͠·͢ɻ */ class ForYouViewModel { private val followedInterestsState: StateFlow = repository.userDataStream .map { /* Ճ޻ */ } .stateIn(/* ॳظ஋΍είʔϓͳͲ */) val feedState: StateFlow = combine( followedInterestsState, /* ͦͷଞͷRepositoryΞΫηεͳͲ */ ) { /* * - combineͷ֤ཁૉ͕ඞཁͳॲཧ * - UiStateܕʹม׵ */ } } Repositoryͷ஋Λऔಘɺ 
 Ճ޻͠StateFlowʹม׵͢Δ ϦϙδτϦͷฦΓ஋ΛΞϓϦͷ υϝΠϯͷܕʹม׵

Slide 9

Slide 9 text

/* ؆୯ͷͨΊʹॾʑলུͯ͠·͢ɻ */ class ForYouViewModel { private val followedInterestsState: StateFlow = repository.userDataStream .map { /* Ճ޻ */ } .stateIn(/* ॳظ஋΍είʔϓͳͲ */) val feedState: StateFlow = combine( followedInterestsState, /* ͦͷଞͷRepositoryΞΫηεͳͲ */ ) { /* * - combineͷ֤ཁૉ͕ඞཁͳॲཧ * - UiStateܕʹม׵ */ } } ViewModel ෳ਺ͷFlow͔ΒҰͭͷ UiStateΛ૊ΈཱͯΔ

Slide 10

Slide 10 text

Feature of “Now in Android”

Slide 11

Slide 11 text

Feature of “Now in Android” App Startup •ΞϓϦͷىಈ࣌ʹॳظԽ͢Δඞཁ ͷ͋ΔϥΠϒϥϦͰ͸ɺͦͷॳظ ԽʹcontentProvider͕༻͍ΒΕΔ ͜ͱ͕͋Δ •ͦΕʹΑͬͯىಈ͕஗͘ͳΒͳ͍ ͨΊʹcontentProviderͷ੍ޚΛߦ ͳͬͯ͘ΕΔϥΠϒϥϦ 11

Slide 12

Slide 12 text

Feature of “Now in Android” App Startup 
 in Now in Android app •NiAΞϓϦ্Ͱ͸ςετͷ౎߹্ 
 ཧ૝తͳ࢖͍ํʹͳͬͯ͸͍ͳ͍ •WorkerΛॳظԽ͠ɺWorkerʹ 
 ΑͬͯAPIίʔϧΛߦͳ͍ͬͯΔ •Ϩεϙϯε͸શͯϩʔΧϧʹ Ωϟογϡ͞ΕΔ 12

Slide 13

Slide 13 text

WindowSizeClass ը໘αΠζʹԠͯ͡දࣔ͢ΔUIΛ 
 ม͍͑ͯΔɻ • BottomBar -> NavRail • χϡʔεͷΧϥϜ਺

Slide 14

Slide 14 text

WindowSizeClass Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compat) { NiaBottomBar(/* ΋Ζ΋Ζ */) } } ) { Row(/* ΋Ζ΋Ζ */) { if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) { NiaNavRail(/* ΋Ζ΋Ζ */) } /* Viewͷίϯςϯπ */ } }

Slide 15

Slide 15 text

WindowSizeClass Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compat) { NiaBottomBar(/* ΋Ζ΋Ζ */) } } ) { Row(/* ΋Ζ΋Ζ */) { if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) { NiaNavRail(/* ΋Ζ΋Ζ */) } /* Viewͷίϯςϯπ */ } } Material designͷجຊతͳߏ଄Λ ࣮૷͍ͯ͠ΔComposable

Slide 16

Slide 16 text

WindowSizeClass Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compat) { NiaBottomBar(/* ΋Ζ΋Ζ */) } } ) { Row(/* ΋Ζ΋Ζ */) { if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) { NiaNavRail(/* ΋Ζ΋Ζ */) } /* Viewͷίϯςϯπ */ } } Material 3ͰActivityΛҾ਺ͱͨ͠ τοϓϨϕϧؔ਺͔ΒऔಘͰ͖Δ

Slide 17

Slide 17 text

WindowSize Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compat) { NiaBottomBar(/* ΋Ζ΋Ζ */) } } ) { Row(/* ΋Ζ΋Ζ */) { if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) { NiaNavRail(/* ΋Ζ΋Ζ */) } /* Viewͷίϯςϯπ */ } }

Slide 18

Slide 18 text

Links

Slide 19

Slide 19 text

Links • ϦϙδτϦ 
 https://github.com/android/nowinandroid • ঺հ͞Ε͍ͯΔAndroid Developers Blog 
 https://android-developers.googleblog.com/2022/05/now-in- android-sample-app-alpha.html • Now in Android ΞϓϦղઆ by yanzm͞Μ 
 https://speakerdeck.com/yanzm/now-in-android-app