Skip to content

Commit

Permalink
Merge branch 'develop' into contribute-to-your-country-link
Browse files Browse the repository at this point in the history
  • Loading branch information
teolemon authored Aug 16, 2024
2 parents 2ce990f + c8f12b3 commit 52ad2d8
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/on-demand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ jobs:
run: |
git remote set-branches --add origin develop
git fetch origin
- name: Run linting
run: XXXXXXXX
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
#channel: stable
cache: true
flutter-version: ${{ steps.flutter-version.outputs.FLUTTER_VERSION }}
cache-key: flutter-${{ hashFiles('flutter-version.txt')}}-${{ hashFiles('packages\smooth_app\pubspec.lock')}}

- run: flutter --version

# Get dependencies
- name: Get dependencies
run: ci/pub_upgrade.sh

# Check for formatting issues and fix them
- name: Check for formatting issues (run "dart format . ")
run: dart format .
- name: Push changes if needed
uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

## Features

Full list of features on the wiki: https://wiki.openfoodfacts.org/Mobile_App/Features

- a scan that truly matches who you are (Green: the product matches your criteria, Red: there is a problem, Gray: Help us answer you by photographing the products)
- a product page that's knowledgeable, building on the vast amount of food facts we collect collaboratively, and other sources of knowledge, to help you make better food decisions

Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/database/dao_string_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class DaoStringList extends AbstractDao {
/// Key for the list of latest languages used in the app.
static const String keyLanguages = 'languages';

/// Key for the list of favorite stores (for price additions).
static const String keyPriceStores = 'priceStores';

/// Max lengths of each key (null means no limit).
static const Map<String, int?> _maxLengths = <String, int?>{
keySearchProductHistory: 10,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:smooth_app/database/dao_string_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/pages/locations/osm_location.dart';

/// Helper used to set/unset/sort stores as user favorites.
class FavoriteLocationHelper {
static const String _key = DaoStringList.keyPriceStores;

/// Sets a store as a favorite store (or not, depending on [isFavorite]).
Future<void> setFavorite(
final LocalDatabase localDatabase,
final OsmLocation location,
final bool isFavorite,
) async {
final DaoStringList daoStringList = DaoStringList(localDatabase);
final String locationKey = _locationToString(location);
await daoStringList.remove(_key, locationKey);
if (isFavorite) {
await daoStringList.add(_key, locationKey);
}
}

/// Returns true if a store was flagged as favorite.
bool isFavorite(
final LocalDatabase localDatabase,
final OsmLocation location,
) {
final DaoStringList daoStringList = DaoStringList(localDatabase);
final List<String> favorites = daoStringList.getAll(_key);
return _isFavorite(favorites, location);
}

/// Returns true if a store was flagged as favorite, from stored keys.
bool _isFavorite(
final List<String> favorites,
final OsmLocation location,
) {
for (final String favorite in favorites) {
if (favorite == _locationToString(location)) {
return true;
}
}
return false;
}

String _locationToString(final OsmLocation location) =>
'${location.osmType}-${location.osmId}';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:smooth_app/database/dao_osm_location.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/pages/locations/favorite_location_helper.dart';
import 'package:smooth_app/pages/locations/location_map_page.dart';
import 'package:smooth_app/pages/locations/osm_location.dart';
import 'package:smooth_app/pages/product/common/search_preloaded_item.dart';
Expand All @@ -20,10 +21,23 @@ class SearchLocationPreloadedItem extends SearchPreloadedItem {
final BuildContext context, {
final VoidCallback? onDismissItem,
}) {
final LocalDatabase localDatabase = context.read<LocalDatabase>();
final bool isFavorite = FavoriteLocationHelper().isFavorite(
localDatabase,
osmLocation,
);
final String? title = osmLocation.getTitle();
final String? subtitle = osmLocation.getSubtitle();
final Widget child = SmoothCard(
child: ListTile(
leading: IconButton(
icon: Icon(isFavorite ? Icons.favorite : Icons.favorite_border),
onPressed: () async => FavoriteLocationHelper().setFavorite(
localDatabase,
osmLocation,
!isFavorite,
),
),
onTap: () {
if (popFirst) {
// pops this result page
Expand Down

0 comments on commit 52ad2d8

Please sign in to comment.