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

Now in Android Overview

Now in Android Overview

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

aosa4054

July 08, 2022
Tweet

More Decks by aosa4054

Other Decks in Programming

Transcript

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

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

    / Jetpack Compose • Androidͷχϡʔε͕ݟΕΔ • is not yet available on the Play Store
  3. Architecture Overview MVVM Architecture with Flow • MVVM + Repository

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

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

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

    = repository.userDataStream .map { /* Ճ޻ */ } .stateIn(/* ॳظ஋΍είʔϓͳͲ */) val feedState: StateFlow = combine( followedInterestsState, /* ͦͷଞͷRepositoryΞΫηεͳͲ */ ) { /* * - combineͷ֤ཁૉ͕ඞཁͳॲཧ * - UiStateܕʹม׵ */ } } ViewModel ෳ਺ͷFlow͔ΒҰͭͷ UiStateΛ૊ΈཱͯΔ
  7. Feature of “Now in Android” App Startup •ΞϓϦͷىಈ࣌ʹॳظԽ͢Δඞཁ ͷ͋ΔϥΠϒϥϦͰ͸ɺͦͷॳظ ԽʹcontentProvider͕༻͍ΒΕΔ

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

    in Android app •NiAΞϓϦ্Ͱ͸ςετͷ౎߹্ 
 ཧ૝తͳ࢖͍ํʹͳͬͯ͸͍ͳ͍ •WorkerΛॳظԽ͠ɺWorkerʹ 
 ΑͬͯAPIίʔϧΛߦͳ͍ͬͯΔ •Ϩεϙϯε͸શͯϩʔΧϧʹ Ωϟογϡ͞ΕΔ 12
  9. WindowSizeClass Scaffold( /* ΋Ζ΋Ζ */ bottomBar = { if (windowSizeClass.widthSizeClass

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

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

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

    == WindowWidthSizeClass.Compat) { NiaBottomBar(/* ΋Ζ΋Ζ */) } } ) { Row(/* ΋Ζ΋Ζ */) { if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) { NiaNavRail(/* ΋Ζ΋Ζ */) } /* Viewͷίϯςϯπ */ } }
  13. 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