Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement langsamfahrstellen (#87) #413

Merged
merged 15 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:das_client/app/i18n/i18n.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/base_row_builder.dart';
import 'package:das_client/app/widgets/assets.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/model/journey/additional_speed_restriction_data.dart';
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class AdditionalSpeedRestrictionRow extends BaseRowBuilder<AdditionalSpeedRestrictionData> {
rawi-coding marked this conversation as resolved.
Show resolved Hide resolved
static const Key additionalSpeedRestrictionIconKey = Key('addition_speed_restrction_icon_key');
static const Color additionalSpeedRestrictionColor = SBBColors.orange;

AdditionalSpeedRestrictionRow({
super.height = 44.0,
required super.metadata,
required super.data,
});

@override
DASTableCell informationCell(BuildContext context) {
return DASTableCell(
color: SBBColors.orange,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${context.l10n.p_train_journey_table_kilometre_label} ${data.restriction.kmFrom.toStringAsFixed(1)}-${data.restriction.kmTo.toStringAsFixed(1)}'),
],
),
);
}

@override
DASTableCell iconsCell3(BuildContext context) {
return DASTableCell(child: const SizedBox.shrink(), color: additionalSpeedRestrictionColor);
}

@override
DASTableCell iconsCell1(BuildContext context) {
return DASTableCell(child: const SizedBox.shrink(), color: additionalSpeedRestrictionColor);
}

@override
DASTableCell iconsCell2(BuildContext context) {
return DASTableCell(
color: additionalSpeedRestrictionColor,
child: SvgPicture.asset(
AppAssets.iconAdditionalSpeedRestriction,
key: additionalSpeedRestrictionIconKey,
),
alignment: Alignment.center);
}

