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

イケてるAndroid開発を完全に理解した__.pdf

4bd69b0ec8e5731a5332ee100ad8fb6d?s=47 entaku
April 25, 2019

 イケてるAndroid開発を完全に理解した__.pdf

4bd69b0ec8e5731a5332ee100ad8fb6d?s=128

entaku

April 25, 2019
Tweet

Transcript

  1. iOSΤϯδχΞ͸ΠέͯΔ Android։ൃ Λ׬શʹཧղͨ͠() Android։ൃָ͠ΜͰ͍͜͏Ͷ

  2. ࣗݾ঺հ • iOS/AndroidΤϯδχΞʢࣗশʣ • ܦྺ: ͳΜͪΌͬͯSE->NWΤϯδχΞ[SIer]->αʔόʔαΠυΤϯδ χΞ[SIer](java/PHP..etc)->iOS/Android ΞϓϦ։ൃ[ελʔτΞοϓ] ʹͳΓ·͢ •

    ΞϓϦ։ൃେ޷͖(°˜°)(°˜°)(°˜°)(°˜°)
  3. ΋͘͡

  4. ΋͘͡

  5. స৬ཧ༝͸࠙਌ձͰฉ͍͍ͯͩ͘͞

  6. ๻ͷϨϕϧ • ͔ͳΓiOSΑΓ • Ұ͔ΒαΫοͱ࡞ΕΔ(͸ͣ) • RxSwiftͰMVVMͷಋೖ͸ܦݧ͋Δ • ͔͠͠ •

    Android։ൃ(Kotlin)͸࠷ۙ͋Μ·Γ΍ͬͯͳ͍ • ؆୯ͳมߋ͸Ͱ͖Δ͚Ͳ
  7. https://developer.android.com/jetpack?hl=JA Android jetpackͳΔ΋ͷ͕͋ΔΒ͍͠…

  8. ͨ͘͞Μ͋ͬͯƂŜŽūŘ…

  9. ྲྀߦΓʁͷMVVMͰ͍͍ײ͡ʹͰ͖ ΔΑ͏ʹͳΔͱ͜ΖΛ໨ࢦͦ͏ʂ

  10. Google ΞʔΩςΫνϟ https://developer.android.com/topic/libraries/architecture/ Lifecycle (ϥΠϑαΠΫϧΠϕϯτʹࣗಈతʹԠ౴͢ΔUIΛ࡞੒) LiveData (Ϗϡʔʹ௨஌͢ΔσʔλΦϒδΣΫτͷߏங) ViewModel (ΞϓϦͷճసͰഁغ͞Εͳ͍UIؔ࿈ͷσʔλΛอଘ) Room

    (ΞϓϦ಺ΦϒδΣΫτͱίϯύΠϧ࣌ͷνΣοΫΛ࢖༻ͯ͠ɺΞϓϦͷSQLiteσʔλϕʔεʹΞΫ ηε) architectureपΓ͔Β͍͘
  11. https://developer.android.com/topic/libraries/architecture/ Lifecycle (ϥΠϑαΠΫϧΠϕϯτʹࣗಈతʹԠ౴͢ΔUIΛ࡞੒) ⭐ LiveData (Ϗϡʔʹ௨஌͢ΔσʔλΦϒδΣΫτͷߏங) ⭐ ViewModel (ΞϓϦͷճసͰഁغ͞Εͳ͍UIؔ࿈ͷσʔλΛอଘ) ⭐

    Room (ΞϓϦ಺ΦϒδΣΫτͱίϯύΠϧ࣌ͷνΣοΫΛ࢖༻ͯ͠ɺΞϓϦͷSQLiteσʔλϕʔεʹΞΫ ηε) architectureपΓ͔Β͍͘
  12. ΜͰ๻͕஌ͬͯΔiOS։ൃͷMVVM ͷొ৔ਓ෺͸ͲΜͳײͩ͡Ζ͏ʁ

  13. JPT "OESPJE 7JFXͷදࣔϩδοΫ $POUSPMMFS "DUJWJUZ'SBHNFOUͷؔ܎ੑ͸$POUBJOFS7JFXͱ ෳ਺ͷ7JFX$POUSPMMFSͰ࣮ݱ "DUJWJUZ'SBHNFOU ༧Ί༻ҙ͞Ε͍ͯΔ 7JFXͷදࣔϩδοΫ $POUSPMMFS

    EFMFHBUFEBUBTPVSDF ෦෼͕ͦΕʹ౰ͨΔ͸ͣ "EBQUFS 7JFXͱ.PEFMΛܨ͙ ΋ͷ 7JFX.PEFM 3YͳͲͷϥΠϒϥϦ͕ඞཁɻઃܭ͕ΦϨΦϨ "OESPJE7JFX.PEFM ެࣜͰఏڙ %BUBCJOEJOH $POUSPMMFSFUD 3YͳͲͷϥΠϒϥϦ͕ඞཁɻ $POUSPMMFSPSEBUBTPVSDFΛผϑΝΠϧͰࢦఆ͠ ͦ͜ͰCJOEͷ಺༰Λॻ͘ %BUB#JOEJOH6UJM ެࣜͰఏڙ  ࣗಈੜ੒͞ΕΜͷ͕ΩϞ ͍ .PEFM "1*$MJFOUͰୟ͍ͨ݁ՌΛఆٛͨ͠ߏ଄ମ TUSVDU ʹ֨ೲ "MBNPpSF"1*,JUͳͲ "1*$MJFOUͰୟ͍ͨ݁ՌΛ ఆٛͨ͠ߏ଄ମ EBUB DMBTT ʹ֨ೲ 3FUSP'JU 7JFX 4UPSU#PBSEYJCFUD ๻͸4UPSU#PBSE޷͖Ͱ͢ YNM YNM͏Β΍·͍͠ iOS/Android։ൃͬ͘͟Γൺֱ
  14. ViewͷදࣔϩδοΫ

  15. ViewͷදࣔϩδοΫ - Lifecycle Lifecycle-aware components perform actions in response to

    a change in the lifecycle status of another component, such as activities and fragments. These components help you produce better- organized, and often lighter-weight code, that is easier to maintain. ϥΠϑαΠΫϧରԠίϯϙʔωϯτ͸ɺΞΫςΟϏςΟ΍ϑϥάϝϯτͳͲɺଞͷίϯϙʔωϯτͷϥΠϑ αΠΫϧεςʔλεͷมԽʹԠͯ͡ΞΫγϣϯΛ࣮ߦ͠·͢ɻ͜ΕΒͷίϯϙʔωϯτΛ࢖༻͢Δͱɺ੔ཧ ͕༰қͰɺΑΓܰྔͳίʔυΛ؆୯ʹ࡞੒Ͱ͖·͢ɻ
  16. ViewͷදࣔϩδοΫ - Lifecycle

  17. ViewͷදࣔϩδοΫ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) if (savedInstanceState

    == null) { //ϓϩδΣΫτҰཡͷFragment val fragment = ProjectListFragment() supportFragmentManager .beginTransaction() .add(R.id.fragment_container, fragment, TAG_OF_PROJECT_LIST_FRAGMENT) .commit() } } J04Ͱ͍͏Կͳͷ͔͸ Θ͔ΒΜ 㶦꒳㶦 ŝžŕ Activity͸FragmentΛݺͼग़͢
  18. ViewͷදࣔϩδοΫ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?

    { //dataBinding༻ͷϨΠΞ΢τϦιʔεΛηοτ binding = DataBindingUtil.inflate(inflater, R.layout.fragment_project_list, container, false) //ΠϕϯτͷcallbackΛadapterʹ఻ୡ projectAdapter = ProjectAdapter() //্هadapterΛreclclerViewʹద༻ requireNotNull(binding).projectList.adapter = projectAdapter //Loading։࢝ requireNotNull(binding).isLoading = true //rootViewΛऔಘ return requireNotNull(binding).root } override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) val viewModel = ViewModelProviders.of(this).get(ProjectListViewModel::class.java) //؂ࢹΛ։࢝ observeViewModel(viewModel) } J04Ͱ͍͏ $POUSPMMFS Έ͍ͨͳ MVVM͔ͩΒFragment͸ViewModel΍Adapter΁ड͚౉͢͠Δ͚ͩ
  19. ༧Ί༻ҙ͞Ε͍ͯΔ ViewͷදࣔϩδοΫ - Adapter

  20. ViewͷදࣔϩδοΫ - Adapter An Adapter object acts as a bridge

    between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. AdapterΦϒδΣΫτ͸ɺAdapterViewͱͦͷϏϡʔͷجʹͳΔσʔλͱͷؒͷϒϦοδͱͯ͠ػೳ͠· ͢ɻΞμϓλ͸σʔλ߲໨΁ͷΞΫηεΛఏڙ͠·͢ɻΞμϓλ͸ɺσʔληοτ಺ͷ֤߲໨ʹରͯ͠Ϗϡʔ Λ࡞੒͢Δ੹೚΋͋Γ·͢ɻ JPT։ൃͰ͍͏ UBCMFWJFXͱ͔ʹ౉͢ EBUBTPVSDFͩ
  21. ViewͷදࣔϩδοΫ - Adapter & DataBinding 3Y4XJGUͰ΋ಉ͡ϊϦͰ CJOEJOH͢ΔΑ // σʔλΛset͢Δ fun

    setProjectList(projectList: List<Team>) { this.projectList = projectList result.dispatchUpdatesTo(this) } } // σʔλΛview಺ͷitemʹ౰ͯ͸ΊΔ override fun onCreateViewHolder(parent: ViewGroup, viewtype: Int): ProjectViewHolder { val binding = DataBindingUtil.inflate( LayoutInflater.from(parent.context), R.layout.project_list_item, parent, false) as ProjectListItemBinding //ࣗಈੜ੒͞ΕͨDataBinding༻ͷjavaclass return ProjectViewHolder(binding) }
  22. ViewͱModelΛܨ͙΋ͷ - ViewModel

  23. ViewModel The ViewModel class is designed to store and manage

    UI-related data in a lifecycle conscious way. The ViewModel class allows data to survive configuration changes such as screen rotations. The Android framework manages the lifecycles of UI controllers, such as activities and fragments. The framework may decide to destroy or re-create a UI controller in response to certain user actions or device events that are completely out of your control. ViewModelΫϥε͸ɺϥΠϑαΠΫϧΛҙࣝͨ͠ํ๏ͰUIؔ࿈ͷσʔλΛ֨ೲ͓Αͼ؅ཧ͢ΔΑ͏ʹઃܭ ͞Ε͍ͯ·͢ɻ ViewModelΫϥεΛ࢖༻͢ΔͱɺσʔλΛը໘ͷճసͳͲͷߏ੒มߋʹ଱͑Δ͜ͱ͕Ͱ͖ ·͢ɻ 3Y4XJGUͰ΍ͬͨ΍ͭͩ ͳʂ
  24. ViewModel class ProjectListViewModel(application: Application) : AndroidViewModel(application) { val projectListObservable: LiveData<List<Team>>

    init { // APIͷ݁ՌΛObservable΁ projectListObservable = FootballRepository.instance.getProjectList() } } 3Y4XJGUͰ ΋ࢥ͚ͬͨͲ γϯϓϧͳߏ੒ͳΒ 7JFX.PEFM͍Βͳ͍͔΋Ͷ σʔλݺͼग़ͯ͠Observable(؂ࢹͰ͖ΔΑ͏ʹ)͢Δʂ
  25. View <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="user" type="com.example.User"/>

    </data> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.firstName}"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@{user.lastName}"/> </LinearLayout> </layout> J04Ͱ͍͏ DPVTUPN7JFXʹ.PEFM౉͢ ϊϦ
  26. Model public class User { private final String firstName; private

    final String lastName; public User(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } public String getFirstName() { return this.firstName; } public String getLastName() { return this.lastName; } } .PEFMͷ࡞Γํ͸ͦΜͳ มΘΜͳ͍ͳ
  27. None
  28. ͱ͍͏Θ͚Ͱ ࡞ͬͯΈͨΞϓϦΛdemo͠·͢ ( ˙꒳˙ )ŝžŕ

  29. Googleਆͷެࣜsample https://github.com/googlesamples/android-architecture- components/tree/master/GithubBrowserSample Android - MVVM https://proandroiddev.com/android-viewmodel-livedata- coroutines-contraption-e1e44af690a6 ࢀߟࢿྉ Googleਆ͕ఏڙ͢Δjetpack

    https://developer.android.com/jetpack?hl=JA ࠓճେ͖͘ύΫͬ ࢀߟʹͨ͠Qiitaهࣄ https://qiita.com/Tsutou/items/69a28ebbd69b69e51703
  30. Twitter GitHub ϦϙδτϦ࡞͍ͬͨͥ( ˙꒳˙ )ŝžŕ ⭐⭐⭐⭐⭐⭐

  31. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