Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
saiprasad-patil authored Aug 6, 2023
2 parents 6630c07 + aa6632d commit 80313f4
Show file tree
Hide file tree
Showing 61 changed files with 1,047 additions and 646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ProductTitleCard extends StatelessWidget {
onRemove: onRemove,
);

if (!(isRemovable && !isSelectable)) {
if (!dense && !(isRemovable && !isSelectable)) {
title = Expanded(child: title);
}

Expand All @@ -46,6 +46,7 @@ class ProductTitleCard extends StatelessWidget {
Expanded(
child: _ProductTitleCardName(
selectable: isSelectable,
dense: dense,
),
),
title,
Expand All @@ -65,8 +66,10 @@ class ProductTitleCard extends StatelessWidget {
class _ProductTitleCardName extends StatelessWidget {
const _ProductTitleCardName({
required this.selectable,
this.dense = false,
});

final bool dense;
final bool selectable;

@override
Expand All @@ -78,7 +81,7 @@ class _ProductTitleCardName extends StatelessWidget {
getProductName(product, appLocalizations),
style: Theme.of(context).textTheme.headlineMedium,
textAlign: TextAlign.start,
maxLines: 3,
maxLines: dense ? 2 : 3,
overflow: TextOverflow.ellipsis,
).selectable(isSelectable: selectable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/data_models/product_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/svg_icon_chip.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
part of '../user_preferences.dart';

/// When we add/remove entries in the [UserPreferences] class, we need to
/// add a new level and ensure we do a proper migration
class UserPreferencesMigrationTool {
const UserPreferencesMigrationTool._();

static final Iterable<UserPreferencesMigration> _versions =
<UserPreferencesMigration>[
const _UserPreferencesMigrationV1(),
const _UserPreferencesMigrationV2(),
const _UserPreferencesMigrationV3(),
];

static Future<void> onUpgrade(
UserPreferences preferences,
int? oldVersion,
int newVersion,
) async {
if (oldVersion == newVersion) {
return;
}

for (final UserPreferencesMigration migration in _versions) {
if ((oldVersion ?? 0) >= migration.version) {
continue;
}

await migration.onUpgrade(preferences, oldVersion, newVersion);
}
}
}

abstract interface class UserPreferencesMigration {
const UserPreferencesMigration();

Future<void> onUpgrade(
UserPreferences preferences,
int? oldVersion,
int newVersion,
);

int get version;
}

class _UserPreferencesMigrationV1 extends UserPreferencesMigration {
const _UserPreferencesMigrationV1();

@override
Future<void> onUpgrade(
UserPreferences preferences,
int? oldVersion,
int newVersion,
) async {
final bool? crashReporting = preferences._sharedPreferences
.getBool(UserPreferences._TAG_CRASH_REPORTS);
if (crashReporting != null) {
await preferences.setUserTracking(crashReporting);
}
}

@override
int get version => 1;
}

class _UserPreferencesMigrationV2 extends UserPreferencesMigration {
const _UserPreferencesMigrationV2();

@override
Future<void> onUpgrade(
UserPreferences preferences,
int? oldVersion,
int newVersion,
) async {
/// With version == null and 1, [_TAG_USER_GROUP] is missing
if (preferences._sharedPreferences
.getInt(UserPreferences._TAG_USER_GROUP) ==
null) {
await preferences._sharedPreferences.setInt(
UserPreferences._TAG_USER_GROUP,
Random().nextInt(10),
);
}
}

@override
int get version => 2;
}

class _UserPreferencesMigrationV3 extends UserPreferencesMigration {
const _UserPreferencesMigrationV3();

@override
Future<void> onUpgrade(
UserPreferences preferences,
int? oldVersion,
int newVersion,
) async {
if (preferences._sharedPreferences.getBool('_TAG_IS_FIRST_SCAN') ?? false) {
await preferences.incrementScanCount();
}
}

@override
int get version => 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
import 'package:smooth_app/themes/color_schemes.dart';

part 'package:smooth_app/data_models/preferences/migration/user_preferences_migration.dart';

/// User choice regarding the picture source.
enum UserPictureSource {
/// Always select between Gallery and Camera
Expand Down Expand Up @@ -57,9 +59,9 @@ class UserPreferences extends ChangeNotifier {
/// Whether the preferences are empty or not
static const String _TAG_INIT = 'init';

/// The current version of preferences (1)
/// The current version of preferences
static const String _TAG_VERSION = 'prefs_version';
static const int _PREFS_CURRENT_VERSION = 2;
static const int _PREFS_CURRENT_VERSION = 3;
static const String _TAG_PREFIX_IMPORTANCE = 'IMPORTANCE_AS_STRING';
static const String _TAG_CURRENT_THEME_MODE = 'currentThemeMode';
static const String _TAG_CURRENT_COLOR_SCHEME = 'currentColorScheme';
Expand All @@ -75,9 +77,6 @@ class UserPreferences extends ChangeNotifier {
static const String _TAG_USER_GROUP = '_user_group';

/// Camera preferences
// Detect if a first successful scan was achieved (condition to show the
// tagline)
static const String _TAG_IS_FIRST_SCAN = 'is_first_scan';
// Use the flash/torch with the camera
static const String _TAG_USE_FLASH_WITH_CAMERA = 'enable_flash_with_camera';
Expand All @@ -98,6 +97,8 @@ class UserPreferences extends ChangeNotifier {
static const String _TAG_IN_APP_REVIEW_ALREADY_DISPLAYED =
'inAppReviewAlreadyAsked';

static const String _TAG_NUMBER_OF_SCANS = 'numberOfScans';

Future<void> init(final ProductPreferences productPreferences) async {
await _onMigrate();

Expand All @@ -110,27 +111,11 @@ class UserPreferences extends ChangeNotifier {

/// Allow to migrate between versions
Future<void> _onMigrate() async {
final int? currentVersion = _sharedPreferences.getInt(_TAG_VERSION);
if (currentVersion == _PREFS_CURRENT_VERSION) {
return;
}

/// With version == null (or 0), [_TAG_USER_TRACKING] didn't exist
if (currentVersion == null) {
final bool? crashReporting =
_sharedPreferences.getBool(_TAG_CRASH_REPORTS);
if (crashReporting != null) {
await setUserTracking(crashReporting);
}
}

/// With version == null and 1, [_TAG_USER_GROUP] is missing
if (_sharedPreferences.getInt(_TAG_USER_GROUP) == null) {
await _sharedPreferences.setInt(
_TAG_USER_GROUP,
Random().nextInt(10),
);
}
await UserPreferencesMigrationTool.onUpgrade(
this,
_sharedPreferences.getInt(_TAG_VERSION),
_PREFS_CURRENT_VERSION,
);

await _sharedPreferences.setInt(
_TAG_VERSION,
Expand Down Expand Up @@ -232,15 +217,12 @@ class UserPreferences extends ChangeNotifier {
: OnboardingPage.values[pageIndex];
}

Future<void> setFirstScanAchieved() async {
if (isFirstScan) {
await _sharedPreferences.setBool(_TAG_IS_FIRST_SCAN, false);
notifyListeners();
}
Future<void> incrementScanCount() async {
await _sharedPreferences.setInt(_TAG_NUMBER_OF_SCANS, numberOfScans + 1);
notifyListeners();
}

bool get isFirstScan =>
_sharedPreferences.getBool(_TAG_IS_FIRST_SCAN) ?? true;
int get numberOfScans => _sharedPreferences.getInt(_TAG_NUMBER_OF_SCANS) ?? 0;

Future<void> markInAppReviewAsShown() async {
await _sharedPreferences.setBool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SmoothLargeButtonWithIcon extends StatelessWidget {
this.backgroundColor,
this.foregroundColor,
this.textAlign,
this.textStyle,
});

final String text;
Expand All @@ -22,6 +23,7 @@ class SmoothLargeButtonWithIcon extends StatelessWidget {
final Color? backgroundColor;
final Color? foregroundColor;
final TextAlign? textAlign;
final TextStyle? textStyle;

Color _getBackgroundColor(final ThemeData themeData) =>
backgroundColor ?? themeData.colorScheme.secondary;
Expand All @@ -32,6 +34,12 @@ class SmoothLargeButtonWithIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
TextStyle style = textStyle ?? themeData.textTheme.bodyMedium!;

if (style.color == null) {
style = style.copyWith(color: _getForegroundColor(themeData));
}

return SmoothSimpleButton(
minWidth: double.infinity,
padding: padding ?? const EdgeInsets.all(10),
Expand All @@ -51,9 +59,7 @@ class SmoothLargeButtonWithIcon extends StatelessWidget {
text,
maxLines: 2,
textAlign: textAlign,
style: themeData.textTheme.bodyMedium!.copyWith(
color: _getForegroundColor(themeData),
),
style: style,
),
),
const Spacer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/themes/theme_provider.dart';

class SmoothSimpleButton extends StatelessWidget {
const SmoothSimpleButton({
Expand Down Expand Up @@ -35,6 +37,18 @@ class SmoothSimpleButton extends StatelessWidget {
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(borderRadius: borderRadius),
),
overlayColor: context.read<ThemeProvider>().isAmoledTheme
? MaterialStateProperty.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.pressed)
? Theme.of(context).colorScheme.primary.withOpacity(0.3)
: null;
})
: null,
side: context.read<ThemeProvider>().isAmoledTheme
? MaterialStateProperty.all<BorderSide>(
const BorderSide(color: Colors.white),
)
: null,
),
onPressed: onPressed,
child: Padding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ class SmoothAlertDialog extends StatelessWidget {
}

Padding _buildBottomBar(EdgeInsetsDirectional padding) {
final bool singleButton =
positiveAction != null && negativeAction == null ||
negativeAction != null && positiveAction == null;

return Padding(
padding: EdgeInsetsDirectional.only(
top: padding.bottom,
start: actionsAxis == Axis.horizontal ? SMALL_SPACE : 0.0,
start: (actionsAxis == Axis.horizontal || singleButton)
? SMALL_SPACE
: 0.0,
end: positiveAction != null && negativeAction != null
? 0.0
: SMALL_SPACE,
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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/user_preferences.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/helpers/global_vars.dart';

/// Category for Matomo Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/services.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';

/// Haptic feedback/vibrations in the app
/// Managed by a preference in the user's preferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_expanded_card.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_page.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/cards/category_cards/abstract_cache.dart';
import 'package:smooth_app/cards/category_cards/svg_cache.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/helpers/extension_on_text_helper.dart';
import 'package:smooth_app/helpers/ui_helpers.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_element_card.dart';
import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart';
Expand Down
Loading

0 comments on commit 80313f4

Please sign in to comment.