Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Living on a green rocket field - DevFest Istanb...

Hasan Hosgel
November 04, 2018

Living on a green rocket field - DevFest Istanbul 2018

At Google IO 2018 the Android team announced Jetpack for Android, which is an opinionated set of libraries and architecture, which is a recommendation for Android developers. We wanted to share our experience with Jetpack and also give some recommendations for all the library & SDK developers.

Hasan Hosgel

November 04, 2018
Tweet

More Decks by Hasan Hosgel

Other Decks in Technology

Transcript

  1. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  2. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  3. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat 2013/07 - AppCompat, Media Router Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  4. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat 2013/07 - AppCompat, Media Router 2014/10 - RecyclerView, CardView Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  5. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat 2013/07 - AppCompat, Media Router 2014/10 - RecyclerView, CardView 2015/08 - bunch of new libraries Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  6. @alosdev DevFest Istanbul 2018 2011/03 - 1st version Support Library

    with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat 2013/07 - AppCompat, Media Router 2014/10 - RecyclerView, CardView 2015/08 - bunch of new libraries 2016/08 - split support libs Timetable source: https://developer.android.com/topic/libraries/support-library/revisions
  7. @alosdev DevFest Istanbul 2018 Timetable 2011/03 - 1st version Support

    Library with Fragments - Parallel ActionBarSherlock 2012/03 - Notification Compat 2013/07 - AppCompat, Media Router 2014/10 - RecyclerView, CardView 2015/08 - bunch of new libraries 2016/08 - split support libs 2017/06 - multidex … source: https://developer.android.com/topic/libraries/support-library/revisions
  8. @alosdev DevFest Istanbul 2018 Android KTX Kotlin Extension for a

    bunch of jetpack libraries: • Core-ktx • Fragment-ktx • Lifecycle-ktx • Navigation-ktx • …
  9. @alosdev DevFest Istanbul 2018 Architecture libraries • DataBinding • Lifecycles

    • LiveData • Navigation • Paging • Room • ViewModel • WorkManager NEW NEW NEW
  10. @alosdev DevFest Istanbul 2018 Navigation • Navigation Controller • new

    resource type navigation • “easily” define the navigation in a wysiwyg editor ◦ also via xml
  11. @alosdev DevFest Istanbul 2018 Navigation graph <navigation android:id="@+id/main_navigation_graph" app:startDestination="@id/listFragment"> <fragment

    android:id="@+id/listFragment" android:name="ist.devfest.navigation.ListFragment" android:label="fragment_list" tools:layout="@layout/fragment_list" /> <fragment android:id="@+id/detailFragment" android:name="ist.devfest.navigation.DetailFragment" android:label="fragment_detail" tools:layout="@layout/fragment_detail" /> </navigation>
  12. @alosdev DevFest Istanbul 2018 Layout file <android.support.constraint.ConstraintLayout …> <fragment android:id="@+id/main_nav_host_fragment"

    android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" app:navGraph="@navigation/main_navigation_graph" /> </android.support.constraint.ConstraintLayout>
  13. @alosdev DevFest Istanbul 2018 Navigation graph <navigation android:id="@+id/main_navigation_graph" app:startDestination="@id/listFragment"> <fragment

    android:id="@+id/listFragment" … > <action android:id="@+id/action_to_detailFragment" app:destination="@id/detailFragment" /> </fragment> <fragment android:id="@+id/detailFragment" … /> </navigation>
  14. @alosdev DevFest Istanbul 2018 Using NavigationController view.findNavController() .navigate(R.id.action_to_detailFragment) button.setOnClickListener( Navigation.createNavigateOnClickListener(

    R.id.action_to_detailFragment, null ) ) toolbar.setupWithNavController(navController) collapsingToolbarLayout.setupWithNavController(navController) navigationView.setupWithNavController(navController) bottomNavigationView.setupWithNavController(navController)
  15. @alosdev DevFest Istanbul 2018 Parameterized navigation <fragment android:id="@+id/detailFragment" android:name="ist.devfest.navigation.DetailFragment" android:label="fragment_detail"

    tools:layout="@layout/fragment_detail"> <argument android:name="sessionId" app:argType="string" android:defaultValue="rocket_field" /> </fragment> var bundle = bundleOf("sessionId" to "green_field") view.findNavController().navigate(R.id.action_to_detailFragment, bundle)
  16. @alosdev DevFest Istanbul 2018 Parameterized navigation with TypeSafety Build.gradle: …

    apply plugin: 'androidx.navigation.safeargs' … Caller side: val action = actionToDetailFragment().setSessionId("green_field") findNavController().navigate(action) Consumer side: DetailFragmentArgs.fromBundle(bundle).sessionId
  17. @alosdev DevFest Istanbul 2018 deeplinking nav_graph: <fragment android:id="@+id/detailFragment" … >

    <deepLink android:autoVerify="true" app:uri="www.devfest.istanbul/session/{sessionId}" /> </fragment> </navigation> AndroidManifest: <activity android:name=".MainActivity"> <nav-graph android:value="@navigation/main_navigation_graph"/> </activity> …
  18. @alosdev DevFest Istanbul 2018 deeplinking val deepLink = findNavController().createDeepLink() .setDestination(R.id.detailFragment)

    .setArguments(args) .createPendingIntent() val builder = NotificationCompat.Builder( context, channelId) .setContentTitle("Navigation") .setContentText("Deep link to Android") .setSmallIcon(R.drawable.ic_clock) .setContentIntent(deepLink) .setAutoCancel(true)
  19. @alosdev DevFest Istanbul 2018 Navigation in Multi Modules/ - Features

    base A B C app feature_a_nav feature_b_nav feature_c_nav main_nav main_nav base_nav
  20. @alosdev DevFest Istanbul 2018 base/main_nav <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/main_nav"> <include

    app:graph="@navigation/base_nav" /> <activity android:id="@+id/feature_a" app:data="https://navigation.devfest.istanbul/a" app:action="android.intent.action.VIEW"/> … </navigation>
  21. @alosdev DevFest Istanbul 2018 app/main_nav <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" app:startDestination="@+id/base_nav" android:id="@+id/main_nav">

    <include app:graph="@navigation/base_nav" /> <include app:graph="@navigation/feature_a_nav" /> <include app:graph="@navigation/feature_b_nav" /> <include app:graph="@navigation/feature_c_nav" /> </navigation>
  22. @alosdev DevFest Istanbul 2018 Paging • PagedList as data object

    • DataSource to serve PageList • PagedListAdapter for RecyclerView
  23. @alosdev DevFest Istanbul 2018 Paging • PagedList as data object

    • DataSource to serve PageList • PagedListAdapter for RecyclerView Attention: if you want to manipulate the List itself that is not the way to go
  24. @alosdev DevFest Istanbul 2018 WorkManager • Successor of JobScheduler, JobDispatcher

    & AlarmManager • Not depending on Google play services (GMS) ◦ Usage outside of Google ecosystem • Defining constraints, when to run them ( charging, network, etc.)
  25. @alosdev DevFest Istanbul 2018 Worker class CompressWorker(context : Context, params

    : WorkerParameters) : Worker(context, params) { override fun doWork(): Result { // Do the work here myCompress() // Indicate success or failure with your return value: return Result.SUCCESS // (Returning RETRY tells WorkManager to try this task again // later; FAILURE says not to try again.) } }
  26. @alosdev DevFest Istanbul 2018 Constraint // Create a Constraints object

    that defines when the task should run val myConstraints = Constraints.Builder() .setRequiresDeviceIdle(true) .setRequiresCharging(true) // Many other constraints are available, see the // Constraints.Builder reference .build()
  27. @alosdev DevFest Istanbul 2018 Running them // ...then create a

    OneTimeWorkRequest that uses those constraints val compressionWork = OneTimeWorkRequestBuilder<CompressWorker>() .setConstraints(myConstraints) .build() OR val compressionWork = PeriodicWorkRequestBuilder<CompressWorker>(12, TimeUnit.HOURS) .setConstraints(myConstraints) .build() // Then enqueue the recurring task: WorkManager.getInstance().enqueue(compressionWork)
  28. @alosdev DevFest Istanbul 2018 Worker chains val chain1 = WorkManager.getInstance()

    .beginWith(workA) .then(workB) val chain2 = WorkManager.getInstance() .beginWith(workC) .then(workD) val chain3 = WorkContinuation .combine(chain1, chain2) .then(workE) chain3.enqueue()
  29. @alosdev DevFest Istanbul 2018 Behaviour libraries • Download Manager •

    Media & Playback • Notifications • Permission • Sharing • Slices NEW
  30. @alosdev DevFest Istanbul 2018 Slices • Currently not visible for

    users, but you can be first movers • Like widgets for the home screen, just in other apps • Supported API level 19 (KitKat) onwards • Can be used with Actions
  31. @alosdev DevFest Istanbul 2018 UI libraries • Animation & transitions

    • Auto • Emoji • Fragment • Layout • Palette • TV • Wear OS by Google
  32. @alosdev DevFest Istanbul 2018 Wishlist for libraries/ SDKs • Don’t

    force your user to a specific marshaller (GSON, Jackson, Moshi) ◦ Offer the functionality like Retrofit and the ConverterFactory • Don’t force your user to use Rx- there is a cool guy around => Coroutine ◦ Droidcon Panel discussion “Rx must die!?” • Don’t depend on bigger libraries, especially if just use a small part of it • Add proguard config in your Jar/ Aar and don’t widen it to much