Skip to content
Merged
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
11 changes: 9 additions & 2 deletions lib/src/model/account/account_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AccountService {

ProviderSubscription<AsyncValue<User?>>? _accountProviderSubscription;
StreamSubscription<(NotificationResponse, LocalNotification)>? _notificationResponseSubscription;
Timer? _refreshTimer;

final Ref _ref;

Expand All @@ -49,7 +50,12 @@ class AccountService {
if (playban != null && lastPlaybanNotificationDate != playban.date) {
_savePlaybanNotificationDate(playban.date);
_ref.read(notificationServiceProvider).show(PlaybanNotification(playban));
_refreshTimer?.cancel();
_refreshTimer = Timer(playban.duration, () {
_ref.invalidate(accountProvider);
});
} else if (playban == null && lastPlaybanNotificationDate != null) {
_refreshTimer?.cancel();
_ref
.read(notificationServiceProvider)
.cancel(lastPlaybanNotificationDate.toIso8601String().hashCode);
Expand All @@ -61,7 +67,7 @@ class AccountService {
final (_, notification) = data;
switch (notification) {
case PlaybanNotification(:final playban):
_onPlaybanNotificationResponse(playban);
showPlaybanDialog(playban);
case _:
break;
}
Expand All @@ -77,11 +83,12 @@ class AccountService {
}

void dispose() {
_refreshTimer?.cancel();
_accountProviderSubscription?.close();
_notificationResponseSubscription?.cancel();
}

Future<void> _onPlaybanNotificationResponse(TemporaryBan playban) async {
Future<void> showPlaybanDialog(TemporaryBan playban) async {
final context = _ref.read(currentNavigatorKeyProvider).currentContext;
if (context == null || !context.mounted) return;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/lobby/game_seek.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GameSeek with _$GameSeek {
(int, int)? ratingDelta,
}) = _GameSeek;

/// Construct a game seek from a predefined time control.
/// Construct a fast pairing game seek from a predefined time control.
factory GameSeek.fastPairing(TimeIncrement setup, AuthSessionState? session) {
return GameSeek(
clock: (Duration(seconds: setup.time), Duration(seconds: setup.increment)),
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/notifications/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class PlaybanNotification extends LocalNotification {
'playban',
importance: Importance.max,
priority: Priority.max,
autoCancel: false,
),
iOS: DarwinNotificationDetails(threadIdentifier: channelId),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/home/home_tab_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import 'package:lichess_mobile/src/view/correspondence/offline_correspondence_ga
import 'package:lichess_mobile/src/view/game/game_screen.dart';
import 'package:lichess_mobile/src/view/game/offline_correspondence_games_screen.dart';
import 'package:lichess_mobile/src/view/home/games_carousel.dart';
import 'package:lichess_mobile/src/view/play/create_game_options.dart';
import 'package:lichess_mobile/src/view/play/ongoing_games_screen.dart';
import 'package:lichess_mobile/src/view/play/play_bottom_sheet.dart';
import 'package:lichess_mobile/src/view/play/play_menu.dart';
import 'package:lichess_mobile/src/view/play/quick_game_matrix.dart';
import 'package:lichess_mobile/src/view/tournament/tournament_list_screen.dart';
import 'package:lichess_mobile/src/view/user/challenge_requests_screen.dart';
Expand Down Expand Up @@ -480,7 +480,7 @@ class _TabletCreateAGameSection extends StatelessWidget {
shouldShow: true,
child: Padding(padding: Styles.bodySectionPadding, child: QuickGameMatrix()),
),
CreateGameOptions(),
PlayMenu(),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
import 'package:lichess_mobile/src/model/auth/auth_session.dart';
import 'package:lichess_mobile/src/model/account/account_service.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/lobby/game_seek.dart';
import 'package:lichess_mobile/src/model/lobby/game_setup_preferences.dart';
Expand All @@ -13,15 +13,13 @@ import 'package:lichess_mobile/src/view/play/time_control_modal.dart';
import 'package:lichess_mobile/src/widgets/adaptive_bottom_sheet.dart';
import 'package:lichess_mobile/src/widgets/adaptive_choice_picker.dart';

class QuickGameWidget extends ConsumerWidget {
const QuickGameWidget();
class CreateGameWidget extends ConsumerWidget {
const CreateGameWidget();

@override
Widget build(BuildContext context, WidgetRef ref) {
final playPrefs = ref.watch(gameSetupPreferencesProvider);
final session = ref.watch(authSessionProvider);
final isOnline = ref.watch(connectivityChangesProvider).valueOrNull?.isOnline ?? false;
final isPlayban = ref.watch(accountProvider).valueOrNull?.playban != null;
final account = ref.watch(accountProvider).valueOrNull;
final userPerf = account?.perfs[playPrefs.realTimePerf];
final canUseRatingRange = userPerf != null && userPerf.provisional != true;
Expand Down Expand Up @@ -157,15 +155,19 @@ class QuickGameWidget extends ConsumerWidget {
),
FilledButton(
onPressed:
isOnline && !isPlayban
isOnline
? () {
// Pops the play bottom sheet
Navigator.of(context).popUntil((route) => route is! ModalBottomSheetRoute);

final playban = ref.read(accountProvider).valueOrNull?.playban;
if (playban != null) {
ref.read(accountServiceProvider).showPlaybanDialog(playban);
return;
}

Navigator.of(context, rootNavigator: true).push(
GameScreen.buildRoute(
context,
seek: GameSeek.fastPairing(playPrefs.timeIncrement, session),
),
GameScreen.buildRoute(context, seek: GameSeek.custom(playPrefs, account)),
);
}
: null,
Expand Down
17 changes: 4 additions & 13 deletions lib/src/view/play/play_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/play/create_game_options.dart';
import 'package:lichess_mobile/src/view/play/playban.dart';
import 'package:lichess_mobile/src/view/play/play_menu.dart';
import 'package:lichess_mobile/src/widgets/adaptive_bottom_sheet.dart';
import 'package:material_symbols_icons/symbols.dart';

Expand Down Expand Up @@ -32,15 +29,9 @@ class PlayBottomSheet extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final playban = ref.watch(accountProvider).valueOrNull?.playban;

return BottomSheetScrollableContainer(
padding: const EdgeInsets.symmetric(vertical: 16.0),
children: [
if (playban != null)
Padding(padding: Styles.bodySectionPadding, child: PlaybanMessage(playban: playban)),
const CreateGameOptions(),
],
return const BottomSheetScrollableContainer(
padding: EdgeInsets.symmetric(vertical: 16.0),
children: [PlayMenu()],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/over_the_board/over_the_board_screen.dart';
import 'package:lichess_mobile/src/view/play/correspondence_challenges_screen.dart';
import 'package:lichess_mobile/src/view/play/quick_game_widget.dart';
import 'package:lichess_mobile/src/view/play/create_game_widget.dart';
import 'package:lichess_mobile/src/view/tournament/tournament_list_screen.dart';
import 'package:lichess_mobile/src/widgets/list.dart';

/// A widget that displays the options for creating a game.
class CreateGameOptions extends ConsumerWidget {
const CreateGameOptions();
class PlayMenu extends ConsumerWidget {
const PlayMenu();

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand All @@ -22,7 +21,7 @@ class CreateGameOptions extends ConsumerWidget {
children: [
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: QuickGameWidget(),
child: CreateGameWidget(),
),
_Section(
children: [
Expand Down