Skip to content

Commit

Permalink
feat: basic fahrbild header with static data and ADL notification. (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawi-coding authored Nov 4, 2024
1 parent 785f1b9 commit f076f44
Show file tree
Hide file tree
Showing 27 changed files with 490 additions and 175 deletions.
4 changes: 0 additions & 4 deletions das_client/.fvm/fvm_config.json

This file was deleted.

4 changes: 4 additions & 0 deletions das_client/.fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"flutter": "3.24.3",
"flavors": {}
}
6 changes: 6 additions & 0 deletions das_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ The prefix is mandatory and indicates the scope of the term. Valid prefixes are:

The context is optional and indicate where a localization is used. When a localization is scoped to a page or widget, the context MUST be equal to the name of that page or widget. For example, localizations used on the login page would start with `p_login_`.

To generate the localization code, run the following command:

```shell
fvm flutter gen-l10n
```

## Code style

This application uses the code style defined in the [Flutter Wiki][2]. The
Expand Down
4 changes: 2 additions & 2 deletions das_client/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

import 'di.dart';
import 'test/fahrbild_test.dart' as fahrbild_tests;
import 'test/train_journey_test.dart' as train_journey_tests;
import 'test/navigation_test.dart' as navigation_tests;

AppLocalizations l10n = AppLocalizationsDe();
Expand All @@ -16,7 +16,7 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Fimber.plantTree(DebugTree());

fahrbild_tests.main();
train_journey_tests.main();
navigation_tests.main();
}

Expand Down
8 changes: 4 additions & 4 deletions das_client/integration_test/test/navigation_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:das_client/pages/fahrt/fahrt_page.dart';
import 'package:das_client/pages/journey/journey_page.dart';
import 'package:das_client/pages/links/links_page.dart';
import 'package:das_client/pages/profile/profile_page.dart';
import 'package:das_client/pages/settings/settings_page.dart';
Expand Down Expand Up @@ -93,7 +93,7 @@ void main() {
expect(find.byType(ProfilePage), findsOneWidget);
});

