Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Now in Android Overview

Now in Android Overview

社内LT会で使用した資料です。

62384887995a0ce07ec4f86b89f5ec9e?s=128

aosa4054

July 08, 2022
Tweet

More Decks by aosa4054

Other Decks in Programming

Transcript

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

  2. Index • What is “Now in Android” • Architecture Overview

    • Feature of “Now in Android” • Links
  3. What is “Now in Android”

  4. What is “Now in Android” • ઃܭʢσβΠϯʁʣɺ։ൃͷϕετ ϓϥΫςΟεΛ࠾༻ͨ͠ࢀߟΞϓϦ • ϑϧKotlin

    / Jetpack Compose • Androidͷχϡʔε͕ݟΕΔ • is not yet available on the Play Store
  5. Architecture Overview

  6. Architecture Overview MVVM Architecture with Flow • MVVM + Repository

    • Room, DataStoreͷFlow IFΛ࢖༻ • APIΞΫηε͸ΞϓϦىಈ࣌ͷΈ • ىಈத͸ΩϟογϡΛ࢖༻ • ViewModelͰՃ޻ͨ͠FlowΛ ViewͰcollectAsStateͰߪಡ 6
  7. ViewModel /* ؆୯ͷͨΊʹॾʑলུͯ͠·͢ɻ */ class ForYouViewModel { private val followedInterestsState:

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

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

    = repository.userDataStream .map { /* Ճ޻ */ } .stateIn(/* ॳظ஋΍είʔϓͳͲ */) val feedState: StateFlow = combine( followedInterestsState, /* ͦͷଞͷRepositoryΞΫηεͳͲ */ ) { /* * - combineͷ֤ཁૉ͕ඞཁͳॲཧ * - UiStateܕʹม׵ */ } } ViewModel ෳ਺ͷFlow͔ΒҰͭͷ UiStateΛ૊ΈཱͯΔ
  10. Feature of “Now in Android”

  11. Feature of “Now in Android” App Startup •ΞϓϦͷىಈ࣌ʹॳظԽ͢Δඞཁ ͷ͋ΔϥΠϒϥϦͰ͸ɺͦͷॳظ ԽʹcontentProvider͕༻͍ΒΕΔ

    ͜ͱ͕͋Δ •ͦΕʹΑͬͯىಈ͕஗͘ͳΒͳ͍ ͨΊʹcontentProviderͷ੍ޚΛߦ ͳͬͯ͘ΕΔϥΠϒϥϦ 11
  12. Feature of “Now in Android” App Startup 
 in Now

    in Android app •NiAΞϓϦ্Ͱ͸ςετͷ౎߹্ 
 ཧ૝తͳ࢖͍ํʹͳͬͯ͸͍ͳ͍ •WorkerΛॳظԽ͠ɺWorkerʹ 
 ΑͬͯAPIίʔϧΛߦͳ͍ͬͯΔ •Ϩεϙϯε͸શͯϩʔΧϧʹ Ωϟογϡ͞ΕΔ 12
  13. WindowSizeClass ը໘αΠζʹԠͯ͡දࣔ͢ΔUIΛ 
 ม͍͑ͯΔɻ • BottomBar -> NavRail • χϡʔεͷΧϥϜ਺

  14. WindowSizeClass Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass

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

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

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

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

  19. 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