Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable android refresh when no connectivity #226

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/ui/watch/tv_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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?
);
},
),
Expand Down
17 changes: 15 additions & 2 deletions lib/src/ui/watch/watch_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,8 +34,15 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
with RouteAware, WidgetsBindingObserver {
final _androidRefreshKey = GlobalKey<RefreshIndicatorState>();

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,
Expand All @@ -49,6 +58,7 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
body: RefreshIndicator(
key: _androidRefreshKey,
onRefresh: () => ref.refresh(liveStreamersProvider.future),
notificationPredicate: (_) => isNowOnline,
child: SafeArea(
child: OrientationBuilder(
builder: (context, orientation) {
Expand Down Expand Up @@ -85,7 +95,9 @@ class _WatchScreenState extends ConsumerState<WatchScreen>
slivers: [
const CupertinoSliverNavigationBar(),
CupertinoSliverRefreshControl(
onRefresh: () => ref.refresh(liveStreamersProvider.future),
onRefresh: () => isNowOnline
? ref.refresh(liveStreamersProvider.future)
: Future.delayed(const Duration(seconds: 1)),
),
SliverSafeArea(
top: false,
Expand Down Expand Up @@ -193,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',
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(
Expand Down