mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-26 20:00:15 +08:00
feat: 5099 - new dev mode item to refresh all the products from the server (#5100)
Impacted files: * `dao_product.dart`: new method `clearAllLanguages` * `pubspec.lock`: wtf * `user_preferences_dev_mode.dart`: added a "Refresh all products from server (cf. Nutriscore v2)" item
This commit is contained in:
@ -302,4 +302,15 @@ class DaoProduct extends AbstractSqlDao implements BulkDeletable {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Sets the language of all products to null.
|
||||
///
|
||||
/// This is useful to refresh the whole database, as products without language
|
||||
/// are easy to detect. And therefore we can say "refresh all the products
|
||||
/// with a language null or different from the current app language", and use
|
||||
/// the same mechanism as "switch language and refresh products accordingly".
|
||||
Future<int> clearAllLanguages() async => localDatabase.database.update(
|
||||
_TABLE_PRODUCT,
|
||||
<String, Object?>{_TABLE_PRODUCT_COLUMN_LANGUAGE: null},
|
||||
);
|
||||
}
|
||||
|
@ -5,9 +5,11 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:openfoodfacts/openfoodfacts.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:smooth_app/background/background_task_badge.dart';
|
||||
import 'package:smooth_app/background/background_task_language_refresh.dart';
|
||||
import 'package:smooth_app/data_models/continuous_scan_model.dart';
|
||||
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
|
||||
import 'package:smooth_app/data_models/product_list.dart';
|
||||
import 'package:smooth_app/database/dao_product.dart';
|
||||
import 'package:smooth_app/database/dao_product_list.dart';
|
||||
import 'package:smooth_app/database/local_database.dart';
|
||||
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
|
||||
@ -291,6 +293,17 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
|
||||
ProductQuery.setLanguage(context, userPreferences);
|
||||
},
|
||||
),
|
||||
UserPreferencesItemTile(
|
||||
title: 'Refresh all products from server (cf. Nutriscore v2)',
|
||||
trailing: const Icon(Icons.refresh),
|
||||
onTap: () async {
|
||||
final LocalDatabase localDatabase = context.read<LocalDatabase>();
|
||||
final DaoProduct daoProduct = DaoProduct(localDatabase);
|
||||
await daoProduct.clearAllLanguages();
|
||||
await BackgroundTaskLanguageRefresh.addTask(localDatabase);
|
||||
_showSuccessMessage();
|
||||
},
|
||||
),
|
||||
UserPreferencesItemSwitch(
|
||||
title: 'Side by side comparison for 2 or 3 products',
|
||||
value:
|
||||
|
Reference in New Issue
Block a user