SlideShare a Scribd company logo
This work is licensed under the Apache 2.0 License
Android Study Jams
Prior Programming Experience Track: Session 4
This work is licensed under the Apache 2.0 License
Prior Programming Experience Track: Session 4
Android Study Jams
This work is licensed under the Apache 2.0 License
Learning Objectives
० Learn about Repository Layer to manage Data
० Using WorkManager for scheduled tasks
० Design your app using Material Design
० Test your app
This work is licensed under the Apache 2.0 License
A little about me
This work is licensed under the Apache 2.0 License
Concept Overview
What is the Repository Layer?
This work is licensed under the Apache 2.0 License
Repository Modules handle data operations.
This work is licensed under the Apache 2.0 License
Repository Components
● Model (Database)
● Remote Data (Network)
● Provides API for accessing both
This work is licensed under the Apache 2.0 License
Why Repository
● Separation of Concerns
● Activity/Fragment are glue
● UI driven by data
● Testable and Consistent
This work is licensed under the Apache 2.0 License
Repository cont...
● DI vs Service Lookup
● View Models and Streams
● ORMs
This work is licensed under the Apache 2.0 License
Databases
● Caches
● Room Library - ORM
● Database Refresh Strategy
● Observables
This work is licensed under the Apache 2.0 License
Room
● @Entity @ColumnInfo
● @Dao
● @Insert, @Delete, and @Update
● @Query
This work is licensed under the Apache 2.0 License
Don’t forget to test!
This work is licensed under the Apache 2.0 License
@Dao
interface VideoDao {
@Query("select * from databasevideo")
fun getVideos(): LiveData<List<DatabaseVideo>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll( videos: List<DatabaseVideo>)
}
@Database(entities = [DatabaseVideo::class], version = 1)
abstract class VideosDatabase: RoomDatabase() {
abstract val videoDao: VideoDao
}
private lateinit var INSTANCE: VideosDatabase
fun getDatabase(context: Context): VideosDatabase {
synchronized(VideosDatabase::class.java) {
if (!::INSTANCE.isInitialized) {
INSTANCE = Room.databaseBuilder(context.applicationContext,
VideosDatabase::class.java,
"videos").build()
}
}
return INSTANCE
}
Room.kt
This work is licensed under the Apache 2.0 License
@Entity
data class DatabaseVideo constructor(
@PrimaryKey
val url: String,
val updated: String,
val title: String,
val description: String,
val thumbnail: String)
/**
* Map DatabaseVideos to domain entities
*/
fun List<DatabaseVideo>.asDomainModel(): List<DevByteVideo> {
return map {
DevByteVideo(
url = it.url,
title = it.title,
description = it.description,
updated = it.updated,
thumbnail = it.thumbnail)
}
}
DatabaseEntities.kt
This work is licensed under the Apache 2.0 License
Network
● REST Services
● Retrofit Library - for API Calls
● Moshi - for JSON to Model
● Observables
This work is licensed under the Apache 2.0 License
interface DevbyteService {
@GET("devbytes")
suspend fun getPlaylist(): NetworkVideoContainer
}
object DevByteNetwork {
// Configure retrofit to parse JSON and use coroutines
private val retrofit = Retrofit.Builder()
.baseUrl("https://android-kotlin-fun-mars-server.appspot.com/")
.addConverterFactory(MoshiConverterFactory.create())
.build()
val devbytes = retrofit.create(DevbyteService::class.java)
}
Service.kt
This work is licensed under the Apache 2.0 License
@JsonClass(generateAdapter = true)
data class NetworkVideoContainer(val videos: List<NetworkVideo>)
@JsonClass(generateAdapter = true)
data class NetworkVideo(
val title: String,
val description: String,
val url: String,
val updated: String,
val thumbnail: String,
val closedCaptions: String?)
fun NetworkVideoContainer.asDomainModel(): List<DevByteVideo> {}
fun NetworkVideoContainer.asDatabaseModel(): List<DatabaseVideo> {}
DTO.kt
This work is licensed under the Apache 2.0 License
Work Manager
This work is licensed under the Apache 2.0 License
Work Manager
● For scheduling repeating tasks
● Define constraints
● Retry
● Chaining
● Threading
This work is licensed under the Apache 2.0 License
Material Design
This work is licensed under the Apache 2.0 License
Testing
This work is licensed under the Apache 2.0 License
Testing
This work is licensed under the Apache 2.0 License
Demos
This work is licensed under the Apache 2.0 License
Learn More
This work is licensed under the Apache 2.0 License
Want to learn more?
● Official Android Developers Site: https://developer.android.com/
● Android Samples on GitHub
● Official Android Developers Blog (for announcements)
● Android Developers Medium Blog (for more technical articles)
● Android Developers YouTube channel
● Follow @AndroidDev on Twitter
● Subscribe to the Android Developer Newsletter
● Kotlin Vocabulary series
● Official Kotlin language site
Version 1.0

More Related Content

What's hot (20)

PPTX
Final session 1
IpsitaSanyal1
 
PPTX
Android development-tutorial
ilias ahmed
 
PDF
Android tutorial
master760
 
PPTX
Intro session kotlin
MohammedMehdiPatel
 
PPTX
Info session on android study jams
ArjavDesai3
 
PPTX
Android study jams - new to programming track sessions 2
alfinazilah
 
PPTX
The First Ever Android Meet-up
vriddhigupta
 
PPTX
Android study jams
NaveenK158
 
PPTX
Android study jams 2021 [collab] [master]
GDSCIIITBbsr
 
PPTX
Android study jams 1
DSCBVRITH
 
PPTX
Week 1 - Android Study Jams
JoannaCamille2
 
PPTX
Android Study Jams Session 5
SadhanaParameswaran
 
PPTX
Google I/O 2019 - what's new in Android Q and Jetpack
Sunita Singh
 
PDF
Android Workshop Part 1
NAILBITER
 
PPTX
Android Study Jams - Session 1
SadhanaParameswaran
 
PPTX
Study Jam Session 2
Boston Android
 
PPTX
Android Study Jams Session 4
SadhanaParameswaran
 
PPTX
Android Study Jams - Session 3
SadhanaParameswaran
 
PPTX
Prior programming experience track
AshwinRaj57
 
PPTX
Android Study Jams - Session 2
SadhanaParameswaran
 
Final session 1
IpsitaSanyal1
 
Android development-tutorial
ilias ahmed
 
Android tutorial
master760
 
Intro session kotlin
MohammedMehdiPatel
 
Info session on android study jams
ArjavDesai3
 
Android study jams - new to programming track sessions 2
alfinazilah
 
The First Ever Android Meet-up
vriddhigupta
 
Android study jams
NaveenK158
 
Android study jams 2021 [collab] [master]
GDSCIIITBbsr
 
Android study jams 1
DSCBVRITH
 
Week 1 - Android Study Jams
JoannaCamille2
 
Android Study Jams Session 5
SadhanaParameswaran
 
Google I/O 2019 - what's new in Android Q and Jetpack
Sunita Singh
 
Android Workshop Part 1
NAILBITER
 
Android Study Jams - Session 1
SadhanaParameswaran
 
Study Jam Session 2
Boston Android
 
Android Study Jams Session 4
SadhanaParameswaran
 
Android Study Jams - Session 3
SadhanaParameswaran
 
Prior programming experience track
AshwinRaj57
 
Android Study Jams - Session 2
SadhanaParameswaran
 

Similar to Android Study Jam 2021 Session 4 slides (20)

PDF
Paging using Paging 3
Fandy Gotama
 
PDF
MobiConf 2018 | Room: an SQLite object mapping library
Magda Miu
 
PPTX
Paging Like A Pro
Gabor Varadi
 
PDF
Capability Driven Design - Rapid Talks - November 2020
Andrzej Jóźwiak
 
PDF
Android Data Persistence
Romain Rochegude
 
PDF
Android Architecture Components
Darshan Parikh
 
PPTX
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Waheed Nazir
 
PDF
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
 
PDF
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
PPTX
Android Architecture - Khoa Tran
Tu Le Dinh
 
PDF
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
PPTX
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
PDF
Reactive clean architecture
Viktor Nyblom
 
PPTX
Android Architecture Components - Guy Bar on, Vonage
DroidConTLV
 
PDF
Android Data Persistence
Jussi Pohjolainen
 
PDF
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
PDF
[App devcon 18] Brace yourself with Android Architecture Components
Michelantonio Trizio
 
PPT
Persistences
Training Guide
 
PPTX
Android Database
Dr Karthikeyan Periasamy
 
DOCX
Android Sample Project By Wael Almadhoun
Wael Almadhoun, MSc, PMP®
 
Paging using Paging 3
Fandy Gotama
 
MobiConf 2018 | Room: an SQLite object mapping library
Magda Miu
 
Paging Like A Pro
Gabor Varadi
 
Capability Driven Design - Rapid Talks - November 2020
Andrzej Jóźwiak
 
Android Data Persistence
Romain Rochegude
 
Android Architecture Components
Darshan Parikh
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Waheed Nazir
 
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
 
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Android Architecture - Khoa Tran
Tu Le Dinh
 
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
Reactive clean architecture
Viktor Nyblom
 
Android Architecture Components - Guy Bar on, Vonage
DroidConTLV
 
Android Data Persistence
Jussi Pohjolainen
 
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
[App devcon 18] Brace yourself with Android Architecture Components
Michelantonio Trizio
 
Persistences
Training Guide
 
Android Database
Dr Karthikeyan Periasamy
 
Android Sample Project By Wael Almadhoun
Wael Almadhoun, MSc, PMP®
 
Ad

Recently uploaded (20)

PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Ad