testWidgets('test navigate to fahrbild', (tester) async {
testWidgets('test navigate to train journey', (tester) async {
// Load app widget.
await prepareAndStartApp(tester);

Expand All @@ -119,7 +119,7 @@ void main() {
await tapElement(tester, find.text(l10n.w_navigation_drawer_fahrtinfo_title));

// Check on FahrtPage
expect(find.byType(FahrtPage), findsOneWidget);
expect(find.byType(JourneyPage), findsOneWidget);
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../app_test.dart';

void main() {
group('home screen test', () {
testWidgets('load fahrbild company=1085, train=7839', (tester) async {
testWidgets('load train journey company=1085, train=7839', (tester) async {
// Load app widget.
await prepareAndStartApp(tester);

Expand All @@ -24,7 +24,7 @@ void main() {
// press load Fahrordnung button
await tester.tap(primaryButton);

// wait for fahrbild to load
// wait for train journey to load
await tester.pumpAndSettle(const Duration(seconds: 1));

// check if station is present
Expand Down
5 changes: 4 additions & 1 deletion das_client/l10n/strings_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"p_train_selection_trainnumber_placeholder": "z.B. 711",
"p_train_selection_company_description": "Company code",
"p_train_selection_company_placeholder": "z.B. 0085",
"p_train_journey_header_button_dark_theme": "Nachtmodus",
"p_train_journey_header_button_pause": "Pause",
"w_navigation_drawer_fahrtinfo_title": "Fahrtinfo",
"w_navigation_drawer_links_title": "Links",
"w_navigation_drawer_settings_title": "Einstellungen",
"w_navigation_drawer_profile_title": "Profil",
"p_login_connect_to_tms": "Mit TMS verbinden",
"p_login_login_button_text": "Login",
"p_login_login_button_description": "Mit Ihrem Account einloggen",
"p_login_login_failed": "Login fehlgeschlagen"
"p_login_login_failed": "Login fehlgeschlagen",
"w_adl_notification_title": "ADL Meldung"
}
9 changes: 5 additions & 4 deletions das_client/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class App extends StatelessWidget {
return MaterialApp.router(
themeMode: ThemeMode.system,
theme: SBBTheme.light(
baseStyle: SBBBaseStyle(
primaryColor: SBBColors.royal,
primaryColorDark: SBBColors.royal125,
)),
baseStyle: SBBBaseStyle(
primaryColor: SBBColors.royal,
primaryColorDark: SBBColors.royal125,
),
),
//darkTheme: SBBTheme.dark(),
localizationsDelegates: localizationDelegates,
supportedLocales: supportedLocales,
Expand Down
35 changes: 0 additions & 35 deletions das_client/lib/bloc/fahrbild_state.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import 'package:fimber/fimber.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

part 'fahrbild_state.dart';
part 'train_journey_state.dart';

class FahrbildCubit extends Cubit<FahrbildState> {
FahrbildCubit({
class TrainJourneyCubit extends Cubit<TrainJourneyState> {
TrainJourneyCubit({
required SferaService sferaService,
}) : _sferaService = sferaService,
super(SelectingFahrbildState());
super(SelectingTrainJourneyState());

final SferaService _sferaService;

Expand All @@ -26,9 +26,9 @@ class FahrbildCubit extends Cubit<FahrbildState> {

StreamSubscription? _stateSubscription;

void loadFahrbild() async {
void loadTrainJourney() async {
final currentState = state;
if (currentState is SelectingFahrbildState) {
if (currentState is SelectingTrainJourneyState) {
final now = DateTime.now();
final company = currentState.company;
final trainNumber = currentState.trainNumber;
Expand All @@ -42,7 +42,7 @@ class FahrbildCubit extends Cubit<FahrbildState> {
_stateSubscription = _sferaService.stateStream.listen((state) {
switch (state) {
case SferaServiceState.connected:
emit(FahrbildLoadedState(company, trainNumber, now));
emit(TrainJourneyLoadedState(company, trainNumber, now));
break;
case SferaServiceState.connecting:
case SferaServiceState.handshaking:
Expand All @@ -52,7 +52,7 @@ class FahrbildCubit extends Cubit<FahrbildState> {
break;
case SferaServiceState.disconnected:
case SferaServiceState.offline:
emit(SelectingFahrbildState(
emit(SelectingTrainJourneyState(
company: company, trainNumber: trainNumber, errorCode: _sferaService.lastErrorCode));
break;
}
Expand All @@ -62,32 +62,32 @@ class FahrbildCubit extends Cubit<FahrbildState> {
}

void updateTrainNumber(String? trainNumber) {
if (state is SelectingFahrbildState) {
emit(SelectingFahrbildState(
if (state is SelectingTrainJourneyState) {
emit(SelectingTrainJourneyState(
trainNumber: trainNumber,
company: (state as SelectingFahrbildState).company,
errorCode: (state as SelectingFahrbildState).errorCode));
company: (state as SelectingTrainJourneyState).company,
errorCode: (state as SelectingTrainJourneyState).errorCode));
}
}

void updateCompany(String? company) {
if (state is SelectingFahrbildState) {
emit(SelectingFahrbildState(
trainNumber: (state as SelectingFahrbildState).trainNumber,
if (state is SelectingTrainJourneyState) {
emit(SelectingTrainJourneyState(
trainNumber: (state as SelectingTrainJourneyState).trainNumber,
company: company,
errorCode: (state as SelectingFahrbildState).errorCode));
errorCode: (state as SelectingTrainJourneyState).errorCode));
}
}

void reset() {
if (state is BaseFahrbildState) {
Fimber.i('Reseting fahrbild cubit in state $state');
emit(SelectingFahrbildState(
trainNumber: (state as BaseFahrbildState).trainNumber, company: (state as BaseFahrbildState).company));
if (state is BaseTrainJourneyState) {
Fimber.i('Reseting TrainJourney cubit in state $state');
emit(SelectingTrainJourneyState(
trainNumber: (state as BaseTrainJourneyState).trainNumber, company: (state as BaseTrainJourneyState).company));
}
}
}

extension ContextBlocExtension on BuildContext {
FahrbildCubit get fahrbildCubit => read<FahrbildCubit>();
TrainJourneyCubit get trainJourneyCubit => read<TrainJourneyCubit>();
}
35 changes: 35 additions & 0 deletions das_client/lib/bloc/train_journey_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
part of 'train_journey_cubit.dart';

@immutable
sealed class TrainJourneyState {}

final class SelectingTrainJourneyState extends TrainJourneyState {
SelectingTrainJourneyState({this.company, this.trainNumber, this.errorCode});

final String? trainNumber;
final String? company;
final ErrorCode? errorCode;
}

abstract class BaseTrainJourneyState extends TrainJourneyState {
BaseTrainJourneyState(this.company, this.trainNumber, this.date);

final String company;
final String trainNumber;
final DateTime date;

@override
String toString() {
return '${runtimeType.toString()}(company=$company, trainNumber=$trainNumber, date=$date)';
}
}

final class ConnectingState extends BaseTrainJourneyState {
ConnectingState(super.company, super.trainNumber, super.date);
}

final class TrainJourneyLoadedState extends BaseTrainJourneyState {
TrainJourneyLoadedState(super.company, super.trainNumber, super.date);
}


19 changes: 13 additions & 6 deletions das_client/lib/nav/app_router.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import 'package:auto_route/auto_route.dart';
import 'package:das_client/pages/fahrt/fahrt_page.dart';
import 'package:das_client/pages/links/links_page.dart';
import 'package:das_client/pages/profile/profile_page.dart';
import 'package:das_client/pages/login/login_page.dart';
import 'package:das_client/pages/login/splash_page.dart';
import 'package:das_client/pages/settings/settings_page.dart';
import 'package:das_client/pages/journey/journey_page.dart';

part 'app_router.gr.dart';

@AutoRouterConfig(replaceInRouteName: 'Page,Route')
class AppRouter extends RootStackRouter {
@override
List<AutoRoute> get routes => [_splash, _login, _fahrt, _links, _settings, _profile];
List<AutoRoute> get routes => [
_splash,
_login,
_journey,
_links,
_settings,
_profile,
];

@override
get defaultRouteType => const RouteType.custom();
Expand All @@ -30,9 +37,9 @@ final _login = AutoRoute(
page: LoginRoute.page,
);

final _fahrt = AutoRoute(
path: '/fahrt',
page: FahrtRoute.page,
final _journey = AutoRoute(
path: '/journey',
page: JourneyRoute.page,
);

final _links = AutoRoute(
Expand All @@ -48,4 +55,4 @@ final _settings = AutoRoute(
final _profile = AutoRoute(
path: '/profile',
page: ProfileRoute.page,
);
);
2 changes: 1 addition & 1 deletion das_client/lib/nav/das_navigation_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DASNavigationDrawer extends StatelessWidget {
context,
icon: SBBIcons.route_circle_start_small,
title: context.l10n.w_navigation_drawer_fahrtinfo_title,
route: const FahrtRoute(),
route: const JourneyRoute(),
),
_navigationTile(
context,
Expand Down
56 changes: 0 additions & 56 deletions das_client/lib/pages/fahrt/widgets/fahrbild.dart

This file was deleted.

Loading

0 comments on commit f076f44

Please sign in to comment.