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. Now in Android Overview
    ࣾ಺Google I/O LTձ
    2022/06/24 Shota Ara

    View full-size slide

  2. Index
    • What is “Now in Android”


    • Architecture Overview


    • Feature of “Now in Android”


    • Links

    View full-size slide

  3. What is “Now in Android”

    View full-size slide

  4. What is


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


    • ϑϧKotlin / Jetpack Compose


    • Androidͷχϡʔε͕ݟΕΔ


    • is not yet available on the Play Store

    View full-size slide

  5. Architecture Overview

    View full-size slide

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


    • Room, DataStoreͷFlow IFΛ࢖༻


    • APIΞΫηε͸ΞϓϦىಈ࣌ͷΈ


    • ىಈத͸ΩϟογϡΛ࢖༻


    • ViewModelͰՃ޻ͨ͠FlowΛ
    ViewͰcollectAsStateͰߪಡ
    6

    View full-size slide

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

    Ճ޻ͯ͠ViewʹStateFlowΛ
    ެ։͢Δɻ

    View full-size slide

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

    Ճ޻͠StateFlowʹม׵͢Δ
    ϦϙδτϦͷฦΓ஋ΛΞϓϦͷ
    υϝΠϯͷܕʹม׵

    View full-size slide

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

    View full-size slide

  10. Feature of “Now in Android”

    View full-size slide

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


    •ͦΕʹΑͬͯىಈ͕஗͘ͳΒͳ͍
    ͨΊʹcontentProviderͷ੍ޚΛߦ
    ͳͬͯ͘ΕΔϥΠϒϥϦ
    11

    View full-size slide

  12. Feature of “Now in Android”
    App Startup

    in Now in Android app
    •NiAΞϓϦ্Ͱ͸ςετͷ౎߹্

    ཧ૝తͳ࢖͍ํʹͳͬͯ͸͍ͳ͍


    •WorkerΛॳظԽ͠ɺWorkerʹ

    ΑͬͯAPIίʔϧΛߦͳ͍ͬͯΔ


    •Ϩεϙϯε͸શͯϩʔΧϧʹ
    Ωϟογϡ͞ΕΔ
    12

    View full-size slide

  13. WindowSizeClass
    ը໘αΠζʹԠͯ͡දࣔ͢ΔUIΛ

    ม͍͑ͯΔɻ


    • BottomBar -> NavRail


    • χϡʔεͷΧϥϜ਺


    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide