SlideShare a Scribd company logo
1 of 25
Download to read offline
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

Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorialilias ahmed
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialmaster760
 
Info session on android study jams
Info session on android study jamsInfo session on android study jams
Info session on android study jamsArjavDesai3
 
Android study jams - new to programming track sessions 2
Android study jams - new to programming track sessions 2Android study jams - new to programming track sessions 2
Android study jams - new to programming track sessions 2alfinazilah
 
The First Ever Android Meet-up
The First Ever Android Meet-upThe First Ever Android Meet-up
The First Ever Android Meet-upvriddhigupta
 
Android study jams
Android study jamsAndroid study jams
Android study jamsNaveenK158
 
Android study jams 2021 [collab] [master]
Android study jams 2021 [collab] [master]Android study jams 2021 [collab] [master]
Android study jams 2021 [collab] [master]GDSCIIITBbsr
 
Android study jams 1
Android study jams 1Android study jams 1
Android study jams 1DSCBVRITH
 
Week 1 - Android Study Jams
Week 1 - Android Study JamsWeek 1 - Android Study Jams
Week 1 - Android Study JamsJoannaCamille2
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackSunita Singh
 
Android Workshop Part 1
Android Workshop Part 1Android Workshop Part 1
Android Workshop Part 1NAILBITER
 
Prior programming experience track
Prior programming experience trackPrior programming experience track
Prior programming experience trackAshwinRaj57
 

What's hot (20)

Final session 1
Final session 1Final session 1
Final session 1
 
Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Intro session kotlin
Intro session kotlinIntro session kotlin
Intro session kotlin
 
Info session on android study jams
Info session on android study jamsInfo session on android study jams
Info session on android study jams
 
Android study jams - new to programming track sessions 2
Android study jams - new to programming track sessions 2Android study jams - new to programming track sessions 2
Android study jams - new to programming track sessions 2
 
The First Ever Android Meet-up
The First Ever Android Meet-upThe First Ever Android Meet-up
The First Ever Android Meet-up
 
Android study jams
Android study jamsAndroid study jams
Android study jams
 
Android study jams 2021 [collab] [master]
Android study jams 2021 [collab] [master]Android study jams 2021 [collab] [master]
Android study jams 2021 [collab] [master]
 
Android study jams 1
Android study jams 1Android study jams 1
Android study jams 1
 
Week 1 - Android Study Jams
Week 1 - Android Study JamsWeek 1 - Android Study Jams
Week 1 - Android Study Jams
 
Android Study Jams Session 5
Android Study Jams Session 5Android Study Jams Session 5
Android Study Jams Session 5
 
Google I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and JetpackGoogle I/O 2019 - what's new in Android Q and Jetpack
Google I/O 2019 - what's new in Android Q and Jetpack
 
Android Workshop Part 1
Android Workshop Part 1Android Workshop Part 1
Android Workshop Part 1
 
Android Study Jams - Session 1
Android Study Jams - Session 1Android Study Jams - Session 1
Android Study Jams - Session 1
 
Study Jam Session 2
Study Jam Session 2Study Jam Session 2
Study Jam Session 2
 
Android Study Jams Session 4
Android Study Jams Session 4Android Study Jams Session 4
Android Study Jams Session 4
 
Android Study Jams - Session 3
Android Study Jams - Session 3Android Study Jams - Session 3
Android Study Jams - Session 3
 
Prior programming experience track
Prior programming experience trackPrior programming experience track
Prior programming experience track
 
Android Study Jams - Session 2
Android Study Jams - Session 2Android Study Jams - Session 2
Android Study Jams - Session 2
 

Similar to Android Study Jam 2021 Session 4 slides

ASJ Session 3 | Get Data From Internet
ASJ Session 3 | Get Data From InternetASJ Session 3 | Get Data From Internet
ASJ Session 3 | Get Data From InternetTejasMane18
 
Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2DSCIGDTUW
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7WASdev Community
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7Kevin Sutter
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 
NuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LDNuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LDJeff Handley
 
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...DevDay.org
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Microsoft
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014Hojoong Kim
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
OpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesOpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesSamuel Terburg
 
Continuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventContinuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventJohn Schneider
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Amazon Web Services
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
What is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna NookellaWhat is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna Nookellamuralikrishnanookella
 
JCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxJCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxGrace Jansen
 

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

ASJ Session 3 | Get Data From Internet
ASJ Session 3 | Get Data From InternetASJ Session 3 | Get Data From Internet
ASJ Session 3 | Get Data From Internet
 
RoR guide_p1
RoR guide_p1RoR guide_p1
RoR guide_p1
 
Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
NuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LDNuGet 3.0 - Transitioning from OData to JSON-LD
NuGet 3.0 - Transitioning from OData to JSON-LD
 
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...
[DevDay 2017] OpenShift Enterprise - Speaker: Linh Do - DevOps Engineer at Ax...
 
Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015Red Hat Forum Benelux 2015
Red Hat Forum Benelux 2015
 
Session-1.pptx
Session-1.pptxSession-1.pptx
Session-1.pptx
 
Open shift and docker - october,2014
Open shift and docker - october,2014Open shift and docker - october,2014
Open shift and docker - october,2014
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
OpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesOpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetes
 
Continuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:InventContinuous Deployment @ AWS Re:Invent
Continuous Deployment @ AWS Re:Invent
 
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
Continuous Integration and Deployment Best Practices on AWS (ARC307) | AWS re...
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
What is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna NookellaWhat is WebDAV - uploaded by Murali Krishna Nookella
What is WebDAV - uploaded by Murali Krishna Nookella
 
JCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxJCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptx
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....rightmanforbloodline
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 

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