Skip to content

Commit

Permalink
Move the setting to "App settings"
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Nov 18, 2024
1 parent 274bdd2 commit b93b580
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class UserPreferences extends ChangeNotifier {
static const String _TAG_UNIQUE_RANDOM = '_unique_random';
static const String _TAG_LAZY_COUNT_PREFIX = '_lazy_count_prefix';
static const String _TAG_LATEST_PRODUCT_TYPE = '_latest_product_type';
static const String _TAG_SEARCH_SHOW_PRODUCT_TYPE_FILTER =
'_search_show_product_type_filter';
static const String _TAG_PRODUCT_PAGE_ACTIONS = '_product_page_actions';

/// Camera preferences
Expand Down Expand Up @@ -488,6 +490,15 @@ class UserPreferences extends ChangeNotifier {
),
);

Future<void> setSearchProductTypeFilter(final bool visible) async {
await _sharedPreferences.setBool(
_TAG_SEARCH_SHOW_PRODUCT_TYPE_FILTER, visible);
notifyListeners();
}

bool get searchProductTypeFilterVisible =>
_sharedPreferences.getBool(_TAG_SEARCH_SHOW_PRODUCT_TYPE_FILTER) ?? false;

List<ProductFooterActionBar> get productPageActions {
final List<String>? actions =
_sharedPreferences.getStringList(_TAG_PRODUCT_PAGE_ACTIONS);
Expand Down
5 changes: 5 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,11 @@
"description": "Label for expanding nutrition facts table in application setting"
},
"expand_ingredients_body": "Keep the ingredients panel expanded",
"search_product_filter_visibility_title": "Show a filter in the search",
"search_product_filter_visibility_subtitle": "Select search site: Open Food Facts, Open Beauty Facts, Open Pet Food Facts or Open Products Facts",
"@search_product_filter_visibility_subtitle": {
"description": "Label for showing the product type filter in the search bar"
},
"no_internet_connection": "No internet connection",
"@no_internet_connection": {
"description": "Message when there is no internet connection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
static const String userPreferencesTestEnvDomain = '__testEnvHost';
static const String userPreferencesFlagEditIngredients = '__editIngredients';
static const String userPreferencesFlagHideFolksonomy = '__hideFolksonomy';
static const String userPreferencesFlagHideProductTypeFilter =
'__hideProductTypeFilter';
static const String userPreferencesFlagBoostedComparison =
'__boostedComparison';
static const String userPreferencesEnumScanMode = '__scanMode';
Expand Down Expand Up @@ -377,19 +375,6 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
_showSuccessMessage();
},
),
UserPreferencesItemSwitch(
title: 'Hide Product Type Filter',
value: userPreferences
.getFlag(userPreferencesFlagHideProductTypeFilter) ??
true,
onChanged: (bool value) async {
await userPreferences.setFlag(
userPreferencesFlagHideProductTypeFilter,
value,
);
_showSuccessMessage();
},
),
UserPreferencesItemSection(
label: appLocalizations.dev_mode_section_ui,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ class UserPreferencesSettings extends AbstractUserPreferences {
subtitle: appLocalizations.expand_ingredients_body,
panelId: KnowledgePanelCard.PANEL_INGREDIENTS_ID,
),
_getDivider(),
UserPreferencesItemSwitch(
title: appLocalizations.search_product_filter_visibility_title,
subtitle: appLocalizations.search_product_filter_visibility_subtitle,
value: userPreferences.searchProductTypeFilterVisible,
onChanged: (final bool visible) async =>
userPreferences.setSearchProductTypeFilter(visible),
),
if (CameraHelper.hasACamera)
_getTitle(
label: appLocalizations.settings_app_miscellaneous,
Expand Down
17 changes: 5 additions & 12 deletions packages/smooth_app/lib/pages/search/search_product_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/provider_helper.dart';
import 'package:smooth_app/helpers/string_extension.dart';
import 'package:smooth_app/pages/navigator/app_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/pages/product/common/product_dialog_helper.dart';
import 'package:smooth_app/pages/product/common/product_query_page_helper.dart';
import 'package:smooth_app/pages/product/common/search_helper.dart';
Expand All @@ -34,12 +33,9 @@ class SearchProductHelper extends SearchHelper {

@override
Widget? getAdditionalFilter() =>
UserPreferences.getUserPreferencesSync().getFlag(
UserPreferencesDevMode.userPreferencesFlagHideProductTypeFilter,
) ??
true
? null
: _ProductTypeFilter(this);
UserPreferences.getUserPreferencesSync().searchProductTypeFilterVisible
? _ProductTypeFilter(this)
: null;

@override
void search(
Expand Down Expand Up @@ -126,11 +122,8 @@ class SearchProductHelper extends SearchHelper {
localDatabase: localDatabase,
productQuery: KeywordsProductQuery(
value,
productType: UserPreferences.getUserPreferencesSync().getFlag(
UserPreferencesDevMode
.userPreferencesFlagHideProductTypeFilter,
) ??
true
productType: UserPreferences.getUserPreferencesSync()
.searchProductTypeFilterVisible
? ProductType.food
: _productType,
),
Expand Down

0 comments on commit b93b580

Please sign in to comment.