Skip to content

Commit

Permalink
feat: Change UI of new product type cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Valimp committed Nov 14, 2024
1 parent 3665f05 commit 68bf65d
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 113 deletions.
14 changes: 14 additions & 0 deletions packages/smooth_app/assets/misc/logo_obf_half.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/smooth_app/assets/misc/logo_off_half.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions packages/smooth_app/assets/misc/logo_opf_half.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions packages/smooth_app/assets/misc/logo_opff_half.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 25 additions & 53 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/helpers/global_vars.dart';
import 'package:smooth_app/query/product_query.dart';

/// Category for Matomo Events
enum AnalyticsCategory {
Expand Down Expand Up @@ -277,12 +275,9 @@ class AnalyticsHelper {
return event;
}

static late PackageInfo _packageInfo;

static Future<void> initMatomo(
final bool screenshotMode,
) async {
_packageInfo = await PackageInfo.fromPlatform();
if (screenshotMode) {
_setCrashReports(false);
_setAnalyticsReports(false);
Expand Down Expand Up @@ -328,11 +323,13 @@ class AnalyticsHelper {
int? eventValue,
String? barcode,
}) =>
trackCustomEvent(
msg.name,
msg.category.tag,
eventValue: eventValue,
barcode: barcode,
MatomoTracker.instance.trackEvent(
eventInfo: EventInfo(
name: msg.name,
category: msg.category.tag,
action: msg.name,
value: eventValue ?? _formatBarcode(barcode),
),
);

// Used by code which is outside of the core:smooth_app code
Expand All @@ -342,51 +339,26 @@ class AnalyticsHelper {
String category, {
int? eventValue,
String? barcode,
String? action,
ProductType? productType,
}) {
final Map<String, String> dimensions = <String, String>{
'dimension1': ProductQuery.getLanguage().offTag,
'dimension2': ProductQuery.getCountry().offTag,
'dimension3': ProductQuery.isLoggedIn() ? 'Y' : 'N',
'dimension4': _packageInfo.version,
'dimension5': productType?.offTag ?? '',
};
MatomoTracker.instance.trackEvent(
eventInfo: EventInfo(
name: msg,
category: category,
action: action ?? msg,
value: eventValue ?? _formatBarcode(barcode),
),
dimensions: dimensions,
);
}

static void trackProductEdit(
AnalyticsEditEvents editEventName,
Product product, [
bool saved = false,
]) =>
trackCustomEvent(
saved ? '${editEventName.name}-saved' : editEventName.name,
AnalyticsCategory.productEdit.tag,
action: editEventName.name,
barcode: product.barcode,
productType: product.productType ?? ProductType.food,
}) =>
MatomoTracker.instance.trackEvent(
eventInfo: EventInfo(
name: msg,
category: category,
action: msg,
value: eventValue ?? _formatBarcode(barcode),
),
);

static void trackProductEvent(
AnalyticsEvent msg, {
int? eventValue,
required Product product,
}) =>
trackCustomEvent(
msg.name,
msg.category.tag,
eventValue: eventValue,
barcode: product.barcode,
productType: product.productType ?? ProductType.food,
static void trackProductEdit(
AnalyticsEditEvents editEventName, String barcode,
[bool saved = false]) =>
MatomoTracker.instance.trackEvent(
eventInfo: EventInfo(
name: saved ? '${editEventName.name}-saved' : editEventName.name,
category: AnalyticsCategory.productEdit.tag,
action: editEventName.name,
value: _formatBarcode(barcode),
),
);

static void trackSearch({
Expand Down
25 changes: 7 additions & 18 deletions packages/smooth_app/lib/helpers/product_cards_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,10 @@ List<ProductImage> getRawProductImages(
final Product product,
final ImageSize imageSize,
) {
final List<ProductImage> result = <ProductImage>[];
final List<ProductImage>? rawImages = product.getRawImages();
if (rawImages == null) {
return <ProductImage>[];
return result;
}
final Map<int, ProductImage> map = <int, ProductImage>{};
for (final ProductImage productImage in rawImages) {
Expand All @@ -438,22 +439,10 @@ List<ProductImage> getRawProductImages(
}
map[imageId] = productImage;
}
final List<ProductImage> result = List<ProductImage>.of(map.values);
result.sort(
(
final ProductImage a,
final ProductImage b,
) {
final int result = (a.uploaded?.millisecondsSinceEpoch ?? 0).compareTo(
b.uploaded?.millisecondsSinceEpoch ?? 0,
);
if (result != 0) {
return result;
}
return (int.tryParse(a.imgid ?? '0') ?? 0).compareTo(
int.tryParse(b.imgid ?? '0') ?? 0,
);
},
);
final List<int> sortedIds = List<int>.of(map.keys);
sortedIds.sort();
for (final int id in sortedIds) {
result.add(map[id]!);
}
return result;
}
16 changes: 16 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -3195,5 +3195,21 @@
"product_page_action_bar_item_disable": "Disable action",
"@product_page_action_bar_item_disable": {
"description": "Accessibility label to disable action (= make it invisible)"
},
"product_type_subtitle_food": "Vegetebles, fruits, frozen food...",
"@product_type_subtitle_food" : {
"description": "Exemple of products for food category"
},
"product_type_subtitle_beauty": "Makeup, soap, toothpaste...",
"@product_type_subtitle_beauty" : {
"description": "Exemple of products for beauty category"
},
"product_type_subtitle_pet_food": "Food for dogs, cats...",
"@product_type_subtitle_pet_food" : {
"description": "Exemple of products for pet food category"
},
"product_type_subtitle_product": "Smartphone, furniture...",
"@product_type_subtitle_product" : {
"description": "Exemple of products for other categories"
}
}
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/navigator/app_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:smooth_app/pages/navigator/error_page.dart';
import 'package:smooth_app/pages/navigator/external_page.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_page.dart';
import 'package:smooth_app/pages/product/add_new_product_page.dart';
import 'package:smooth_app/pages/product/add_new_product/add_new_product_page.dart';
import 'package:smooth_app/pages/product/edit_product_page.dart';
import 'package:smooth_app/pages/product/product_loader_page.dart';
import 'package:smooth_app/pages/product/product_page/new_product_page.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {

AnalyticsHelper.trackProductEdit(
AnalyticsEditEvents.basicDetails,
_product,
_product.barcode!,
true,
);
await BackgroundTaskDetails.addTask(
Expand Down
Loading

0 comments on commit 68bf65d

Please sign in to comment.