@override
DASTableCell graduatedSpeedCell(BuildContext context) {
return DASTableCell(
color: additionalSpeedRestrictionColor,
child: Text(data.restriction.speed.toString()),
alignment: Alignment.center,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import 'package:das_client/app/pages/journey/train_journey/widgets/table/additional_speed_restriction_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/route_cell_body.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/app/widgets/table/das_table_row.dart';
import 'package:das_client/model/journey/additional_speed_restriction.dart';
import 'package:das_client/model/journey/base_data.dart';
import 'package:das_client/model/journey/metadata.dart';
import 'package:flutter/material.dart';

abstract class BaseRowBuilder extends DASTableRowBuilder {
class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
Grodien marked this conversation as resolved.
Show resolved Hide resolved
const BaseRowBuilder({
super.height,
this.kilometre,
this.defaultAlignment = Alignment.bottomCenter,
this.rowColor,
this.isCurrentPosition = false,
required this.metadata,
required this.data,
});

final List<double>? kilometre;
final Alignment defaultAlignment;
final Color? rowColor;
final bool isCurrentPosition;
final Metadata metadata;
final T data;

@override
DASTableRow build(BuildContext context) {
Expand All @@ -39,7 +43,7 @@ abstract class BaseRowBuilder extends DASTableRowBuilder {
}

DASTableCell kilometreCell(BuildContext context) {
if (kilometre == null || kilometre!.isEmpty) {
if (data.kilometre.isEmpty) {
return DASTableCell.empty();
}

Expand All @@ -48,8 +52,8 @@ abstract class BaseRowBuilder extends DASTableRowBuilder {
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(kilometre![0].toStringAsFixed(1)),
if (kilometre!.length > 1) Text(kilometre![1].toStringAsFixed(1))
Text(data.kilometre[0].toStringAsFixed(1)),
if (data.kilometre.length > 1) Text(data.kilometre[1].toStringAsFixed(1))
],
),
alignment: Alignment.centerLeft);
Expand All @@ -63,7 +67,7 @@ abstract class BaseRowBuilder extends DASTableRowBuilder {
return DASTableCell(
padding: EdgeInsets.all(0.0),
alignment: null,
child: RouteCellBody(isCurrentPosition: isCurrentPosition),
child: RouteCellBody(isCurrentPosition: metadata.currentPosition == data, backgroundColor: getRouteCellColor()),
);
}

Expand All @@ -72,15 +76,15 @@ abstract class BaseRowBuilder extends DASTableRowBuilder {
}

DASTableCell graduatedSpeedCell(BuildContext context) {
return DASTableCell(child: Text('85'), alignment: defaultAlignment);
return DASTableCell.empty();
}

DASTableCell advisedSpeedCell(BuildContext context) {
return DASTableCell(child: Text('100'), alignment: defaultAlignment);
return DASTableCell.empty();
}

DASTableCell brakedWeightSpeedCell(BuildContext context) {
return DASTableCell(child: Text('95'), alignment: defaultAlignment);
return DASTableCell.empty();
}

// TODO: clarify use of different icon cells and set appropriate name
Expand All @@ -101,4 +105,16 @@ abstract class BaseRowBuilder extends DASTableRowBuilder {
DASTableCell actionsCell(BuildContext context) {
return DASTableCell.empty();
}

Color? getRouteCellColor() {
return getAdditionalSpeedRestriction() != null
? AdditionalSpeedRestrictionRow.additionalSpeedRestrictionColor
: null;
}

AdditionalSpeedRestriction? getAdditionalSpeedRestriction() {
return metadata.additionalSpeedRestrictions
.where((it) => it.orderFrom <= data.order && it.orderTo >= data.order)
.firstOrNull;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RouteCellBody extends StatelessWidget {
this.isCurrentPosition = false,
this.isRouteStart = false,
this.isRouteEnd = false,
this.backgroundColor,
rawi-coding marked this conversation as resolved.
Show resolved Hide resolved
});

final double chevronHeight;
Expand All @@ -32,6 +33,8 @@ class RouteCellBody extends StatelessWidget {
final bool isRouteStart;
final bool isRouteEnd;

final Color? backgroundColor;

@override
Widget build(BuildContext context) {
return LayoutBuilder(
Expand All @@ -41,6 +44,7 @@ class RouteCellBody extends StatelessWidget {
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
if (backgroundColor != null) _background(),
_routeLine(context, height),
if (isCurrentPosition) _chevron(context),
if (isStop) _circle(context),
Expand All @@ -50,8 +54,20 @@ class RouteCellBody extends StatelessWidget {
);
}

Widget _background() {
return Positioned(
top: -sbbDefaultSpacing,
bottom: -sbbDefaultSpacing,
right: 0,
left: 0,
child: Container(color: backgroundColor,),
Grodien marked this conversation as resolved.
Show resolved Hide resolved
);
}

Positioned _routeLine(BuildContext context, double height) {
final isDarkTheme = SBBBaseStyle.of(context).brightness == Brightness.dark;
final isDarkTheme = SBBBaseStyle
Grodien marked this conversation as resolved.
Show resolved Hide resolved
.of(context)
.brightness == Brightness.dark;
final lineColor = isDarkTheme ? SBBColors.white : SBBColors.black;
return Positioned(
key: isRouteStart ? routeStartKey : isRouteEnd ? routeEndKey : null,
Expand All @@ -64,7 +80,9 @@ class RouteCellBody extends StatelessWidget {
}

Positioned _circle(BuildContext context) {
final isDarkTheme = SBBBaseStyle.of(context).brightness == Brightness.dark;
final isDarkTheme = SBBBaseStyle
.of(context)
.brightness == Brightness.dark;
final circleColor = isDarkTheme ? SBBColors.sky : SBBColors.black;
return Positioned(
bottom: sbbDefaultSpacing,
Expand All @@ -73,7 +91,9 @@ class RouteCellBody extends StatelessWidget {
}

Positioned _chevron(BuildContext context) {
final isDarkTheme = SBBBaseStyle.of(context).brightness == Brightness.dark;
final isDarkTheme = SBBBaseStyle
.of(context)
.brightness == Brightness.dark;
final chevronColor = isDarkTheme ? SBBColors.sky : SBBColors.black;
return Positioned(
bottom: isStop ? sbbDefaultSpacing + circleSize : sbbDefaultSpacing,
Expand All @@ -98,7 +118,9 @@ class _RouteCircle extends StatelessWidget {

@override
Widget build(BuildContext context) {
final tableThemeData = DASTableTheme.of(context)?.data;
final tableThemeData = DASTableTheme
.of(context)
?.data;
final tableBackgroundColor = tableThemeData?.backgroundColor ?? SBBColors.white;
return Container(
key: isStopOnRequest ? RouteCellBody.stopOnRequestKey : RouteCellBody.stopKey,
Expand All @@ -110,13 +132,14 @@ class _RouteCircle extends StatelessWidget {

BoxDecoration _stopDecoration() => BoxDecoration(color: color, shape: BoxShape.circle);

BoxDecoration _stopOnRequestDecoration({required Color backgroundColor}) => BoxDecoration(
color: backgroundColor,
shape: BoxShape.circle,
border: Border.all(
color: color, // Set the border color
width: 2.0, // Set the border width
));
BoxDecoration _stopOnRequestDecoration({required Color backgroundColor}) =>
BoxDecoration(
color: backgroundColor,
shape: BoxShape.circle,
border: Border.all(
color: color, // Set the border color
width: 2.0, // Set the border width
));
}

class _ChevronPainter extends CustomPainter {
Expand All @@ -133,8 +156,7 @@ class _ChevronPainter extends CustomPainter {

final path = Path()
..moveTo(0, 0)
..lineTo(size.width / 2, size.height)
..lineTo(size.width, 0);
..lineTo(size.width / 2, size.height)..lineTo(size.width, 0);

canvas.drawPath(path, paint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@ import 'package:das_client/app/i18n/i18n.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/base_row_builder.dart';
import 'package:das_client/app/widgets/assets.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/model/journey/metadata.dart';
import 'package:das_client/model/journey/protection_section.dart';
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class ProtectionSectionRow extends BaseRowBuilder {
class ProtectionSectionRow extends BaseRowBuilder<ProtectionSection> {
static const Key protectionSectionKey = Key('protection_section_key');

ProtectionSectionRow({
super.height = 44.0,
required this.metadata,
required this.protectionSection,
}) : super(rowColor: SBBColors.peach, kilometre: protectionSection.kilometre);

final Metadata metadata;
final ProtectionSection protectionSection;
required super.metadata,
required super.data,
}) : super(rowColor: SBBColors.peach);

@override
DASTableCell informationCell(BuildContext context) {
return DASTableCell(
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${context.l10n.p_train_journey_table_kilometre_label} ${protectionSection.kilometre[0].toStringAsFixed(1)}'),
Text('${context.l10n.p_train_journey_table_kilometre_label} ${data.kilometre[0].toStringAsFixed(1)}'),
Spacer(),
Text('${protectionSection.isOptional ? 'F' : ''}${protectionSection.isLong ? 'L' : ''}'),
Text('${data.isOptional ? 'F' : ''}${data.isLong ? 'L' : ''}'),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,29 @@ import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/b
import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/route_cell_body.dart';
import 'package:das_client/app/widgets/assets.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/model/journey/metadata.dart';
import 'package:das_client/model/journey/service_point.dart';
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

// TODO: Extract real values from SFERA objects.
class ServicePointRow extends BaseRowBuilder {
class ServicePointRow extends BaseRowBuilder<ServicePoint> {
static const Key stopOnRequestKey = Key('stop_on_request_key');

ServicePointRow({
super.height = 64.0,
this.isRouteStart = false,
this.isRouteEnd = false,
required this.metadata,
required this.servicePoint,
}) : super(
rowColor: metadata.nextStop == servicePoint ? SBBColors.royal.withOpacity(0.2) : Colors.transparent,
kilometre: servicePoint.kilometre,
isCurrentPosition: metadata.currentPosition == servicePoint);

final Metadata metadata;
final ServicePoint servicePoint;

required super.metadata,
required super.data,
}) : super(rowColor: metadata.nextStop == data ? SBBColors.royal.withOpacity(0.2) : Colors.transparent);

final bool isRouteStart;
final bool isRouteEnd;

@override
DASTableCell informationCell(BuildContext context) {
final servicePointName = servicePoint.name.localized;
final textStyle = servicePoint.isStation
final servicePointName = data.name.localized;
final textStyle = data.isStation
? SBBTextStyles.largeBold.copyWith(fontSize: 24.0)
: SBBTextStyles.largeLight.copyWith(fontSize: 24.0, fontStyle: FontStyle.italic);
return DASTableCell(
Expand All @@ -57,12 +48,12 @@ class ServicePointRow extends BaseRowBuilder {
child: Stack(
clipBehavior: Clip.none,
children: [
if (servicePoint.bracketStation != null)
if (data.bracketStation != null)
BracketStationBody(
bracketStation: servicePoint.bracketStation!,
bracketStation: data.bracketStation!,
height: height!,
),
if (!servicePoint.mandatoryStop)
if (!data.mandatoryStop)
Align(
alignment: Alignment.bottomCenter,
child: SvgPicture.asset(
Expand All @@ -80,11 +71,12 @@ class ServicePointRow extends BaseRowBuilder {
padding: EdgeInsets.all(0.0),
alignment: null,
child: RouteCellBody(
isStop: servicePoint.isStop,
isCurrentPosition: isCurrentPosition,
isStop: data.isStop,
isCurrentPosition: metadata.currentPosition == data,
isRouteStart: isRouteStart,
isRouteEnd: isRouteEnd,
isStopOnRequest: !servicePoint.mandatoryStop,
isStopOnRequest: !data.mandatoryStop,
backgroundColor: getRouteCellColor(),
),
);
}
Expand Down
Loading
Loading