75.6 Adding the Repository
Add a new class named ProductRepository to the project, with the Class option selected.
The repository class will be responsible for interacting with the Room database on behalf of the ViewModel and will need to provide methods that use the DAO to insert, delete and query product records. With the exception of the getAllProducts() DAO method (which returns a LiveData object) these database operations will need to be performed on separate threads from the main thread.
Remaining within the ProductRepository.kt file, make the following changes :
package com.ebookfrenzy.roomdemo
import android.app.Application
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.*
class ProductRepository(application: Application) {
val searchResults = MutableLiveData<List<Product>>()
}
The above declares a MutableLiveData variable...