From 716f176fb8b755a5dfe0f3b4fb2f678e3811f521 Mon Sep 17 00:00:00 2001 From: rool78 Date: Tue, 4 Jul 2023 20:55:25 +0200 Subject: [PATCH 1/2] disable android refresh when no connectivity --- lib/src/ui/watch/tv_screen.dart | 2 +- lib/src/ui/watch/watch_screen.dart | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/src/ui/watch/tv_screen.dart b/lib/src/ui/watch/tv_screen.dart index 9177d1a238..1f88296f96 100644 --- a/lib/src/ui/watch/tv_screen.dart +++ b/lib/src/ui/watch/tv_screen.dart @@ -174,7 +174,7 @@ class _Body extends ConsumerWidget { interactableSide: cg.InteractableSide.none, orientation: cg.Side.white, ), - errorMessage: 'Could not load TV stream.', + errorMessage: 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error? ); }, ), diff --git a/lib/src/ui/watch/watch_screen.dart b/lib/src/ui/watch/watch_screen.dart index ce43dcdc5b..4cd3a29860 100644 --- a/lib/src/ui/watch/watch_screen.dart +++ b/lib/src/ui/watch/watch_screen.dart @@ -19,6 +19,8 @@ import 'package:lichess_mobile/src/widgets/shimmer.dart'; import 'package:lichess_mobile/src/ui/watch/streamer_screen.dart'; import 'package:lichess_mobile/src/ui/watch/tv_screen.dart'; +import '../../utils/connectivity.dart'; + final _featuredGameNoSoundProvider = featuredGameProvider(withSound: false); class WatchScreen extends ConsumerStatefulWidget { @@ -32,8 +34,15 @@ class _WatchScreenState extends ConsumerState with RouteAware, WidgetsBindingObserver { final _androidRefreshKey = GlobalKey(); + bool isNowOnline = true; + @override Widget build(BuildContext context) { + ref.listen(connectivityChangesProvider, (_, connectivity) { + if (!connectivity.isRefreshing && connectivity.hasValue) { + isNowOnline = connectivity.value!.isOnline; + } + }); return ConsumerPlatformWidget( ref: ref, androidBuilder: _buildAndroid, @@ -49,6 +58,7 @@ class _WatchScreenState extends ConsumerState body: RefreshIndicator( key: _androidRefreshKey, onRefresh: () => ref.refresh(liveStreamersProvider.future), + notificationPredicate: (_) => isNowOnline, child: SafeArea( child: OrientationBuilder( builder: (context, orientation) { @@ -84,7 +94,7 @@ class _WatchScreenState extends ConsumerState controller: watchScrollController, slivers: [ const CupertinoSliverNavigationBar(), - CupertinoSliverRefreshControl( + CupertinoSliverRefreshControl( //TODO: Explore workaround to handle refresh on iOS. onRefresh: () => ref.refresh(liveStreamersProvider.future), ), SliverSafeArea( @@ -193,7 +203,7 @@ class _WatchTvWidget extends ConsumerWidget { header: Text('Lichess TV', style: Styles.sectionTitle), orientation: Side.white, fen: kEmptyFen, - errorMessage: 'Could not load Tv Stream', + errorMessage: 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error? ); }, loading: () => BoardPreview( From 76680cb821052e1834a756fae828dc8e37bf222e Mon Sep 17 00:00:00 2001 From: Raul Maza <54546499+rool78@users.noreply.github.com> Date: Wed, 5 Jul 2023 22:57:13 +0200 Subject: [PATCH 2/2] don't referesh streamers provider when no connection --- lib/src/ui/watch/watch_screen.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/ui/watch/watch_screen.dart b/lib/src/ui/watch/watch_screen.dart index 4cd3a29860..30a51a5b06 100644 --- a/lib/src/ui/watch/watch_screen.dart +++ b/lib/src/ui/watch/watch_screen.dart @@ -94,8 +94,10 @@ class _WatchScreenState extends ConsumerState controller: watchScrollController, slivers: [ const CupertinoSliverNavigationBar(), - CupertinoSliverRefreshControl( //TODO: Explore workaround to handle refresh on iOS. - onRefresh: () => ref.refresh(liveStreamersProvider.future), + CupertinoSliverRefreshControl( + onRefresh: () => isNowOnline + ? ref.refresh(liveStreamersProvider.future) + : Future.delayed(const Duration(seconds: 1)), ), SliverSafeArea( top: false, @@ -203,7 +205,8 @@ class _WatchTvWidget extends ConsumerWidget { header: Text('Lichess TV', style: Styles.sectionTitle), orientation: Side.white, fen: kEmptyFen, - errorMessage: 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error? + errorMessage: + 'Could not load TV Stream. Go online to watch TV Stream.', //TBD: Should we have different error messages depending on the error? ); }, loading: () => BoardPreview(