mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-06 18:25:11 +08:00

New file: * `work_type.dart`: Type of long download work for some background tasks. Impacted files: * `background_task.dart`: removed the default `uriProductHelper` getter * `background_task_barcode.dart`: added a `uriProductHelper` getter that depends on the `productType` * `background_task_download_products.dart`: refactored the access to product type * `background_task_full_refresh.dart`: split by product type * `background_task_language_refresh.dart`: split by product type * `background_task_offline.dart`: refactored the access to product type * `background_task_progressing.dart`: added the `productType` parameter; moved code to new `WorkType` class * `background_task_top_barcodes.dart`: refactored the access to product type * `dao_product.dart`: new methods `getProductTypes` and `splitAllProducts`; refactored with product type * `lazy_counter.dart`: explicitly counting the "food" products * `newsfeed_provider.dart`: explicitly getting the news from "food" * `offline_data_page.dart`: now displaying "download top N products" buttons for each product type; stats for each product type * `offline_tasks_page.dart`: enhanced "work text" algo, now depending on product type * `operation_type.dart`: enhanced "key" algo, now depending on product type * `ordered_nutrients_cache.dart`: explicitly using the "food" nutrients * `product_list_page.dart`: now reloading products from their server * `product_list_popup_items.dart`: now linking to the first server with products * `product_query.dart`: made product type a mandatory parameter * `product_refresher.dart`: added mandatory parameter product type * `random_questions_query.dart`: explicitly ask for "food" robotoff products * `temp_product_list_share_helper.dart`: added mandatory parameter product type * `user_preferences_dev_debug_info.dart`: added explicit use of "food" data
39 lines
1.3 KiB
Dart
39 lines
1.3 KiB
Dart
import 'package:openfoodfacts/openfoodfacts.dart';
|
|
import 'package:smooth_app/database/local_database.dart';
|
|
import 'package:smooth_app/pages/product/common/product_refresher.dart';
|
|
import 'package:smooth_app/query/product_query.dart';
|
|
import 'package:smooth_app/query/questions_query.dart';
|
|
|
|
/// Robotoff questions helper, for random product questions.
|
|
class RandomQuestionsQuery extends QuestionsQuery {
|
|
@override
|
|
Future<List<RobotoffQuestion>> getQuestions(
|
|
final LocalDatabase localDatabase,
|
|
final int count,
|
|
) async {
|
|
final RobotoffQuestionResult result = await RobotoffAPIClient.getQuestions(
|
|
ProductQuery.getLanguage(),
|
|
user: ProductQuery.getReadUser(),
|
|
countries: <OpenFoodFactsCountry>[ProductQuery.getCountry()],
|
|
count: count,
|
|
questionOrder: RobotoffQuestionOrder.random,
|
|
);
|
|
|
|
if (result.questions?.isNotEmpty != true) {
|
|
return <RobotoffQuestion>[];
|
|
}
|
|
final List<String> barcodes = <String>[];
|
|
for (final RobotoffQuestion question in result.questions!) {
|
|
if (question.barcode != null) {
|
|
barcodes.add(question.barcode!);
|
|
}
|
|
}
|
|
await ProductRefresher().silentFetchAndRefreshList(
|
|
barcodes: barcodes,
|
|
localDatabase: localDatabase,
|
|
productType: ProductType.food,
|
|
);
|
|
return result.questions ?? <RobotoffQuestion>[];
|
|
}
|
|
}
|