Skip to content

Commit

Permalink
Adapting for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Sep 18, 2023
1 parent 9b298be commit 56dd488
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
9 changes: 6 additions & 3 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,11 @@ class HomePageState extends State<HomePage> {
),
);
apidataTT = response.data;
_lessonStatus =
getLessonStatus(apidataTT["Days"].values.first, TimeOfDay.now());
_lessonStatus = getLessonStatus(
apidataTT["Days"].values.length == 0
? []
: apidataTT["Days"].values.first,
TimeOfDay.now());
if (_lessonStatus.hasLessonsToday) {
_startTimer();
}
Expand Down Expand Up @@ -681,7 +684,7 @@ class HomePageState extends State<HomePage> {
splashColor: Colors.transparent,
child: Badge(
label: Text(local.homePreview),
alignment: AlignmentDirectional.topEnd,
alignment: Alignment.topLeft,
child: ListTile(
leading: const Icon(Icons.bolt_rounded),
title: Text(local.homeQuickstart),
Expand Down
25 changes: 12 additions & 13 deletions lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class TimeTablePageState extends State<MessagesPage> {
}
];
List<dynamic> msgs =
apidataMsg.where((msg) => msg["type"] == "sprava").toList();
apidataMsg.where((msg) => msg["typ"] == "sprava").toList();
List<dynamic> msgsWOR = List.from(msgs);
List<Map<String, int>> bump = [];
for (Map<String, dynamic> msg in msgs) {
Expand All @@ -141,13 +141,8 @@ class TimeTablePageState extends State<MessagesPage> {
}
}
for (Map<String, dynamic> msg in msgsWOR) {
String attText = msg["attachments"].length < 5
? msg["attachments"].length > 1
? "y"
: "a"
: "";
rows.add(Card(
color: msg["isSeen"] ? null : const Color.fromARGB(255, 124, 95, 0),
//color: msg["isSeen"] ? null : const Color.fromARGB(255, 124, 95, 0),
child: InkWell(
onTap: () {
Navigator.push(
Expand All @@ -165,8 +160,7 @@ class TimeTablePageState extends State<MessagesPage> {
Row(
children: [
Text(
'${msg["owner"]["firstname"]?.trim()} ${msg["owner"]["lastname"]?.trim()}'
.replaceAll(RegExp(r'\s+'), ' '),
msg["vlastnik_meno"].replaceAll(RegExp(r'\s+'), ' '),
style: const TextStyle(fontSize: 18),
),
const Icon(
Expand All @@ -175,7 +169,7 @@ class TimeTablePageState extends State<MessagesPage> {
),
Expanded(
child: Text(
unescape.convert(msg["title"]),
unescape.convert(msg["user_meno"]),
overflow: TextOverflow.fade,
maxLines: 5,
softWrap: false,
Expand All @@ -197,6 +191,7 @@ class TimeTablePageState extends State<MessagesPage> {
)
],
),
/*
for (Map<String, dynamic> r in msg["replies"])
Row(
children: [
Expand All @@ -217,7 +212,8 @@ class TimeTablePageState extends State<MessagesPage> {
),
],
),
if (msg["attachments"].length > 0)
*/
if (msg["data"]["Value"]["attachements"].length > 0)
Padding(
padding: const EdgeInsets.only(top: 5),
child: Row(
Expand All @@ -227,8 +223,11 @@ class TimeTablePageState extends State<MessagesPage> {
Icons.attach_file_rounded,
size: 18,
),
Text(msg["attachments"].length.toString()),
Text(" Přípon$attText"),
Text(msg["data"]["Value"]["attachements"]
.length
.toString()),
const Text(
""), //TODO Setup localization for attachments
],
),
),
Expand Down
28 changes: 25 additions & 3 deletions lib/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TimeTablePageState extends State<TimeTablePage> {
String token = sharedPreferences.getString("token")!;

Response response = await dio.get(
"$baseUrl/api/timetable?to=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime(date.year, date.month, date.day))}&from=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime.now())}",
"$baseUrl/api/timetable?to=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime(date.year, date.month, date.day))}&from=${DateFormat('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'', 'en_US').format(DateTime(date.year, date.month, date.day))}",
options: buildCacheOptions(
const Duration(days: 4),
forceRefresh: true,
Expand All @@ -166,7 +166,8 @@ class TimeTablePageState extends State<TimeTablePage> {

List<TimeTableClass> ttClasses = <TimeTableClass>[];
Map<String, dynamic> lessons = response.data["Days"];
for (Map<String, dynamic> ttLesson in lessons.values.first) {
for (Map<String, dynamic> ttLesson
in lessons.values.isEmpty ? [] : lessons.values.first) {
ttClasses.add(
TimeTableClass(
ttLesson["uniperiod"],
Expand All @@ -185,7 +186,10 @@ class TimeTablePageState extends State<TimeTablePage> {
);
}
TimeTableData t = TimeTableData(
DateTime.parse(response.data["Days"].keys.first), ttClasses);
DateTime.parse(response.data["Days"].keys.isEmpty
? date.toString()
: response.data["Days"].keys.first),
ttClasses);
timetables.add(t);
return t;
}
Expand Down Expand Up @@ -280,6 +284,24 @@ Widget getTimeTable(TimeTableData tt, int daydiff, Function(int) modifyDayDiff,
}
for (TimeTableClass ttclass in tt.classes) {
List<Widget> extrasRow = <Widget>[];
if (ttclass.data["teachers"] != null) {
List<dynamic> teachers = ttclass.data["teachers"];
String names = teachers.length == 1 ? "Teacher: " : "Teachers: ";
names += teachers[0]["firstname"] + " " + teachers[0]["lastname"];
for (Map<String, dynamic> teacher in teachers.skip(1)) {
names += ", ${teacher["firstname"]} ${teacher["lastname"]}";
}
extrasRow.add(
Expanded(
child: Text(
names,
overflow: TextOverflow.fade,
maxLines: 5,
softWrap: false,
),
),
);
}
if (ttclass.data['curriculum'] != null) {
extrasRow.add(
Expanded(
Expand Down

0 comments on commit 56dd488

Please sign in to comment.