I have a database that has a table with multiple columns, and I wish to only load 3 when showing my list and before the user selects one item to show it.
In order to do this I have created the following dao
@Dao
interface ReportDao {
@Query("SELECT id, name, description, created FROM reports ORDER BY created DESC")
fun loadShortReports(): LiveData<List<ReportItemDO>>
@Insert(onConflict = OnConflictStrategy.FAIL)
fun saveReports(reports: List<ReportDO>): Completable
}
this is my report entity:
@Entity(tableName = "reports")
data class ReportDO(
@PrimaryKey val id: UUID
, val name: String
, val description: String
.......)
and this is the minified entity for the list
data class ReportItemDO(
override val id: UUID
, override val name: String
, override val description: String
, @ColumnInfo(name = "created") override val date: Date)
: ReportItemVO
(the ReportItemVO interface is what the list expects)
When the application loads, everything loads correctly
but in order to test this I created a simple button that adds a random ReportDO
item to the database using this code:
repository.addReport(
report
).subscribeOn(schedulers.subscribeScheduler)
.observeOn(schedulers.observeScheduler)
.subscribe {
Log.i(MainViewModel.TAG, "success")
}
which in turn calls
reportDao.saveReports(listof(report))
but the list does not seem to get updated automatically
When I close and restart the application the list is updated
I am assuming this is because I'm only taking a subset of the entity so Room does not know it should trigger the update
Is there a way to make Room understand that the LiveData it created was updated and trigger the loading process again?
Also , because I wish to add a refresh button, is there a way to send Room a message to manually reload the data?