execute method
- LocalDatabase localDatabase
override
Executes the background task: upload, download, update locally.
Implementation
@override
Future<void> execute(LocalDatabase localDatabase) async {
final DaoProduct daoProduct = DaoProduct(localDatabase);
final DaoWorkBarcode daoWorkBarcode = DaoWorkBarcode(localDatabase);
for (final ProductType productType in ProductType.values) {
await daoWorkBarcode.deleteWork(WorkType.freshKP.getWorkTag(productType));
await daoWorkBarcode.deleteWork(
WorkType.freshNoKP.getWorkTag(productType),
);
}
// We separate the products into lists, products with or without
// knowledge panels, and split by product types.
final Map<String, List<String>> split = await daoProduct.splitAllProducts((
Product product,
) {
final bool noKP = product.knowledgePanels == null;
final WorkType workType = noKP ? WorkType.freshNoKP : WorkType.freshKP;
final ProductType productType = product.productType ?? ProductType.food;
return workType.getWorkTag(productType);
});
for (int i = 0; i <= 1; i++) {
final bool noKP = i == 0;
final WorkType workType = noKP ? WorkType.freshNoKP : WorkType.freshKP;
for (final ProductType productType in ProductType.values) {
final String tag = workType.getWorkTag(productType);
final List<String>? barcodes = split[tag];
if (barcodes == null) {
continue;
}
await _startDownloadTask(
barcodes: barcodes,
work: tag,
localDatabase: localDatabase,
downloadFlag: noKP
? BackgroundTaskDownloadProducts.flagMaskExcludeKP
: 0,
productType: productType,
);
}
}
}