diff --git a/lib/features/trakt/containers/up_next.container.dart b/lib/features/trakt/containers/up_next.container.dart index df259dc..fdb94e8 100644 --- a/lib/features/trakt/containers/up_next.container.dart +++ b/lib/features/trakt/containers/up_next.container.dart @@ -156,9 +156,11 @@ class TraktContainerState extends State { } Future refresh() async { - _logger.info('Refreshing data'); - _cachedItems = []; - await _loadData(); + try { + _logger.info('Refreshing data for ${widget.loadId}'); + _cachedItems = []; + await _loadData(); + } catch (e) {} } String get title { @@ -234,7 +236,7 @@ class TraktContainerState extends State { ), Stack( children: [ - if ((_cachedItems ?? []).isEmpty && !_isLoading) + if ((_cachedItems ?? []).isEmpty && !_isLoading && _error != null) const Positioned.fill( child: Center( child: Text("Nothing to see here"), @@ -242,18 +244,46 @@ class TraktContainerState extends State { ), if (_isLoading && (_cachedItems ?? []).isEmpty) const SpinnerCards(), - SizedBox( - height: getListHeight(context), - child: RenderListItems( - isWide: widget.loadId == "up_next_series", - items: _cachedItems ?? [], - error: _error, - itemScrollController: _scrollController, - hasError: _error != null, - heroPrefix: "trakt_up_next${widget.loadId}", - service: TraktService.stremioService!, + if (_error != null) Text(_error!), + if (_error != null) + Positioned.fill( + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Error: $_error", + style: theme.textTheme.bodyMedium?.copyWith( + color: Colors.red, + ), + ), + const SizedBox(height: 10), + ElevatedButton( + onPressed: () { + setState(() { + _error = null; + }); + _loadData(); + }, + child: const Text("Retry"), + ), + ], + ), + ), + ), + if (_error == null) + SizedBox( + height: getListHeight(context), + child: RenderListItems( + isWide: widget.loadId == "up_next_series", + items: _cachedItems ?? [], + error: _error, + itemScrollController: _scrollController, + hasError: _error != null, + heroPrefix: "trakt_up_next${widget.loadId}", + service: TraktService.stremioService!, + ), ), - ), ], ) ], diff --git a/lib/features/trakt/service/trakt.service.dart b/lib/features/trakt/service/trakt.service.dart index 32d7228..cf54050 100644 --- a/lib/features/trakt/service/trakt.service.dart +++ b/lib/features/trakt/service/trakt.service.dart @@ -24,8 +24,6 @@ class TraktService { final refetchKey = BehaviorSubject>(); - static const Duration _cacheRevalidationInterval = Duration(hours: 1); - static TraktService? _instance; static TraktService? get instance => _instance; static BaseConnectionService? stremioService; @@ -43,8 +41,6 @@ class TraktService { ); } - Timer? _cacheRevalidationTimer; - clearCache() { _logger.info('Clearing cache'); _cache.clear(); @@ -132,25 +128,6 @@ class TraktService { void _startCacheRevalidation() { _logger.info('Starting cache revalidation timer'); - _cacheRevalidationTimer = Timer.periodic( - _cacheRevalidationInterval, - (_) async { - await _revalidateCache(); - }, - ); - } - - Future _revalidateCache() async { - _logger.info('Revalidating cache'); - for (final key in _cache.keys) { - final cachedData = _cache[key]; - if (cachedData != null) { - final updatedData = await _makeRequest(key, bypassCache: true); - _cache[key] = updatedData; - } - } - - saveCacheToDisk(); } Future _makeRequest(String url, {bool bypassCache = false}) async { diff --git a/lib/pages/home_tab.page.dart b/lib/pages/home_tab.page.dart index b4855a6..edc4978 100644 --- a/lib/pages/home_tab.page.dart +++ b/lib/pages/home_tab.page.dart @@ -67,7 +67,11 @@ class _HomeTabPageState extends State { if (state == null) continue; - promises.add(state.refresh()); + promises.add(() async { + try { + state.refresh(); + } catch (e) {} + }()); } await Future.wait(promises);