Adds real-time connectivity monitoring and visual feedback across the app. Offline icon appears in all app bars when disconnected, cached content shows download badges, and access control prevents browsing servers or opening uncached content without internet connection. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
58 lines
1.8 KiB
Dart
58 lines
1.8 KiB
Dart
import 'package:worldhopper/models/opds_entry.dart';
|
|
import 'package:worldhopper/services/epub_download_service.dart';
|
|
|
|
/// Service for checking if content is available offline
|
|
///
|
|
/// Determines whether a given OPDS entry can be accessed without
|
|
/// an internet connection.
|
|
class OfflineContentChecker {
|
|
final EpubDownloadService _epubService;
|
|
|
|
OfflineContentChecker({
|
|
required EpubDownloadService epubService,
|
|
}) : _epubService = epubService;
|
|
|
|
/// Check if the given content is available offline
|
|
///
|
|
/// Returns true if:
|
|
/// - For EPUBs: The file is cached locally
|
|
/// - For OPDS-PS streams: Always returns false (pages are streamed from server)
|
|
///
|
|
/// Returns false otherwise.
|
|
Future<bool> isContentAvailableOffline(OPDSEntry entry) async {
|
|
// EPUB publications can be cached
|
|
if (entry.isEpub) {
|
|
return await _epubService.isEpubCached(entry);
|
|
}
|
|
|
|
// Image streams (OPDS-PS) require server connection
|
|
// Pages are streamed and not fully cached
|
|
if (entry.isImageStream) {
|
|
return false;
|
|
}
|
|
|
|
// Default to false for unknown content types
|
|
return false;
|
|
}
|
|
|
|
/// Get a detailed status message about offline availability
|
|
///
|
|
/// Returns a user-friendly message explaining whether the content
|
|
/// is available offline and why.
|
|
Future<String> getOfflineStatusMessage(OPDSEntry entry) async {
|
|
if (entry.isEpub) {
|
|
final isCached = await _epubService.isEpubCached(entry);
|
|
if (isCached) {
|
|
return 'This EPUB is cached and available offline.';
|
|
} else {
|
|
return 'This EPUB is not cached. Connect to internet to download.';
|
|
}
|
|
}
|
|
|
|
if (entry.isImageStream) {
|
|
return 'Image streams require an internet connection. Pages may not load offline.';
|
|
}
|
|
|
|
return 'This content requires an internet connection.';
|
|
}
|
|
}
|