Slide 1

Slide 1 text

@alosdev Mobilization 2018 Living on a green rocket field Hasan Hosgel

Slide 2

Slide 2 text

@alosdev Mobilization 2018 History

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

@alosdev Mobilization 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

Slide 5

Slide 5 text

@alosdev Mobilization 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

Slide 6

Slide 6 text

@alosdev Mobilization 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

Slide 7

Slide 7 text

@alosdev Mobilization 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

Slide 8

Slide 8 text

@alosdev Mobilization 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

Slide 9

Slide 9 text

@alosdev Mobilization 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

Slide 10

Slide 10 text

@alosdev Mobilization 2018 What now?

Slide 11

Slide 11 text

@alosdev Mobilization 2018 The King is dead - long live the king

Slide 12

Slide 12 text

@alosdev Mobilization 2018 Welcome Jetpack

Slide 13

Slide 13 text

@alosdev Mobilization 2018 android.support.v4.*** -> androidx.*** Except com.google.android.material.***

Slide 14

Slide 14 text

@alosdev Mobilization 2018 gradle.properties android.useAndroidX = true android.enableJetifier = true

Slide 15

Slide 15 text

@alosdev Mobilization 2018 Jetpack components ● Foundation ● Architecture ● Behaviour ● UI

Slide 16

Slide 16 text

@alosdev Mobilization 2018 Foundation libraries ● AppCompat ● Android KTX ● MultiDex ● Test NEW

Slide 17

Slide 17 text

@alosdev Mobilization 2018 Android KTX Kotlin Extension for a bunch of jetpack libraries: ● Core-ktx ● Fragment-ktx ● Lifecycle-ktx ● Navigation-ktx ● …

Slide 18

Slide 18 text

@alosdev Mobilization 2018 Architecture libraries ● DataBinding ● Lifecycles ● LiveData ● Navigation ● Paging ● Room ● ViewModel ● WorkManager NEW NEW NEW

Slide 19

Slide 19 text

@alosdev Mobilization 2018 Navigation ● Navigation Controller ● new resource type navigation ● “easily” define the navigation in a wysiwyg editor ○ also via xml

Slide 20

Slide 20 text

@alosdev Mobilization 2018 Navigation graph

Slide 21

Slide 21 text

@alosdev Mobilization 2018 Layout file

Slide 22

Slide 22 text

@alosdev Mobilization 2018 Navigation Editor

Slide 23

Slide 23 text

@alosdev Mobilization 2018 Navigation graph

Slide 24

Slide 24 text

@alosdev Mobilization 2018 Navigation Editor

Slide 25

Slide 25 text

@alosdev Mobilization 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)

Slide 26

Slide 26 text

@alosdev Mobilization 2018 Parameterized navigation var bundle = bundleOf("sessionId" to "green_field") view.findNavController().navigate(R.id.action_to_detailFragment, bundle)

Slide 27

Slide 27 text

@alosdev Mobilization 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

Slide 28

Slide 28 text

@alosdev Mobilization 2018 deeplinking nav_graph: AndroidManifest: …

Slide 29

Slide 29 text

@alosdev Mobilization 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)

Slide 30

Slide 30 text

@alosdev Mobilization 2018 Navigation in Multi Modules/ - Features base A B C app

Slide 31

Slide 31 text

@alosdev Mobilization 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

Slide 32

Slide 32 text

@alosdev Mobilization 2018 base/main_nav …

Slide 33

Slide 33 text

@alosdev Mobilization 2018 base/base_nav …

Slide 34

Slide 34 text

@alosdev Mobilization 2018 a/feature_a_nav

Slide 35

Slide 35 text

@alosdev Mobilization 2018 app/main_nav

Slide 36

Slide 36 text

@alosdev Mobilization 2018 Paging ● PagedList as data object ● DataSource to serve PageList ● PagedListAdapter for RecyclerView

Slide 37

Slide 37 text

@alosdev Mobilization 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

Slide 38

Slide 38 text

@alosdev Mobilization 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.)

Slide 39

Slide 39 text

@alosdev Mobilization 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.) } }

Slide 40

Slide 40 text

@alosdev Mobilization 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()

Slide 41

Slide 41 text

@alosdev Mobilization 2018 Running them // ...then create a OneTimeWorkRequest that uses those constraints val compressionWork = OneTimeWorkRequestBuilder() .setConstraints(myConstraints) .build() OR val compressionWork = PeriodicWorkRequestBuilder(12, TimeUnit.HOURS) .setConstraints(myConstraints) .build() // Then enqueue the recurring task: WorkManager.getInstance().enqueue(compressionWork)

Slide 42

Slide 42 text

@alosdev Mobilization 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()

Slide 43

Slide 43 text

@alosdev Mobilization 2018 Behaviour libraries ● Download Manager ● Media & Playback ● Notifications ● Permission ● Sharing ● Slices NEW

Slide 44

Slide 44 text

@alosdev Mobilization 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

Slide 45

Slide 45 text

@alosdev Mobilization 2018 UI libraries ● Animation & transitions ● Auto ● Emoji ● Fragment ● Layout ● Palette ● TV ● Wear OS by Google

Slide 46

Slide 46 text

@alosdev Mobilization 2018 Jetpack - sample app https://github.com/googlesamples/android-sunflower

Slide 47

Slide 47 text

@alosdev Mobilization 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

Slide 48

Slide 48 text

@alosdev Mobilization 2018 Any Questions

Slide 49

Slide 49 text

@alosdev Mobilization 2018 slides https://bit.ly/rocket-field-mob