2024-05-01から1ヶ月間の記事一覧

Room Entity, DAO, Database and Repository

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Entity @Entity(tableName = "subscriber_data_table") data class Subscriber( @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "subscriber_id") val id: Int, @ColumnInfo(name…

Gradle Setups

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Enable DataBinding android { dataBinding { enable = true } } Kapt plugins { id("kotlin-kapt") } Lifecycle Reference dependencies { val lifecycle_version = "2.8.0" // ViewMod…

SwiftUI Fonts

Preview with SwiftData

1. Create a file PreviewContainer @MainActor let previoewContainer: ModelContainer = { do { let container = try ModelContainer(for: Match.self, configurations: ModelConfiguration(isStoredInMemoryOnly: true)) let match = Match(...) containe…

Live Data Builder

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. A Live Data Builder can execute a coroutine block and set the value to the live data attributes. Example: class MainActivityViewModel: ViewModel() { private val usersReposit…

LifeCycleScope

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. LifeCycleScope is similar to ViewModelScope, just it is used for life cycle owner (e.g. Activity, Fragment). Usage: lifeCycleScope { ... }

ViewModelScope

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. When not using ViewModelScope: class MainActivityViewModel: ViewModel() { private val myJob = Job() private val myScope = CoroutineScope(Dispatchers.IO + myJob) fun getUserD…

Async Await

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Assume we have these two function, private suspend fun getStock1(): Int { delay(1000) return 2 } private suspend fun getStock2(): Int { delay(2000) return 3 } and we want to…

Switch Thread of Coroutine

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. CoroutineScope(Dispatchers.IO).launch { // heavy tasks withContext(Dispatchers.Main) { // UI changes } }

Set up Coroutine

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Import Coroutine Latest version can be found here. In app's build.gradle, add the dependencies: dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-co…