From 911e113a4b9f89ff52a9e18ba47aa86248b450e0 Mon Sep 17 00:00:00 2001 From: Oleg Date: Sun, 18 Aug 2024 16:57:53 +0300 Subject: [PATCH] add special message for last week before next study year --- ios/Podfile.lock | 6 ++ lib/common/utils/date_utils.dart | 19 +++-- .../schedule/widget/schedule_page.dart | 6 +- .../schedule/widget/schedule_widget.dart | 73 +++++++++++++++++++ lib/l10n/app_en.arb | 5 +- lib/l10n/app_ru.arb | 5 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 32 ++++++++ pubspec.yaml | 1 + test/date_utils_test.dart | 24 ++++++ 10 files changed, 158 insertions(+), 15 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 7def2b7..3139cae 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -96,6 +96,8 @@ PODS: - sqlite3/fts5 - sqlite3/perf-threadsafe - sqlite3/rtree + - url_launcher_ios (0.0.1): + - Flutter DEPENDENCIES: - appmetrica_plugin (from `.symlinks/plugins/appmetrica_plugin/ios`) @@ -105,6 +107,7 @@ DEPENDENCIES: - share_plus (from `.symlinks/plugins/share_plus/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`) + - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) SPEC REPOS: trunk: @@ -142,6 +145,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" sqlite3_flutter_libs: :path: ".symlinks/plugins/sqlite3_flutter_libs/ios" + url_launcher_ios: + :path: ".symlinks/plugins/url_launcher_ios/ios" SPEC CHECKSUMS: appmetrica_plugin: d5b67180992259ecfa040189027808915101b893 @@ -169,6 +174,7 @@ SPEC CHECKSUMS: shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 sqlite3: 19d8c26842078b45fa2deed63c4bbbe0c0e786ce sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b + url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011 diff --git a/lib/common/utils/date_utils.dart b/lib/common/utils/date_utils.dart index c4903a4..c7661af 100644 --- a/lib/common/utils/date_utils.dart +++ b/lib/common/utils/date_utils.dart @@ -52,14 +52,17 @@ DateTime getEndOfStudyWeek(int week, DateTime nowTime) { } DateTime getStartOfStudyYearDate(DateTime nowTime) { - if (nowTime.month >= kSeptemberMonthNumber) { - return getWeekStart( - DateTime( - nowTime.year, - kSeptemberMonthNumber, - 1, - ), - ); + final currentStudyYearStartDate = getWeekStart( + DateTime( + nowTime.year, + kSeptemberMonthNumber, + 1, + ), + ); + + if (nowTime.isAtSameMomentAs(currentStudyYearStartDate) || + nowTime.isAfter(currentStudyYearStartDate)) { + return currentStudyYearStartDate; } else { return getWeekStart( DateTime( diff --git a/lib/feature/schedule/widget/schedule_page.dart b/lib/feature/schedule/widget/schedule_page.dart index 66f3a30..e4ef418 100644 --- a/lib/feature/schedule/widget/schedule_page.dart +++ b/lib/feature/schedule/widget/schedule_page.dart @@ -599,11 +599,7 @@ class _SchedulePageState extends State } if (currentWeek < 0 || currentWeek > 52) { - return ScheduleWidget( - schedule: const Schedule.empty(), - onNextWeek: () => onNextWeek(context), - onPreviousWeek: () => onPreviousWeek(context), - ); + return null; } return ScheduleWidget( diff --git a/lib/feature/schedule/widget/schedule_widget.dart b/lib/feature/schedule/widget/schedule_widget.dart index ebd824f..058adf1 100644 --- a/lib/feature/schedule/widget/schedule_widget.dart +++ b/lib/feature/schedule/widget/schedule_widget.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; import 'package:uneconly/common/localization/localization.dart'; import 'package:uneconly/common/utils/date_utils.dart'; import 'package:uneconly/common/utils/string_utils.dart'; import 'package:uneconly/feature/schedule/model/schedule.dart'; import 'package:uneconly/feature/schedule/widget/lesson_tile.dart'; +import 'package:url_launcher/url_launcher.dart'; /// {@template schedule_widget} /// ScheduleWidget widget @@ -147,6 +149,77 @@ class ScheduleWidget extends StatelessWidget { ), ); + final isLastStudyWeekOfCurrentYear = currentSchedule.week == 52; + + if (isLastStudyWeekOfCurrentYear) { + return Center( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only( + left: 8, + right: 8, + top: 0, + bottom: 20, + ), + child: Column( + children: [ + const Text( + '🍀', + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 100, + ), + ), + Text('$weekStart - $weekEnd'), + const SizedBox( + height: 8, + ), + Text( + AppLocalizations.of(context)!.lastWeekOfCurrentStudyYear, + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 18, + ), + ), + const SizedBox( + height: 8, + ), + Text( + AppLocalizations.of(context)! + .checkOutOfficialWebsiteForPreciseInformation, + textAlign: TextAlign.center, + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 18, + ), + ), + const SizedBox( + height: 8, + ), + ElevatedButton( + onPressed: () async { + await launchUrl( + Uri.parse( + 'https://rasp.unecon.ru/raspisanie_grp.php?g=${currentSchedule.groupId}', + ), + ); + }, + child: Text( + AppLocalizations.of(context)!.openOfficialWebsite, + ), + ), + ], + ), + ), + ], + ), + ); + } + return Center( child: Column( mainAxisSize: MainAxisSize.min, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 1f951fc..66ddc6e 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -47,5 +47,8 @@ "cacheIsCleared": "Cache is successfully cleared!", "errorWhileCleaningCache": "Unexpected error happened during cache clean. Try again later", "cacheIsEmpty": "Cache is empty. Nothing to clean!", - "share": "Share" + "share": "Share", + "lastWeekOfCurrentStudyYear": "This is the last week of current study year. Next study year schedule should be available soon", + "checkOutOfficialWebsiteForPreciseInformation": "Check out official website for precise info", + "openOfficialWebsite": "Open official website" } \ No newline at end of file diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index 8c3c844..12b8a24 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -44,5 +44,8 @@ "cacheIsCleared": "Кэш успешно очищен!", "errorWhileCleaningCache": "Возникла неожиданная ошибка при очистке кэша. Попробуйте снова", "cacheIsEmpty": "Кэш уже пуст!", - "share": "Поделиться" + "share": "Поделиться", + "lastWeekOfCurrentStudyYear": "Это последняя неделя текущего учебного года. Скоро должно появиться расписание для следующего учебного года", + "checkOutOfficialWebsiteForPreciseInformation": "Проверяйте точную информацию на официальном веб-сайте", + "openOfficialWebsite": "Открыть официальный вебсайт" } \ No newline at end of file diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 088835f..f2356e7 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -9,10 +9,12 @@ import path_provider_foundation import share_plus import shared_preferences_foundation import sqlite3_flutter_libs +import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin")) + UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index f3c926c..3353552 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -970,6 +970,30 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "21b704ce5fa560ea9f3b525b43601c678728ba46725bab9b01187b4831377ed3" + url: "https://pub.dev" + source: hosted + version: "6.3.0" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: f0c73347dfcfa5b3db8bc06e1502668265d39c08f310c29bff4e28eea9699f79 + url: "https://pub.dev" + source: hosted + version: "6.3.9" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e + url: "https://pub.dev" + source: hosted + version: "6.3.1" url_launcher_linux: dependency: transitive description: @@ -978,6 +1002,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.0" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: "9a1a42d5d2d95400c795b2914c36fdcb525870c752569438e4ebb09a2b5d90de" + url: "https://pub.dev" + source: hosted + version: "3.2.0" url_launcher_platform_interface: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5bf6d4f..89ca579 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -54,6 +54,7 @@ dependencies: octopus: ^0.0.9 share_plus: ^10.0.2 appmetrica_plugin: ^2.1.1 + url_launcher: ^6.3.0 dev_dependencies: flutter_test: diff --git a/test/date_utils_test.dart b/test/date_utils_test.dart index 34f683f..eee9d9d 100644 --- a/test/date_utils_test.dart +++ b/test/date_utils_test.dart @@ -78,4 +78,28 @@ void main() { ); }, ); + + test( + 'getStartOfStudyYearDate returns start of study year for 2024/2025 study year when it is start of first study week', + () { + final nowTime = DateTime(2024, 8, 26, 0, 0, 1); + + expect( + getStartOfStudyYearDate(nowTime), + equals(DateTime(2024, 8, 26)), + ); + }, + ); + + test( + 'getStartOfStudyYearDate returns start of study year for 2024/2025 study year when month is September', + () { + final nowTime = DateTime(2024, 9, 1, 0, 0, 1); + + expect( + getStartOfStudyYearDate(nowTime), + equals(DateTime(2024, 8, 26)), + ); + }, + ); }