diff --git a/lib/src/ui/components/Bijlage.dart b/lib/src/ui/components/Bijlage.dart index e93afce..ac70374 100644 --- a/lib/src/ui/components/Bijlage.dart +++ b/lib/src/ui/components/Bijlage.dart @@ -4,6 +4,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:filesize/filesize.dart'; +import 'package:url_launcher/url_launcher.dart'; enum DownloadState { done, loading, none } @@ -28,48 +29,54 @@ class BijlageItem extends StatelessWidget { message: bijlage.naam, child: ListTile( onTap: () { - if (onTap != null) onTap(); - if (download != null) { - downloadState.value = DownloadState.loading; + if (bijlage.contentType == "application/octet-stream") { + launch(bijlage.downloadUrl); + } else { + if (onTap != null) onTap(); + if (download != null) { + downloadState.value = DownloadState.loading; - download( - bijlage, - (count, total) { - bijlage.downloadCount = count; - downloadCount.value = count; - if (count >= total) { - downloadState.value = DownloadState.done; - } - }, - ); + download( + bijlage, + (count, total) { + bijlage.downloadCount = count; + downloadCount.value = count; + if (count >= total) { + downloadState.value = DownloadState.done; + } + }, + ); + } } }, leading: bijlage.isFolder ? Icon(Icons.folder_outlined) - : Column( - children: [ - Padding( - padding: EdgeInsets.only( - top: 5, - ), - child: Icon( - Icons.insert_drive_file_outlined, - ), - ), - Padding( - padding: EdgeInsets.only( - top: 7.5, - ), - child: Text( - splittedNaam.length > 1 ? splittedNaam.last.toUpperCase() : bijlage.naam, - style: TextStyle( - fontSize: 12.5, + : bijlage.contentType == "application/octet-stream" + ? Icon(Icons.link) + : Column( + children: [ + Padding( + padding: EdgeInsets.only( + top: 5, + ), + child: Icon( + Icons.insert_drive_file_outlined, + ), ), - ), - ) - ], - ), - subtitle: bijlage.isFolder + Padding( + padding: EdgeInsets.only( + top: 7.5, + ), + child: Text( + splittedNaam.length > 1 ? splittedNaam.last.toUpperCase() : bijlage.naam, + style: TextStyle( + fontSize: 12.5, + ), + ), + ) + ], + ), + subtitle: bijlage.isFolder || bijlage.contentType == "application/octet-stream" ? null : Padding( child: ValueListenableBuilder( @@ -93,7 +100,7 @@ class BijlageItem extends StatelessWidget { vertical: 10, ), ), - trailing: bijlage.isFolder + trailing: bijlage.isFolder || bijlage.contentType == "application/octet-stream" ? Icon( Icons.arrow_forward_ios, size: 14, diff --git a/lib/src/ui/tabs/Studiewijzer.dart b/lib/src/ui/tabs/Studiewijzer.dart index e0b38a6..77fea0c 100644 --- a/lib/src/ui/tabs/Studiewijzer.dart +++ b/lib/src/ui/tabs/Studiewijzer.dart @@ -222,7 +222,7 @@ class _StudiewijzerTab extends State { if (wijstab.bronnen.isNotEmpty) MaterialCard( children: divideListTiles([ - for (var bron in wijstab.bronnen) + for (var bron in wijstab.bronnen.where((b) => !b.isFolder)) //Folders are not yet supported BijlageItem( bron, download: account().magister.bronnen.downloadFile, @@ -248,14 +248,10 @@ class _StudiewijzerTab extends State { onRefresh: () async => retry(), child: EmptyPage( icon: Icons.wifi_off_outlined, - text: error?.error ?? error?.toString(), + text: error?.toString(), ), ), - futureBuilder: () async { - await account().magister.studiewijzers.loadTab( - wijstab, - ); - }, + futureBuilder: () async => await account().magister.studiewijzers.loadTab(wijstab), busyBuilder: (BuildContext context) => Center( child: CircularProgressIndicator(), ), diff --git a/lib/src/utils/hive/adapters.dart b/lib/src/utils/hive/adapters.dart index 3aa6a7d..50d568d 100644 --- a/lib/src/utils/hive/adapters.dart +++ b/lib/src/utils/hive/adapters.dart @@ -501,7 +501,7 @@ class Wijzer { if (pinned == null) { pinned = false; } - if (wijzer["Links"] != null) { + if (wijzer["Links"] != null && wijzer["Links"].isNotEmpty) { this.tabUrl = wijzer["Links"].where((a) => a["Rel"] == "Self").first["Href"]; } if (wijzer["Bronnen"] != null) { diff --git a/lib/src/utils/magister/Bronnen.dart b/lib/src/utils/magister/Bronnen.dart index 2e62574..eef43ca 100644 --- a/lib/src/utils/magister/Bronnen.dart +++ b/lib/src/utils/magister/Bronnen.dart @@ -1,3 +1,5 @@ +import 'package:dio/dio.dart'; + import 'magister.dart'; import 'package:argo/src/utils/hive/adapters.dart'; @@ -35,8 +37,8 @@ class Bronnen extends MagisterApi { onReceiveProgress(bron.size, 0); return; } - await api.dio.download( - bron.downloadUrl, + await Dio().download( + (await api.dio.get(bron.downloadUrl + "?redirect_type=body")).data["location"], savePath, onReceiveProgress: onReceiveProgress, ); diff --git a/lib/src/utils/magister/Studiewijzers.dart b/lib/src/utils/magister/Studiewijzers.dart index 31f7913..bdb3a98 100644 --- a/lib/src/utils/magister/Studiewijzers.dart +++ b/lib/src/utils/magister/Studiewijzers.dart @@ -20,12 +20,13 @@ class Studiewijzers extends MagisterApi { .cast(); } - Future loadWijzer([id = ""]) async { - return (await api.dio.get("api/leerlingen/${account.id}/studiewijzers/$id?peildatum=${dateFormatter.format(DateTime.now())}")).data; + Future loadWijzer() async { + var wijzers = await Future.wait([api.dio.get("api/leerlingen/${account.id}/studiewijzers/?peildatum=${dateFormatter.format(DateTime.now())}"), api.dio.get("api/leerlingen/${account.id}/projecten/?peildatum=${dateFormatter.format(DateTime.now())}")]); + return {...wijzers.first.data}..["Items"].addAll(wijzers.last.data["Items"]); } Future loadChildren(Wijzer wijs) async { - Map wijzer = (await loadWijzer(wijs.id)); + Map wijzer = (await api.dio.get(wijs.tabUrl)).data; wijs.children = wijzer["Onderdelen"]["Items"] .map( (wijs) => Wijzer(wijs),