addMediaItem method
- MediaItem item
Add a MediaItem to history. This should be called at startup when the media item is launched.
Implementation
void addMediaItem(MediaItem item) {
_database.writeTxnSync(() {
_database.mediaItems.deleteByUniqueKeySync(item.uniqueKey);
item.id = null;
_database.mediaItems.putSync(item);
int countInSameHistory = _database.mediaItems
.filter()
.mediaTypeIdentifierEqualTo(item.mediaTypeIdentifier)
.countSync();
if (maximumMediaHistoryItems < countInSameHistory) {
int surplus = countInSameHistory - maximumSearchHistoryItems;
_database.mediaItems
.filter()
.mediaTypeIdentifierEqualTo(item.mediaTypeIdentifier)
.limit(surplus)
.build()
.deleteAllSync();
}
});
}