Skip to content

Commit

Permalink
feat: 5099 - new dev mode item to refresh all the products from the s…
Browse files Browse the repository at this point in the history
…erver (#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
  • Loading branch information
monsieurtanuki authored Apr 8, 2024
1 parent cd563f5 commit c6077dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/smooth_app/lib/database/dao_product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c6077dc

Please sign in to comment.