Skip to content

Commit

Permalink
add special message for last week before next study year
Browse files Browse the repository at this point in the history
  • Loading branch information
smart7even committed Aug 18, 2024
1 parent 429685d commit 911e113
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 15 deletions.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -169,6 +174,7 @@ SPEC CHECKSUMS:
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqlite3: 19d8c26842078b45fa2deed63c4bbbe0c0e786ce
sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: c4c93c5f6502fe2754f48404d3594bf779584011

Expand Down
19 changes: 11 additions & 8 deletions lib/common/utils/date_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 1 addition & 5 deletions lib/feature/schedule/widget/schedule_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,7 @@ class _SchedulePageState extends State<SchedulePage>
}

if (currentWeek < 0 || currentWeek > 52) {
return ScheduleWidget(
schedule: const Schedule.empty(),
onNextWeek: () => onNextWeek(context),
onPreviousWeek: () => onPreviousWeek(context),
);
return null;
}

return ScheduleWidget(
Expand Down
73 changes: 73 additions & 0 deletions lib/feature/schedule/widget/schedule_widget.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 4 additions & 1 deletion lib/l10n/app_ru.arb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
"cacheIsCleared": "Кэш успешно очищен!",
"errorWhileCleaningCache": "Возникла неожиданная ошибка при очистке кэша. Попробуйте снова",
"cacheIsEmpty": "Кэш уже пуст!",
"share": "Поделиться"
"share": "Поделиться",
"lastWeekOfCurrentStudyYear": "Это последняя неделя текущего учебного года. Скоро должно появиться расписание для следующего учебного года",
"checkOutOfficialWebsiteForPreciseInformation": "Проверяйте точную информацию на официальном веб-сайте",
"openOfficialWebsite": "Открыть официальный вебсайт"
}
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
32 changes: 32 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions test/date_utils_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
);
},
);
}

0 comments on commit 911e113

Please sign in to comment.