diff --git a/lib/core/models/sheet.dart b/lib/core/models/sheet.dart index dcfc5af..4fea404 100644 --- a/lib/core/models/sheet.dart +++ b/lib/core/models/sheet.dart @@ -7,12 +7,14 @@ class Sheet { String name; String composer; DateTime updatedAt; + bool availableOffline; Sheet({ required this.uuid, required this.name, required this.composer, required this.updatedAt, + this.availableOffline = false, }); /// Creates a [Sheet] from a JSON map returned by the API. diff --git a/lib/core/services/api_client.dart b/lib/core/services/api_client.dart index 1563c70..efc3f1c 100644 --- a/lib/core/services/api_client.dart +++ b/lib/core/services/api_client.dart @@ -254,6 +254,13 @@ class ApiClient { return cachedFile; } + Future isPdfFileCached(String sheetUuid) async { + final cacheDir = await getTemporaryDirectory(); + final cachedFile = File('${cacheDir.path}/$sheetUuid.pdf'); + + return await cachedFile.exists(); + } + // --------------------------------------------------------------------------- // Annotation Operations // --------------------------------------------------------------------------- diff --git a/lib/features/home/home_page.dart b/lib/features/home/home_page.dart index 413c032..d6a3728 100644 --- a/lib/features/home/home_page.dart +++ b/lib/features/home/home_page.dart @@ -125,6 +125,10 @@ class _HomePageState extends State with RouteAware { _sheets = await _sortSheetsByRecency(result.sheets); _isOnline = result.isOnline; + for (var sheet in _sheets) { + sheet.availableOffline = await _apiClient!.isPdfFileCached(sheet.uuid); + } + return result; } diff --git a/lib/features/home/widgets/sheet_list_item.dart b/lib/features/home/widgets/sheet_list_item.dart index 847dfda..5175139 100644 --- a/lib/features/home/widgets/sheet_list_item.dart +++ b/lib/features/home/widgets/sheet_list_item.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; import '../../../core/models/sheet.dart'; /// A list tile displaying a single sheet's information. @@ -24,6 +25,10 @@ class SheetListItem extends StatelessWidget { subtitle: Text(sheet.composer), onTap: onTap, onLongPress: onLongPress, + trailing: Visibility( + visible: !kIsWeb && sheet.availableOffline, + child: Icon(Icons.download_done, color: Colors.green), + ), ); } } diff --git a/lib/features/sheet_viewer/sheet_viewer_page.dart b/lib/features/sheet_viewer/sheet_viewer_page.dart index 97ca6c7..9ce0641 100644 --- a/lib/features/sheet_viewer/sheet_viewer_page.dart +++ b/lib/features/sheet_viewer/sheet_viewer_page.dart @@ -98,6 +98,7 @@ class _SheetViewerPageState extends State // Native: use file cache final file = await widget.apiClient.getPdfFileCached(widget.sheet.uuid); _document = await PdfDocument.openFile(file.path); + widget.sheet.availableOffline = true; } setState(() {