Android Study Jam 2021 Session 4 slides

  • 1. This work is licensed under the Apache 2.0 License Android Study Jams Prior Programming Experience Track: Session 4
  • 2. This work is licensed under the Apache 2.0 License Prior Programming Experience Track: Session 4 Android Study Jams
  • 3. This work is licensed under the Apache 2.0 License Learning Objectives ० Learn about Repository Layer to manage Data ० Using WorkManager for scheduled tasks ० Design your app using Material Design ० Test your app
  • 4. This work is licensed under the Apache 2.0 License A little about me
  • 5. This work is licensed under the Apache 2.0 License Concept Overview What is the Repository Layer?
  • 6. This work is licensed under the Apache 2.0 License Repository Modules handle data operations.
  • 7. This work is licensed under the Apache 2.0 License Repository Components ● Model (Database) ● Remote Data (Network) ● Provides API for accessing both
  • 8. This work is licensed under the Apache 2.0 License Why Repository ● Separation of Concerns ● Activity/Fragment are glue ● UI driven by data ● Testable and Consistent
  • 9. This work is licensed under the Apache 2.0 License Repository cont... ● DI vs Service Lookup ● View Models and Streams ● ORMs
  • 10. This work is licensed under the Apache 2.0 License Databases ● Caches ● Room Library - ORM ● Database Refresh Strategy ● Observables
  • 11. This work is licensed under the Apache 2.0 License Room ● @Entity @ColumnInfo ● @Dao ● @Insert, @Delete, and @Update ● @Query
  • 12. This work is licensed under the Apache 2.0 License Don’t forget to test!
  • 13. This work is licensed under the Apache 2.0 License @Dao interface VideoDao { @Query("select * from databasevideo") fun getVideos(): LiveData<List<DatabaseVideo>> @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll( videos: List<DatabaseVideo>) } @Database(entities = [DatabaseVideo::class], version = 1) abstract class VideosDatabase: RoomDatabase() { abstract val videoDao: VideoDao } private lateinit var INSTANCE: VideosDatabase fun getDatabase(context: Context): VideosDatabase { synchronized(VideosDatabase::class.java) { if (!::INSTANCE.isInitialized) { INSTANCE = Room.databaseBuilder(context.applicationContext, VideosDatabase::class.java, "videos").build() } } return INSTANCE } Room.kt
  • 14. This work is licensed under the Apache 2.0 License @Entity data class DatabaseVideo constructor( @PrimaryKey val url: String, val updated: String, val title: String, val description: String, val thumbnail: String) /** * Map DatabaseVideos to domain entities */ fun List<DatabaseVideo>.asDomainModel(): List<DevByteVideo> { return map { DevByteVideo( url = it.url, title = it.title, description = it.description, updated = it.updated, thumbnail = it.thumbnail) } } DatabaseEntities.kt
  • 15. This work is licensed under the Apache 2.0 License Network ● REST Services ● Retrofit Library - for API Calls ● Moshi - for JSON to Model ● Observables
  • 16. This work is licensed under the Apache 2.0 License interface DevbyteService { @GET("devbytes") suspend fun getPlaylist(): NetworkVideoContainer } object DevByteNetwork { // Configure retrofit to parse JSON and use coroutines private val retrofit = Retrofit.Builder() .baseUrl("https://android-kotlin-fun-mars-server.appspot.com/") .addConverterFactory(MoshiConverterFactory.create()) .build() val devbytes = retrofit.create(DevbyteService::class.java) } Service.kt
  • 17. This work is licensed under the Apache 2.0 License @JsonClass(generateAdapter = true) data class NetworkVideoContainer(val videos: List<NetworkVideo>) @JsonClass(generateAdapter = true) data class NetworkVideo( val title: String, val description: String, val url: String, val updated: String, val thumbnail: String, val closedCaptions: String?) fun NetworkVideoContainer.asDomainModel(): List<DevByteVideo> {} fun NetworkVideoContainer.asDatabaseModel(): List<DatabaseVideo> {} DTO.kt
  • 18. This work is licensed under the Apache 2.0 License Work Manager
  • 19. This work is licensed under the Apache 2.0 License Work Manager ● For scheduling repeating tasks ● Define constraints ● Retry ● Chaining ● Threading
  • 20. This work is licensed under the Apache 2.0 License Material Design
  • 21. This work is licensed under the Apache 2.0 License Testing
  • 22. This work is licensed under the Apache 2.0 License Testing
  • 23. This work is licensed under the Apache 2.0 License Demos
  • 24. This work is licensed under the Apache 2.0 License Learn More
  • 25. This work is licensed under the Apache 2.0 License Want to learn more? ● Official Android Developers Site: https://developer.android.com/ ● Android Samples on GitHub ● Official Android Developers Blog (for announcements) ● Android Developers Medium Blog (for more technical articles) ● Android Developers YouTube channel ● Follow @AndroidDev on Twitter ● Subscribe to the Android Developer Newsletter ● Kotlin Vocabulary series ● Official Kotlin language site Version 1.0