Skip to content

Commit

Permalink
LessonCardInfoPanelTimeToEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
StarProxima committed May 3, 2023
1 parent 754772b commit e531c5b
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:cube_system/features/timetable_page/state_holders/lessons/curren

final currentLessonTimeToEndProvider = Provider<DateTimeDuration?>((ref) {
final currentDateTime = ref.watch(currentDateTimeQuick);
final activeLesson = ref.watch(currentLesson);
final activeLesson = ref.watch(currentLessonStateHolder);

if (activeLesson == null) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ final nextLessonTimeToStartProgressValueProvider = Provider<double>((ref) {
final timeLeft = ref.read(nextLessonTimeToStartProvider)?.duration;
if (timeLeft == null) return 1;

final lessonNext = ref.watch(nextLesson);
final lessonLast = ref.watch(lastLesson);
final lessonNext = ref.watch(nextLessonStateHolder);
final lessonLast = ref.watch(lastLessonStateHolder);

if (lessonNext == null || lessonLast == null) return 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ final nextLessonTimeToStartProvider = Provider<DateTimeDuration?>((ref) {
if (condition.isNever) return null;

if (condition.isOnlyRecessBetweenLessons) {
final last = ref.watch(lastLesson);
final next = ref.watch(nextLesson);
final last = ref.watch(lastLessonStateHolder);
final next = ref.watch(nextLessonStateHolder);
if (last == null || next == null) return null;
if (next.number - last.number != 1) return null;
}

final next = ref.watch(nextLesson);
final next = ref.watch(nextLessonStateHolder);

if (next == null) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ import 'package:cube_system/features/settings/state_holders/app_lesson_colors.da

import 'package:cube_system/features/timetable_page/state_holders/lessons/next_lesson.dart';

import 'package:cube_system/features/timetable_page/managers/timetable_lessons_manager.dart';

part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_body.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_footer.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_header.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel_icon.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel_chip.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel_time_to_end.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/info_panel/lesson_card_info_panel.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_indicator.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_time_left.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/next_lesson_time_to_start_progress_bar.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_lesson_type_chip.dart';
part 'package:cube_system/features/timetable_page/features/lesson_card/ui/widgets/lesson_card_time_to_start.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ class LessonCardInfoPanel extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final isRemotely =
ref.watch(_lessonInLessonCard.select((value) => value.isRemotely));
final lesson = ref.watch(_lessonInLessonCard);

final isCollision =
ref.watch(_lessonInLessonCard.select((value) => value.isCollision));
final isRemotely = lesson.isRemotely;

final isCancelled =
ref.watch(_lessonInLessonCard.select((value) => value.isCancelled));
final isCollision = lesson.isCollision;

final isActiveLessons =
ref.watch(_lessonInLessonCard) == ref.watch(currentLesson);
final isCancelled = lesson.isCancelled;

final currentLesson = ref.watch(currentLessonStateHolder);

final equelNumber = lesson.number == currentLesson?.number;

final equelStartDateTime = lesson.dateTimings.startDateTime ==
currentLesson?.dateTimings.startDateTime;

final isActiveLessons = equelNumber && equelStartDateTime;

// final isCollision = _random.nextInt(100) < 25;

Expand All @@ -43,28 +48,7 @@ class LessonCardInfoPanel extends ConsumerWidget {
LessonCardInfoPanelIcon(
icon: Text('$numberOfNotes'),
),
if (isActiveLessons)
Consumer(
builder: (context, ref, _) {
ref.watch(
currentLessonTimeToEndProvider
.select((value) => value?.format().length),
);

final hasHours =
(ref.read(currentLessonTimeToEndProvider)?.hours ?? 0) > 0;

return hasHours
? const LessonCardInfoPanelChip(
minWidth: 66,
text: LessonCardTimeLeft(),
)
: const LessonCardInfoPanelChip(
minWidth: 46,
text: LessonCardTimeLeft(),
);
},
),
const LessonCardInfoPanelTimeToEnd(),
if (isCollision)
const LessonCardInfoPanelChip(
text: Text('Коллизия'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
part of 'package:cube_system/features/timetable_page/features/lesson_card/ui/lesson_card.dart';

class LessonCardInfoPanelTimeToEnd extends ConsumerWidget {
const LessonCardInfoPanelTimeToEnd({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final lesson = ref.watch(_lessonInLessonCard);

final currentLesson = ref.watch(currentLessonStateHolder);

final manager = ref.read(timetableLessonsManager);

final isActiveLessons = manager.isEquelLessons(lesson, currentLesson);

if (!isActiveLessons) return const SizedBox();

return Consumer(
builder: (context, ref, _) {
ref.watch(
currentLessonTimeToEndProvider
.select((value) => value?.format().length),
);

final hasHours =
(ref.read(currentLessonTimeToEndProvider)?.hours ?? 0) > 0;

return hasHours
? const LessonCardInfoPanelChip(
minWidth: 66,
text: _LessonCardInfoPanelTimeToEndText(),
)
: const LessonCardInfoPanelChip(
minWidth: 46,
text: _LessonCardInfoPanelTimeToEndText(),
);
},
);
}
}

class _LessonCardInfoPanelTimeToEndText extends ConsumerWidget {
const _LessonCardInfoPanelTimeToEndText({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
return Consumer(
builder: (context, ref, _) {
final timeToEnd = ref.watch(currentLessonTimeToEndProvider);
final timeToEndStr = timeToEnd?.format() ?? '00:00';
return Text(
timeToEndStr,
style: context.textStyles.chipLabel
.copyWith(color: context.colors.white),
);
},
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ class LessonCardTimeToStart extends ConsumerWidget {
nextLessonTimeToStartProvider.select((value) => value == null),
);

final lessonNext = ref.watch(nextLesson);
final lessonCurrent = ref.watch(currentLesson);
final nextLesson = ref.watch(nextLessonStateHolder);

if (dontShow || lesson != lessonNext || lessonCurrent != null) {
final currentLesson = ref.watch(currentLessonStateHolder);

final manager = ref.read(timetableLessonsManager);

final isActiveLessons = manager.isEquelLessons(lesson, nextLesson);

if (dontShow || !isActiveLessons || currentLesson != null) {
return const SizedBox();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ final timetableLessonsManager = Provider<TimetableLessonsManager>((ref) {
events: ref.watch(timetablePageEvents.notifier),
currentDateTime: ref.watch(currentDateTimeQuick.notifier),
selectedDate: ref.watch(selectedDate.notifier),
currentLesson: ref.watch(currentLesson.notifier),
nextLesson: ref.watch(nextLesson.notifier),
lastLesson: ref.watch(lastLesson.notifier),
currentLesson: ref.watch(currentLessonStateHolder.notifier),
nextLesson: ref.watch(nextLessonStateHolder.notifier),
lastLesson: ref.watch(lastLessonStateHolder.notifier),
);
});

Expand Down Expand Up @@ -215,4 +215,9 @@ class TimetableLessonsManager {
}
}
}

bool isEquelLessons(Lesson? one, Lesson? two) {
return one?.dateTimings.startDateTime == two?.dateTimings.startDateTime &&
one?.number == two?.number;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:cube_system/models/lesson/lesson.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

final currentLesson = StateProvider<Lesson?>((ref) {
// TODO: Объеденить current, next, last в один stateHolder
// TODO: Возможно, стоит хранить не Lesson, a LessonDateTimings и LessonTimings

final currentLessonStateHolder = StateProvider<Lesson?>((ref) {
return null;
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:cube_system/models/lesson/lesson.dart';

final lastLesson = StateProvider<Lesson?>((ref) {
final lastLessonStateHolder = StateProvider<Lesson?>((ref) {
return null;
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'package:cube_system/models/lesson/lesson.dart';

final nextLesson = StateProvider<Lesson?>((ref) {
final nextLessonStateHolder = StateProvider<Lesson?>((ref) {
return null;
});

0 comments on commit e531c5b

Please sign in to comment.