Add symbol for offline available sheets
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -254,6 +254,13 @@ class ApiClient {
|
||||
return cachedFile;
|
||||
}
|
||||
|
||||
Future<bool> isPdfFileCached(String sheetUuid) async {
|
||||
final cacheDir = await getTemporaryDirectory();
|
||||
final cachedFile = File('${cacheDir.path}/$sheetUuid.pdf');
|
||||
|
||||
return await cachedFile.exists();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Annotation Operations
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -125,6 +125,10 @@ class _HomePageState extends State<HomePage> with RouteAware {
|
||||
_sheets = await _sortSheetsByRecency(result.sheets);
|
||||
_isOnline = result.isOnline;
|
||||
|
||||
for (var sheet in _sheets) {
|
||||
sheet.availableOffline = await _apiClient!.isPdfFileCached(sheet.uuid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ class _SheetViewerPageState extends State<SheetViewerPage>
|
||||
// Native: use file cache
|
||||
final file = await widget.apiClient.getPdfFileCached(widget.sheet.uuid);
|
||||
_document = await PdfDocument.openFile(file.path);
|
||||
widget.sheet.availableOffline = true;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
|
||||
Reference in New Issue
Block a user