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 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 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.'; } }