Skip to content
Open
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: 2 additions & 0 deletions android/app/.gradle/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Thu Oct 23 12:27:02 CDT 2025
java.home=C\:\\Program Files\\Android\\Android Studio\\jbr
8 changes: 8 additions & 0 deletions android/app/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Thu Oct 23 12:27:02 CDT 2025
sdk.dir=C\:\\Users\\Rocco\\AppData\\Local\\Android\\Sdk
12 changes: 12 additions & 0 deletions lib/src/model/over_the_board/over_the_board_clock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import 'package:lichess_mobile/src/model/common/time_increment.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'over_the_board_clock.freezed.dart';

part 'over_the_board_clock.g.dart';

@riverpod
class OverTheBoardClock extends _$OverTheBoardClock {
final Stopwatch _stopwatch = Stopwatch();
final int _timeToGive = 15;

Timer? _updateTimer;

Expand Down Expand Up @@ -44,6 +46,16 @@ class OverTheBoardClock extends _$OverTheBoardClock {
);
}

void giveTime(Side side) {
final timeToGiveDuration = Duration(seconds: _timeToGive);

if (side == Side.white) {
state = state.copyWith(whiteTimeLeft: state.whiteTimeLeft! + timeToGiveDuration);
} else {
state = state.copyWith(blackTimeLeft: state.blackTimeLeft! + timeToGiveDuration);
}
}

void setupClock(TimeIncrement timeIncrement) {
_stopwatch.stop();
_stopwatch.reset();
Expand Down
10 changes: 10 additions & 0 deletions lib/src/model/over_the_board/over_the_board_game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import 'package:lichess_mobile/src/model/game/game.dart';
import 'package:lichess_mobile/src/model/game/game_status.dart';
import 'package:lichess_mobile/src/model/game/material_diff.dart';
import 'package:lichess_mobile/src/model/game/over_the_board_game.dart';
import 'package:lichess_mobile/src/model/over_the_board/over_the_board_clock.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'over_the_board_game_controller.freezed.dart';

part 'over_the_board_game_controller.g.dart';

@riverpod
Expand Down Expand Up @@ -105,6 +107,10 @@ class OverTheBoardGameController extends _$OverTheBoardGameController {
);
}

void giveTime(Side side) {
ref.read(overTheBoardClockProvider.notifier).giveTime(side);
}

void goForward() {
if (state.canGoForward) {
state = state.copyWith(stepCursor: state.stepCursor + 1, promotionMove: null);
Expand Down Expand Up @@ -158,8 +164,11 @@ sealed class OverTheBoardGameState with _$OverTheBoardGameState {
}

Position get currentPosition => game.stepAt(stepCursor).position;

Side get turn => currentPosition.turn;

bool get finished => game.finished;

NormalMove? get lastMove =>
stepCursor > 0 ? NormalMove.fromUci(game.steps[stepCursor].sanMove!.move.uci) : null;

Expand All @@ -170,5 +179,6 @@ sealed class OverTheBoardGameState with _$OverTheBoardGameState {
List<String> get moves => game.steps.skip(1).map((e) => e.sanMove!.san).toList(growable: false);

bool get canGoForward => stepCursor < game.steps.length - 1;

bool get canGoBack => stepCursor > 0;
}
29 changes: 19 additions & 10 deletions lib/src/view/over_the_board/over_the_board_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,11 @@ class _BodyState extends ConsumerState<_Body> {
child: PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) async {
if (didPop) {
return;
}
if (didPop) return;

final navigator = Navigator.of(context);
final game = gameState.game;
if (game.abortable) {
return navigator.pop();
}
if (game.abortable) return navigator.pop();

if (game.playable) {
ref.read(overTheBoardClockProvider.notifier).pause();
Expand Down Expand Up @@ -235,7 +231,6 @@ class _BottomBar extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final gameState = ref.watch(overTheBoardGameControllerProvider);

final clock = ref.watch(overTheBoardClockProvider);

return BottomBar(
Expand Down Expand Up @@ -295,6 +290,8 @@ class _BottomBar extends ConsumerWidget {

Future<void> _showOtbGameMenu(BuildContext context, WidgetRef ref) {
final gameState = ref.read(overTheBoardGameControllerProvider);
final gameClock = ref.read(overTheBoardClockProvider);

return showAdaptiveActionSheet(
context: context,
actions: [
Expand Down Expand Up @@ -359,6 +356,21 @@ class _BottomBar extends ConsumerWidget {
);
},
),
if (!gameState.game.finished &&
gameClock.blackTimeLeft != null &&
gameClock.whiteTimeLeft != null)
BottomSheetAction(
makeLabel: (context) => Text(
context.l10n.giveNbSeconds(gameState.game.meta.clock?.moreTime?.inSeconds ?? 15),
),
onPressed: () {
if (gameState.turn == Side.white) {
ref.read(overTheBoardClockProvider.notifier).giveTime(Side.black);
} else {
ref.read(overTheBoardClockProvider.notifier).giveTime(Side.white);
}
},
),
],
);
}
Expand All @@ -368,9 +380,7 @@ class _Player extends ConsumerWidget {
const _Player({required this.clockKey, required this.side, required this.upsideDown});

final Side side;

final Key clockKey;

final bool upsideDown;

@override
Expand All @@ -395,7 +405,6 @@ class _Player extends ConsumerWidget {
timeLeft: Duration(milliseconds: max(0, clock.timeLeft(side)!.inMilliseconds)),
key: clockKey,
active: clock.activeClock == side,
// https://github.com/lichess-org/mobile/issues/785#issuecomment-2183903498
emergencyThreshold: Duration(
seconds: (clock.timeIncrement.time * 0.125).clamp(10, 60).toInt(),
),
Expand Down
Loading
Loading