-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 3595 - transient file refactoring and fixes (#3939)
New file: * `background_task_upload.dart`: Background task about generic file upload. Impacted files: * `abstract_background_task.dart`: added a `recover` abstract method * `background_task_crop.dart`: now extends new class `BackgroundTaskUpload` * `background_task_image.dart`: now extends new class `BackgroundTaskUpload` * `background_task_manager.dart`: now calls `recover`for each task at run time; minor fix about "internet error" * `background_task_unselect.dart`: minor refactoring; minor fix removing the transient file * `crop_page.dart`: minor refactoring * `edit_ingredients_page.dart`: minor refactoring * `image_upload_card.dart`: minor refactoring * `product_cards_helper.dart`: minor refactoring * `product_image_viewer.dart`: minor refactoring * `smooth_product_image.dart`: minor refactoring * `transient_file.dart`: refactored as a "real" class, not a static one
- Loading branch information
1 parent
72f3396
commit 6e72ff0
Showing
13 changed files
with
196 additions
and
188 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
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
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
69 changes: 69 additions & 0 deletions
69
packages/smooth_app/lib/background/background_task_upload.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,69 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:openfoodfacts/openfoodfacts.dart'; | ||
import 'package:smooth_app/background/abstract_background_task.dart'; | ||
import 'package:smooth_app/database/local_database.dart'; | ||
import 'package:smooth_app/database/transient_file.dart'; | ||
|
||
/// Background task about generic file upload. | ||
abstract class BackgroundTaskUpload extends AbstractBackgroundTask { | ||
const BackgroundTaskUpload({ | ||
required super.processName, | ||
required super.uniqueId, | ||
required super.barcode, | ||
required super.languageCode, | ||
required super.user, | ||
required super.country, | ||
required super.stamp, | ||
required this.imageField, | ||
required this.croppedPath, | ||
required this.rotationDegrees, | ||
required this.cropX1, | ||
required this.cropY1, | ||
required this.cropX2, | ||
required this.cropY2, | ||
}); | ||
|
||
final String imageField; | ||
final String croppedPath; | ||
final int rotationDegrees; | ||
final int cropX1; | ||
final int cropY1; | ||
final int cropX2; | ||
final int cropY2; | ||
|
||
TransientFile _getTransientFile() => TransientFile( | ||
ImageField.fromOffTag(imageField)!, | ||
barcode, | ||
getLanguage(), | ||
); | ||
|
||
@protected | ||
void putTransientImage(final LocalDatabase localDatabase) => | ||
_getTransientFile().putImage( | ||
localDatabase, | ||
File(croppedPath), | ||
); | ||
|
||
@protected | ||
void removeTransientImage(final LocalDatabase localDatabase) => | ||
_getTransientFile().removeImage(localDatabase); | ||
|
||
File? _getTransientImage() => _getTransientFile().getImage(); | ||
|
||
@override | ||
Future<void> recover(final LocalDatabase localDatabase) async { | ||
final File? transientFile = _getTransientImage(); | ||
if (transientFile == null) { | ||
putTransientImage(localDatabase); | ||
} | ||
} | ||
|
||
static String getStamp( | ||
final String barcode, | ||
final String imageField, | ||
final String language, | ||
) => | ||
'$barcode;image;$imageField;$language'; | ||
} |
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.