O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Create Modern Apps with Android Jetpack

This talk was presented during the GDG DevFest Cerrado 2018, in Goiânia, GO - Brazil.

  • Entre para ver os comentários

Create Modern Apps with Android Jetpack

  1. 1. CREATE MODERNAPPS WITH ANDROID JETPACK Ramon Ribeiro Rabello
  2. 2. Hi, I’m Ramon Rabello | Bio 10 years in Android GDG Floripa Organizer Keen to Communities Star Wars fan, I am! Master Software Engineer | about.me/ramonrabello A keep-learner
  3. 3. We’re hiring | ArcTouch Brasil (Florianópolis Office) arctouch.com/brjobs
  4. 4. DevFest Floripa 2018 | Coming soon
  5. 5. Android Dev Generations™
  6. 6. Android Dev 1st Gen | 2008-2012
  7. 7. Android Dev 1st Gen | Activity-centered development public class MainActivity extends Activity { private Button signInButton; private Button signUpButton; @Override public void onCreate(Bundle savedInstanceState) { signInButton = (TextView) findViewById(R.id.sign_in_button); signUpButton = (TextView) findViewById(R.id.sign_up_button); signInButton.setOnClickListener(new View.OnClickListener(){ // onClick() signIn(); }) signUpButton.setOnClickListener(new View.OnClickListener(){ // onClick() signUp(); }) private void signIn() { … } private void signUp() { … } God-Activity effect
  8. 8. Android Dev 1st Gen | Async programming was challenging private class LoadDataTask extends AsyncTask<Params, Progress, Result> { @Override void onPreExecute(){ showProgress(); // run on UI Thread } @Override public Result doInBackground(Params params…) { return loadData(); // run on background Thread } @Override void onPostExecute(Result result){ if (uiComponent != null){ // needed to avoid NPE updateView(result); } } private void updateView(Result result) { … }
  9. 9. Android Dev 1st Gen | Lifecycle handling was error prone @Override public void onStart() { super.onStart(); loadData(); } @Override public void onStop() { super.onStop(); releaseData(); } Race conditions & Memory Leaks
  10. 10. Android Dev 1st Gen | Java was the only supported language
  11. 11. Android Dev 1st Gen | The developer guide was poor
  12. 12. Android Dev 2nd Gen | 2013 - 2016
  13. 13. Android Dev 2nd Gen | Android Studio Preview was launched
  14. 14. Android Dev 2nd Gen | Gradle as a new build system
  15. 15. Android Dev 2nd Gen | Material Design as UI/UX guideline
  16. 16. Android Dev 2nd Gen | Plenty of 3rd-party libraries created Networking Retrofit Glide UIL Okio Picasso ActionBarSherlock SuperRecyclerView AHBottomBar … OkHttp Volley HttpClient Imaging Fresco JSON Jackson Gson Moshi DI EventBus RoboGuice ButterKnife AndroidAnnotations Async Dagger 1/2 ToothPick Otto RxJava RxAndroid Testing Robolectric Robotium Espresso UI Database GreenDAO ActiveDroid ORMLite Realm DBFlow Mockito Hamcrest Firestore CircleImageView
  17. 17. Android Dev 3rd Gen | 2017 - …
  18. 18. Android Dev 3rd Gen | MVP pattern matured in Android interface AddNoteContract { interface View { fun updateNotesList() fun showLoading() fun hideLoading() } interface Presenter { fun addNote(note: Note) } }
  19. 19. Android Dev 3rd Gen | Kotlin as a primary language for Android data class Person(val name : String, val age: Int) fun View.show() { visibility = View.VISIBLE } fun View.gone() { visibility = View.GONE } peopleRecyclerView.show() loadingProgressBar.gone() fun loadList(onSuccess:() -> Unit, onError:() -> Unit) presenter.loadList( onSuccess = { … }, onError = { … } ) data classes extension functions lambdas high-order functions
  20. 20. Android Dev 3rd Gen | RxJava + MVVM = reactive apps class NoteListViewModel { fun getNoteList(): Subscription { return repository.getNoteList() } } class NoteListActivity: AppCompatActivity() { private val viewModel = AddNoteViewModel() private val compositeSubscription = CompositeSubscription() private fun subscribeToNoteListChanges(): Subscription { return viewModel.getNoteList() .observeOn(AndroidSchedulers.mainThread()) .subscribe(adapter::updateList, this::handleError) } override fun onResume() { super.onResume() compositeSubscription.add(subscribeToNoteListChanges()) } override fun onPause() { compositeSubscription.clear() super.onPause() } }
  21. 21. NOW ANDROID HAS 10 YEARS!
  22. 22. Here comes Android Jetpack!
  23. 23. Android Jetpack | Overview Simplify complex tasks A collection of Android software components Follow best practices Free you from writing boilerplate code Comprises the androidx.* packages
  24. 24. Android Jetpack | Components Architecture Foundation Behaviour UI •
  25. 25. Jetpack Components | Foundation AppComponent Android KTX Multidex Test Architecture Foundation Behaviour UI • NEW
  26. 26. Jetpack Components | Architecture DataBinding Lifecycles LiveData Navigation Paging Room ViewModel WorkManager Architecture Foundation Behaviour UI • NEW NEW NEW
  27. 27. Jetpack Components | UI Animation & transitions Auto Emoji Fragment Layout Palette TV Wear OS by Google Architecture Foundation Behaviour UI •
  28. 28. Jetpack Components | Behaviour Download manager Media & playback Notifications Permissions Sharing Slices Architecture Foundation Behaviour UI • NEW
  29. 29. androidx
  30. 30. androidx | Overview
  31. 31. androidx | Migrating to androidx Manually Automagically Add both androidX=true and enableJetfier=true to gradle.properties file In Android Studio 3.2.1: Refactor -> Migrate to AndroidX…
  32. 32. android-ktx
  33. 33. ANDROIDX.CORE:CORE-KTX
  34. 34. KOTLIN sharedPreferences.edit() .putBoolean("key", value) .apply()
  35. 35. KOTLIN + ANDROID KTX sharedPreferences.edit { putBoolean("key", value) }
  36. 36. KOTLIN view.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener { override fun onPreDraw(): Boolean { viewTreeObserver.removeOnPreDrawListener(this) actionToBeTriggered() return true } } )
  37. 37. KOTLIN + ANDROID KTX view.doOnPreDraw { actionToBeTriggered() }
  38. 38. WorkManager
  39. 39. BASICS
  40. 40. CREATE A WORKER class UploadPhotoWorker(context: Context, params: WorkerParameters) : Worker(context, params) { override fun doWork(): Result { uploadPhoto() return Result.SUCCESS } }
  41. 41. CREATE A WORKER REQUEST val uploadWork = OneTimeRequestBuilder<CompressWorker>().build() WorkerManager.getInstance().enqueue(uploadWork)
  42. 42. OBSERVING WORK STATUS WorkManager.getInstance().getStatusById(uploadWork.id) .observe(lifecycleOwner, Observer { workStatus -> if (workStatus != null && workStaus.state.isFinished) { // do something according to the status } }
  43. 43. Who has already adopted Android Jetpack?
  44. 44. Android Jetpack adoption | top apps
  45. 45. Demo ramonrabello Android-Jetpack-Playground AndroidX Architecture Components Material Theming Coroutines Retrofit 2 Gson Kotlin 1.3
  46. 46. What’s next?
  47. 47. What’s next? | Learn more Modern Android development: Android Jetpack, Kotlin, and more (Google I/O 2018) https://www.youtube.com/watch?v=IrMw7MEgADk Android X | Android Developers https://developer.android.com/jetpack/androidx/ Android Jetpack | Android Developers https://developer.android.com/jetpack/ Android KTX | Android Developers https://developer.android.com/kotlin/ktx
  48. 48. Q & A
  49. 49. THANK YOU. https://about.me/ramonrabello

×