This commit is contained in:
2024-12-22 02:32:40 +03:00
parent de1d6c85e5
commit 86e539daf1
38 changed files with 213 additions and 195 deletions

View File

@@ -18,7 +18,22 @@ class CalendarScheduleController extends GetxController {
loading = false.obs; update();
}
static void openScreen() async {
Get.to(() => const CalendarScreen());
static void openScreen() async { Get.to(() => const CalendarScreen()); }
void goToConcreteDay(DateTime day) async {
date = (day.copyWith(hour: 12, minute: 0, millisecond: 0, microsecond: 0)).obs;
loadSchedule(date.value);
}
void goToPrevDay() async {
if(date.value.isBefore(DateTime(2024, 8, 1, 23, 59))) return;
date = (date.value.copyWith().subtract(const Duration(days: 1)).copyWith(hour: 12, minute: 0)).obs;
loadSchedule(date.value);
}
void goToNextDay() async {
if(date.value.isAfter(DateTime(2025, 12, 31))) return;
date = (date.value.copyWith().add(const Duration(days: 1)).copyWith(hour: 12, minute: 0)).obs;
loadSchedule(date.value);
}
}

View File

@@ -1,5 +1,6 @@
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:reverse_nn/application/services/schedule.dart';
@@ -12,6 +13,7 @@ class ScheduleController extends GetxController {
}
void updateCurrentSchedule() async {
if(kDebugMode) { log('update current status'); }
currentSchedule = (await ScheduleService().getCurrentStatus()).obs;
update();

View File

@@ -66,9 +66,10 @@ class ScheduleService {
}).toList();
}
Future<List<Map<String, dynamic>>?> getScheduleByDate(DateTime datetime) async {
final datetimeStartWithOffset = datetime.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0)
.add(dayOffset);
Future<List<Map<String, dynamic>>?> getScheduleByDate(DateTime datetime, {bool force = false}) async {
final dateStart = datetime.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0);
final dateEnd = datetime.copyWith(hour: 23, minute: 59, second: 59, microsecond: 999, millisecond: 999);
final datetimeStartWithOffset = dateStart.copyWith().add(dayOffset);
final DateTime usedScheduleDatetime = datetime.isAfter(datetimeStartWithOffset)
? datetime
@@ -93,23 +94,34 @@ class ScheduleService {
for (var i = 0; i < schedule.length; i++) {
final scheduleItem = schedule[i];
final int duration = (scheduleItem['duration'] as int);
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
durationOffset += duration;
bool showEndDate = false;
if(i == (schedule.length -1)) {
final scheduleNextDay = await getScheduleByDate(datetime.copyWith().add(const Duration(days: 1)));
final firstScheduleElement = scheduleNextDay?[0];
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
showEndDate = true;
if(!force) {
if(i == 0) {
final schedulePrevDay = await getScheduleByDate(datetime.copyWith().subtract(const Duration(days: 1)), force: true);
final lastScheduleElement = schedulePrevDay?.last;
if(lastScheduleElement != null && (lastScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
start = start.subtract(Duration(minutes: lastScheduleElement['duration'] as int));
}
}
if(i == (schedule.length -1)) {
final scheduleNextDay = await getScheduleByDate(datetime.copyWith().add(const Duration(days: 1)), force: true);
final firstScheduleElement = scheduleNextDay?.first;
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
}
}
}
schedule[i]['start'] = start;
schedule[i]['show_start_date'] = !(start.isAfter(dateStart) && start.isBefore(dateEnd));
schedule[i]['end'] = end;
schedule[i]['show_end_date'] = !(end.isAfter(dateStart) && end.isBefore(dateEnd));
}
return schedule;
}
@@ -118,39 +130,12 @@ class ScheduleService {
final List<Map<String, dynamic>>? schedule = await getScheduleByDate(now);
if(schedule == null) return null;
DateTime datetimeStartWithOffset = now.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0)
.add(dayOffset);
if(now.isBefore(datetimeStartWithOffset)) {
datetimeStartWithOffset = datetimeStartWithOffset.subtract(const Duration(days: 1));
}
int durationOffset = 0;
for (var i = 0; i < schedule.length; i++) {
final scheduleItem = schedule[i];
final int duration = (scheduleItem['duration'] as int);
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
durationOffset += duration;
bool showEndDate = false;
if(i == (schedule.length -1)) {
final scheduleNextDay = await getScheduleByDate(now.copyWith().add(const Duration(days: 1)));
final firstScheduleElement = scheduleNextDay?[0];
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
showEndDate = true;
}
}
for(var i = 0; i < schedule.length; i++) {
final start = schedule[i]['start'];
final end = schedule[i]['end'];
if(now.isAfter(start) && now.isBefore(end)) {
return <String, dynamic>{
"direction": scheduleItem['direction'] as String,
"start": start,
"end": end,
"need_show_end_date": showEndDate,
};
return schedule[i];
}
}