Skip to content

Commit

Permalink
Remove "Lesson start" and "Lesson length" from the timetable settings…
Browse files Browse the repository at this point in the history
… page, as they can be found in "Lesson times". (#1767)

      | Before | After |
|--------|--------|
| ![timetable_settings_page_light
iphone11](https://github.com/user-attachments/assets/420425d7-d864-48e3-b341-0d3139b8a0dd)
| ![timetable_settings_page_light
iphone11](https://github.com/user-attachments/assets/1417e36c-0990-40b4-a01a-97debfe9b5ec)
|

Should be a cleaner page now. Closes #1297
  • Loading branch information
nilsreichardt authored Oct 15, 2024
1 parent 91d0708 commit c6b77ad
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import 'package:sharezone/settings/src/subpages/timetable/periods/periods_edit_p
import 'package:sharezone/settings/src/subpages/timetable/weekdays/weekdays_edit_page.dart';
import 'package:sharezone/sharezone_plus/page/sharezone_plus_page.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart';
import 'package:sharezone/timetable/src/edit_time.dart';
import 'package:sharezone/timetable/src/edit_weektype.dart';
import 'package:sharezone/timetable/src/models/lesson_length/lesson_length.dart';
import 'package:sharezone_widgets/sharezone_widgets.dart';
import 'package:time/time.dart';
import 'package:user/user.dart';

class TimetableSettingsPage extends StatelessWidget {
Expand All @@ -48,20 +46,14 @@ class TimetableSettingsPage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
LessonsLengthField(
streamLessonLength: bloc.lessonLengthStream,
onChanged: (lessonLength) =>
bloc.saveLessonLengthInCache(lessonLength.minutes),
),
_TimetablePeriodsField(),
const Divider(),
_ABWeekField(),
const Divider(),
_TimetablePreferencesField(),
_AbbreviationInTimetable(),
const Divider(),
_TimetableEnabledWeekDaysField(),
const Divider(),
_TimetablePeriodsField(),
const Divider(),
const _ICalLinks(),
// We only show the time picker settings on iOS because on
// other platforms we use the different time picker where we
Expand Down Expand Up @@ -153,11 +145,34 @@ class _ABWeekField extends StatelessWidget {
}
}

class _AbbreviationInTimetable extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<UserSettingsBloc>(context);
return StreamBuilder<UserSettings>(
stream: bloc.streamUserSettings(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();
final userSettings = snapshot.data!;
return SwitchListTile.adaptive(
title: const Text("Kürzel im Stundenplan anzeigen"),
value: userSettings.showAbbreviation,
onChanged: (newValue) {
bloc.updateSettings(
userSettings.copyWith(showAbbreviation: newValue));
},
);
},
);
}
}

class _TimetablePeriodsField extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
title: const Text("Stundenzeiten"),
subtitle: const Text("Stundenplanbeginn, Stundenlänge, etc."),
onTap: () => openPeriodsEditPage(context),
);
}
Expand Down Expand Up @@ -204,45 +219,6 @@ class _TimetableEnabledWeekDaysField extends StatelessWidget {
}
}

class _TimetablePreferencesField extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<UserSettingsBloc>(context);
return StreamBuilder<UserSettings>(
stream: bloc.streamUserSettings(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Container();
final userSettings = snapshot.data;
final tbStart = userSettings!.timetableStartTime;
return Column(
children: <Widget>[
ListTile(
title: const Text("Stundenplanbeginn"),
subtitle: Text(tbStart.time),
onTap: () async {
final newTime = await selectTime(context,
initialTime: Time(hour: 8, minute: 0));
if (newTime != null) {
bloc.updateTimetableStartTime(newTime);
}
},
),
const Divider(),
SwitchListTile.adaptive(
title: const Text("Kürzel im Stundenplan anzeigen"),
value: userSettings.showAbbreviation,
onChanged: (newValue) {
bloc.updateSettings(
userSettings.copyWith(showAbbreviation: newValue));
},
),
],
);
},
);
}
}

class LessonsLengthField extends StatelessWidget {
const LessonsLengthField({
super.key,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 85 additions & 0 deletions app/test_goldens/timetable/timetable_settings_page_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt)
// Licensed under the EUPL-1.2-or-later.
//
// You may obtain a copy of the Licence at:
// https://joinup.ec.europa.eu/software/page/eupl
//
// SPDX-License-Identifier: EUPL-1.2

import 'package:bloc_provider/bloc_provider.dart';
import 'package:bloc_provider/multi_bloc_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:golden_toolkit/golden_toolkit.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:provider/provider.dart';
import 'package:sharezone/settings/src/bloc/user_settings_bloc.dart';
import 'package:sharezone/settings/src/subpages/timetable/bloc/timetable_settings_bloc_factory.dart';
import 'package:sharezone/settings/src/subpages/timetable/time_picker_settings_cache.dart';
import 'package:sharezone/settings/src/subpages/timetable/timetable_settings_page.dart';
import 'package:sharezone/sharezone_plus/subscription_service/subscription_service.dart';
import 'package:sharezone/timetable/src/models/lesson_length/lesson_length_cache.dart';
import 'package:sharezone_widgets/sharezone_widgets.dart';
import 'package:user/user.dart';

import 'timetable_settings_page_test.mocks.dart';

@GenerateNiceMocks([
MockSpec<LessonLengthCache>(),
MockSpec<TimePickerSettingsCache>(),
MockSpec<SubscriptionService>(),
MockSpec<UserSettingsBloc>(),
])
void main() {
group(TimetableSettingsPage, () {
late UserSettingsBloc userSettingsBloc;

setUp(() {
userSettingsBloc = MockUserSettingsBloc();

when(userSettingsBloc.streamUserSettings())
.thenAnswer((_) => Stream.value(UserSettings.defaultSettings()));
});

Future<void> pumpTimetableSettingsPage(
WidgetTester tester, {
ThemeData? themeData,
}) async {
await tester.pumpWidgetBuilder(
Provider<SubscriptionService>(
create: (context) => MockSubscriptionService(),
child: MultiBlocProvider(
blocProviders: [
BlocProvider<TimetableSettingsBlocFactory>(
bloc: TimetableSettingsBlocFactory(
MockLessonLengthCache(),
MockTimePickerSettingsCache(),
),
),
BlocProvider<UserSettingsBloc>(bloc: userSettingsBloc)
],
child: (_) => const TimetableSettingsPage(),
),
),
wrapper: materialAppWrapper(theme: themeData),
);
}

testGoldens('should render as expected (light mode)', (tester) async {
await pumpTimetableSettingsPage(
tester,
themeData: getLightTheme(),
);
await multiScreenGolden(tester, 'timetable_settings_page_light');
});

testGoldens('should render as expected (dark mode)', (tester) async {
await pumpTimetableSettingsPage(
tester,
themeData: getDarkTheme(),
);
await multiScreenGolden(tester, 'timetable_settings_page_dark');
});
});
}
Loading

0 comments on commit c6b77ad

Please sign in to comment.