Skip to content

Commit

Permalink
feat(wine-festival): add support for the Wine Festival Event
Browse files Browse the repository at this point in the history
  • Loading branch information
vareversat committed Jun 17, 2023
1 parent 8c91535 commit af84840
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 21 deletions.
3 changes: 3 additions & 0 deletions lib/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Const {
'https://www.myshiptracking.com/vessels?side=false&name=$vesselFinderLinkPlaceholder';
static const String githubLink = 'https://github.com/vareversat/chabo';
static const String privacyInfoLink = 'https://chabo.vareversat.fr/privacy';
static const String bordeauxWineFestivalSailingShipLink =
'https://www.bordeaux-fete-le-vin.com/la-fete-sur-les-quais/grands-voiliers.html';

static List<WebLinkIcon> usefulLinks = [
WebLinkIcon(
Expand Down Expand Up @@ -144,4 +146,5 @@ class Const {
/// Misc
static const List<String> vowelList = ['a', 'e', 'i', 'o', 'u', 'y'];
static const String oflLicenseEntryName = 'google_fonts';
static const String specialWineFestivalBoatsEvent = 'Bateaux fete du vin';
}
4 changes: 4 additions & 0 deletions lib/extensions/boats_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,8 @@ extension BoatsExtension on List<Boat> {

return arriving;
}

bool isWineFestival() {
return length == 1 && this[0].isWineFestivalSailBoats;
}
}
6 changes: 6 additions & 0 deletions lib/extensions/color_scheme_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ extension ColorSchemeExtension on ColorScheme {
? const Color(0xFF81C784)
: Colors.green;
}

Color get bordeauxColor {
return brightness == Brightness.light
? const Color.fromRGBO(123, 31, 48, 1)
: const Color.fromRGBO(167, 106, 117, 1);
}
}
17 changes: 14 additions & 3 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@
"dialogInformationContentFromEnd": "to",
"dialogInformationContentFromEnd2": "to",
"dialogInformationContentBridge_closed": "the Chaban bridge will be closed for",
"dialogInformationContentBridgeDeparture": "the departure of the",
"dialogInformationContentBridgeArrival": "the arrival of the",
"dialogInformationContentBridgeDeparture": "the departure of the {count, plural, =1 {the} other {the}}",
"@dialogInformationContentBridgeDeparture": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridgeArrival": "the arrival of {count, plural, =1 {the} other {the}}",
"@dialogInformationContentBridgeArrival": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridge_closed_maintenance": "maintenance",
"dialogInformationContentTime_of_crossing": "estimated time of crossing",
"errorScreenContentError": "Error",
Expand Down Expand Up @@ -209,5 +219,6 @@
"placeholders": {
"count": {}
}
}
},
"wineFestivalSailBoats": "Wine Festival Sailboats"
}
17 changes: 14 additions & 3 deletions lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@
"dialogInformationContentFromEnd": "hasta",
"dialogInformationContentFromEnd2": "a",
"dialogInformationContentBridge_closed": "el puente Chaban estará cerrado por",
"dialogInformationContentBridgeDeparture": "la salida del ",
"dialogInformationContentBridgeArrival": "la llegada del ",
"dialogInformationContentBridgeDeparture": "la salida {count, plural, =1 {del} other {de los}}",
"@dialogInformationContentBridgeDeparture": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridgeArrival": "la llegada {count, plural, =1 {del} other {de los}}",
"@dialogInformationContentBridgeArrival": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridge_closed_maintenance": "mantenimiento",
"dialogInformationContentTime_of_crossing": "hora estimada de cruce",
"errorScreenContentError": "Error",
Expand Down Expand Up @@ -209,5 +219,6 @@
"placeholders": {
"count": {}
}
}
},
"wineFestivalSailBoats": "Veleros de la Fiesta del Vino"
}
17 changes: 14 additions & 3 deletions lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,18 @@
"dialogInformationContentFromEnd": "à",
"dialogInformationContentFromEnd2": "au",
"dialogInformationContentBridge_closed": "le pont Chaban sera fermé pour",
"dialogInformationContentBridgeDeparture": "le départ du",
"dialogInformationContentBridgeArrival": "l'arrivée du",
"dialogInformationContentBridgeDeparture": "le départ {count, plural, =1 {du} other {des}}",
"@dialogInformationContentBridgeDeparture": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridgeArrival": "l'arrivée {count, plural, =1 {du} other {des}}",
"@dialogInformationContentBridgeArrival": {
"placeholders": {
"count": {}
}
},
"dialogInformationContentBridge_closed_maintenance": "maintenance",
"dialogInformationContentTime_of_crossing": "heure de passage estimée",
"errorScreenContentError": "Erreur",
Expand Down Expand Up @@ -209,5 +219,6 @@
"placeholders": {
"count": {}
}
}
},
"wineFestivalSailBoats": "Voiliers de la fête du vin"
}
27 changes: 21 additions & 6 deletions lib/models/boat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,42 @@ import 'package:url_launcher/url_launcher_string.dart';
class Boat extends Equatable {
final String name;
final bool isLeaving;
late final bool isWineFestivalSailBoats;

const Boat({required this.name, required this.isLeaving});
Boat({
required this.name,
required this.isLeaving,
}) {
isWineFestivalSailBoats = name == Const.specialWineFestivalBoatsEvent;
}

void _launchURL(String url) async {
await launchUrlString(url, mode: LaunchMode.externalApplication);
}

TextSpan toLocalizedTextSpan(BuildContext context, bool colored) {
final baseURL = isWineFestivalSailBoats
? Const.bordeauxWineFestivalSailingShipLink
: Const.vesselFinderLink;
final text = isWineFestivalSailBoats
? AppLocalizations.of(context)!.wineFestivalSailBoats
: name;

return TextSpan(
recognizer: TapGestureRecognizer()
..onTap = () => _launchURL(
Const.vesselFinderLink.replaceAll(
baseURL.replaceAll(
Const.vesselFinderLinkPlaceholder,
name,
),
),
text: name,
text: text,
style: TextStyle(
fontWeight: FontWeight.bold,
color: colored
? Theme.of(context).colorScheme.boatColor
? isWineFestivalSailBoats
? Theme.of(context).colorScheme.bordeauxColor
: Theme.of(context).colorScheme.boatColor
: Theme.of(context).dialogBackgroundColor,
decoration: TextDecoration.underline,
),
Expand All @@ -42,7 +57,7 @@ class Boat extends Equatable {
children: [
TextSpan(
text:
'${AppLocalizations.of(context)!.dialogInformationContentBridgeDeparture} ',
'${AppLocalizations.of(context)!.dialogInformationContentBridgeDeparture(isWineFestivalSailBoats ? 2 : 1)} ',
),
toLocalizedTextSpan(context, colored),
],
Expand All @@ -51,7 +66,7 @@ class Boat extends Equatable {
children: [
TextSpan(
text:
'${AppLocalizations.of(context)!.dialogInformationContentBridgeArrival} ',
'${AppLocalizations.of(context)!.dialogInformationContentBridgeArrival(isWineFestivalSailBoats ? 2 : 1)} ',
),
toLocalizedTextSpan(context, colored),
],
Expand Down
14 changes: 12 additions & 2 deletions lib/models/boat_forecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ class BoatForecast extends AbstractForecast {
double size,
bool isLight,
) {
const iconData = Icons.directions_boat_filled_outlined;
var iconData = boats.isWineFestival()
? Icons.wine_bar_outlined
: Icons.directions_boat_filled_outlined;

return isLight
? Icon(iconData, color: getColor(context, reversed), size: size)
Expand All @@ -208,13 +210,21 @@ class BoatForecast extends AbstractForecast {

@override
Color getColor(BuildContext context, bool reversed) {
if (boats.isWineFestival()) {
return reversed
? Theme.of(context).dialogBackgroundColor
: Theme.of(context).colorScheme.bordeauxColor;
}

return reversed
? Theme.of(context).dialogBackgroundColor
: Theme.of(context).colorScheme.boatColor;
}

@override
String getClosingReason(BuildContext context) {
return boats.getNames(context);
return boats.isWineFestival()
? AppLocalizations.of(context)!.wineFestivalSailBoats
: boats.getNames(context);
}
}
28 changes: 24 additions & 4 deletions test/units/boats_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:chabo/const.dart';
import 'package:chabo/extensions/boats_extension.dart';
import 'package:chabo/models/boat.dart';
import 'package:flutter/material.dart';
Expand All @@ -6,15 +7,18 @@ import 'package:flutter_test/flutter_test.dart';
import '../localized_testable_widget.dart';

void main() {
final boats1 = [const Boat(name: 'TEST_BOAT', isLeaving: false)];
final boats2 = [...boats1, const Boat(name: 'TEST_BOAT_2', isLeaving: true)];
final boats1 = [Boat(name: 'TEST_BOAT', isLeaving: false)];
final boats2 = [...boats1, Boat(name: 'TEST_BOAT_2', isLeaving: true)];
final boats3 = [
...boats2,
const Boat(name: 'TEST_BOAT_3', isLeaving: false),
Boat(name: 'TEST_BOAT_3', isLeaving: false),
];
final boats4 = [
...boats3,
const Boat(name: 'TEST_BOAT_4', isLeaving: false),
Boat(name: 'TEST_BOAT_4', isLeaving: false),
];
final boats5 = [
Boat(name: Const.specialWineFestivalBoatsEvent, isLeaving: false),
];

group('toNames', () {
Expand Down Expand Up @@ -223,4 +227,20 @@ void main() {
);
});
});

group('isWineFestival', () {
test('2 Boats', () {
expect(
boats2.isWineFestival(),
false,
);
});

test('1 Boat', () {
expect(
boats5.isWineFestival(),
true,
);
});
});
}

0 comments on commit af84840

Please sign in to comment.