Dagger - Put Component in Application

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Usually we define the dagger component in custom application class, which will init before any activity. 1. Create Custom Application Class class SmartPhoneApplication: Appl…

Dagger - Module with Parameter

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Please read this article first. If the MemoryCardModule has a parameter memorySize, @Module class MemoryCardModule(private val memorySize: Int) { @Provides fun providesMemor…

Dagger Field Injection

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. In this article we introduced created an abstract function getSmartPhone() and call it to get SmartPhone instance. We can also inject it into another class. This article I'l…

Dagger Binds

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. Please read last article before reading this one. Assuming class SmartPhone has another dependency Battery, and Battery is an interface, NickelCadmiumBattery is its implemen…

Dagger Module and Provides

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. In last article we mentioned we need to add @Inject before dependency class's constructor. However some classes might came from 3rd party library, then we cannot modify them…

Dagger Basic Usage

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Import Dagger Please check this note 2. Change Class's Constructor Before: class SmartPhone(...) { ... } After: class SmartPhone @Inject constructor(...) { ... } 3. Creat…

Work Manager - Request Chain

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. val parallelRequest = listOf(request1A, request1B) workManager .beginWith(parallelRequest) .then(request2) .then(request3) .enqueue()

Work Manager - Input and Output Data

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Read Work Manager - One Time Request link 2. Modify UploadWorker class UploadWorker(context: Context, params: WorkerParameters): Worker(context, params) { override fun do…

Work Manager - Periodic Work Request

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Read Work Manager - One Time Request link 2. Write Function private fun setPeriodicWorkRequest() { val periodicWorkRequest = PeriodicWorkRequest .Builder(UploadWorker::cl…

Work Manager - Add Constraints

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Read previous note note 2. Add User Permissions in AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 3. Edit Function SetOn…</uses-permission></uses-permission>

Work Manager - One Time Request

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Set up Gradle for Work Manager Please check this note. 2. Create Worker Class class UploadWorker(context: Context, params: WorkerParameters): Worker(context, params) { ov…

Send Notification

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. In AndroidManifest.xml, add: <manifest ...> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> ... </manifest> In MainActivity.kt: class MainActivity : AppCompatActivity() { private val channelID = "com.mxy.notif…

Usage of Retrofit

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Set up Gradle Check this note. 2. Set up Internet Permissions Check this note. 3. Create Class RetrofitInstance class RetrofitInstance { companion object { val BASE_URL =…

Create Kotlin Data Class from Json

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Go to Settings of Android Studio, add the plugin "JSON To Kotlin Class). 2. Right click a folder, now under "New" option we have an option "Kotlin data class File from JS…

Enable Using Internet

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. In AndroidManifest.xml: <manifest ...> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> </uses-permission></uses-permission></manifest>

Room Auto Migration with Column Name Change

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. For example, in table "student_info", we want to change column "student_course" to "student_subject". @Database(entities = [Student::class], version = 2, autoMigrations = [ …

Room Auto Migration

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. We want to add email to the Student entity. 1. Edit Entity Origin: @Entity(tableName = "student_info") data class Student( @PrimaryKey(autoGenerate = true) @ColumnInfo(name …

Sync SwiftData with iCloud

Constrains: Cannot user @Attribute(.unique). All properties must have default values or be optional. All relationships must be optional. Process: Add iCloud capability, check CloudKit option, provide it a CloudKit container. Add Background…

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…

Recycler View

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. 1. Add Recycler View Create a new project and drag a recycler view component to activity_main.xml, give it id name "recyclerView". 2. Create a Layout for List Item Name it l…

Pass Data Between Fragments

This is my note for Udemy lesson: Advanced Android Bootcamp 2024. First, check my previous note Then in HomeFragment, do: val bundle = bundleOf("user_name" to binding.editTextText.text.toString()) it.findNavController().navigate(R.id.actio…