-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 4066 - predownload and top 1K download as background tasks (#4131)
Deleted file: * `products_preload_helper.dart` New files: * `background_task.dart`: Abstract background task. * `background_task_full_refresh.dart`: Background task about refreshing all the already downloaded products. * `background_task_offline.dart`: Background task about pre-downloading top n products for offline usage. Impacted files: * `background_task_barcode.dart` * `background_task_crop.dart`: refactored * `background_task_details.dart`: refactored * `background_task_hunger_games.dart`: refactored * `background_task_image.dart`: refactored * `background_task_manager.dart` * `background_task_refresh_later.dart`: refactored * `background_task_unselect.dart`: refactored * `background_task_upload.dart`: refactored * `offline_data_page.dart`: now using background task for offline and full refresh tasks * `offline_tasks_page.dart`: dealing with the "no barcode" case * `operation_type.dart`: added values `offline` and `fullRefresh`; added `processName` field; added a `BackgroundTask` constructor * `product_refresher.dart`: bug fix
- Loading branch information
1 parent
e1912c8
commit 55b4894
Showing
17 changed files
with
523 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/smooth_app/lib/background/background_task_barcode.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:smooth_app/background/background_task.dart'; | ||
import 'package:smooth_app/database/local_database.dart'; | ||
import 'package:smooth_app/pages/product/common/product_refresher.dart'; | ||
|
||
/// Abstract background task that involves a single barcode. | ||
abstract class BackgroundTaskBarcode extends BackgroundTask { | ||
const BackgroundTaskBarcode({ | ||
required super.processName, | ||
required super.uniqueId, | ||
required super.languageCode, | ||
required super.user, | ||
required super.country, | ||
required super.stamp, | ||
required this.barcode, | ||
}); | ||
|
||
BackgroundTaskBarcode.fromJson(Map<String, dynamic> json) | ||
: barcode = json[_jsonTagBarcode] as String, | ||
super.fromJson(json); | ||
|
||
final String barcode; | ||
|
||
static const String _jsonTagBarcode = 'barcode'; | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> result = super.toJson(); | ||
result[_jsonTagBarcode] = barcode; | ||
return result; | ||
} | ||
|
||
/// Uploads data changes. | ||
@protected | ||
Future<void> upload(); | ||
|
||
/// Executes the background task: upload, download, update locally. | ||
@override | ||
Future<void> execute(final LocalDatabase localDatabase) async { | ||
await upload(); | ||
await _downloadAndRefresh(localDatabase); | ||
} | ||
|
||
/// Downloads the whole product, updates locally. | ||
Future<void> _downloadAndRefresh(final LocalDatabase localDatabase) async => | ||
ProductRefresher().silentFetchAndRefresh( | ||
barcode: barcode, | ||
localDatabase: localDatabase, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.