JungIn Choi
04/12/2021, 1:06 PMDay29
• 80% thru Lesson8
◦ 1) Create Retrofit object (addConverterFactory(), baseUrl()) --> 2) Define a service API interface (GET annotation to specify an endpoint) --> 3) Create Retrofit Service (retrofit._create_(interface))
▪︎ Retrofit Call object - starts network request
▪︎ .enqueue() method - starts the request on background thread, calls Callbacks when the request is complete
▪︎ should add internet permissions in manifest, by adding <uses-permissions tag (Android libraries can have its own manifest file. Can check the permission it asks)
▪︎ Moshi library - parses JSON response to kotlin objects
• Needs a data class to store the JSON values (Data class property names should match the names inside JSON response, or attach JSON annotation
▪︎ Deferred object - await() - suspend function which causes the code to await without blocking
◦ Displaying a photo from URL, using Glide library
▪︎ Steps needed - download, buffer, decode from compressed to android compatible format, cache ... (--> all should happen in background thread)
▪︎ Set up placeholder image, error image
• Etc.
◦ (recap) coroutine job - provides methods for cancelling & determining the state of a coroutine etc
◦ (recap) Dispatcher sends off coroutines to run on various threads (Dispatcher.main, Dispatcher.io) / Main dispatcher uses UI thread.
◦ (recap) ? is nullable
◦ (recap) kotlin scope function - let (link) (let{} returns whatever the lambda block evaluates to / apply{} will return the context object)
Self-Comment
• Quite a lot of contents than I expected. My ego urges myself to finish lesson8 but I have morning doctor appointment so I'll just have to wrap it up here.
• Hoping to finish this course by wednesday!
Goals Tomorrow
• Finish Lesson8 - parcel stuff / Finish lesson9