Skip to content

Commit

Permalink
Merge branch 'Jimima-1098-feature-change-clock-position'
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Nov 20, 2024
2 parents 73662b1 + 277ef37 commit 88a1242
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 18 deletions.
19 changes: 19 additions & 0 deletions lib/src/model/settings/board_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class BoardPreferences extends _$BoardPreferences
);
}

Future<void> setClockPosition(ClockPosition clockPosition) {
return save(
state.copyWith(clockPosition: clockPosition),
);
}

Future<void> toggleEnableShapeDrawings() {
return save(
state.copyWith(enableShapeDrawings: !state.enableShapeDrawings),
Expand All @@ -115,6 +121,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable {
required bool coordinates,
required bool pieceAnimation,
required bool showMaterialDifference,
required ClockPosition clockPosition,
@JsonKey(
defaultValue: PieceShiftMethod.either,
unknownEnumValue: PieceShiftMethod.either,
Expand Down Expand Up @@ -144,6 +151,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable {
coordinates: true,
pieceAnimation: true,
showMaterialDifference: true,
clockPosition: ClockPosition.right,
pieceShiftMethod: PieceShiftMethod.either,
enableShapeDrawings: true,
magnifyDraggedPiece: true,
Expand Down Expand Up @@ -309,6 +317,17 @@ enum BoardTheme {
);
}

enum ClockPosition {
left,
right;

// TODO: l10n
String get label => switch (this) {
ClockPosition.left => 'Left',
ClockPosition.right => 'Right',
};
}

String dragTargetKindLabel(DragTargetKind kind) => switch (kind) {
DragTargetKind.circle => 'Circle',
DragTargetKind.square => 'Square',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/view/game/game_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class GameBody extends ConsumerWidget {
: null,
mePlaying: youAre == Side.black,
zenMode: gameState.isZenModeActive,
clockPosition: boardPreferences.clockPosition,
confirmMoveCallbacks:
youAre == Side.black && gameState.moveToConfirm != null
? (
Expand Down Expand Up @@ -181,6 +182,7 @@ class GameBody extends ConsumerWidget {
: null,
mePlaying: youAre == Side.white,
zenMode: gameState.isZenModeActive,
clockPosition: boardPreferences.clockPosition,
confirmMoveCallbacks:
youAre == Side.white && gameState.moveToConfirm != null
? (
Expand Down
3 changes: 3 additions & 0 deletions lib/src/view/game/game_common_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class GameAppBar extends ConsumerWidget {
isDismissible: true,
isScrollControlled: true,
showDragHandle: true,
constraints: BoxConstraints(
minHeight: MediaQuery.sizeOf(context).height * 0.5,
),
builder: (_) => GameSettings(id: id!),
),
semanticsLabel: context.l10n.settingsSettings,
Expand Down
15 changes: 13 additions & 2 deletions lib/src/view/game/game_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/model/common/service/sound_service.dart';
import 'package:lichess_mobile/src/model/game/material_diff.dart';
import 'package:lichess_mobile/src/model/game/player.dart';
import 'package:lichess_mobile/src/model/settings/board_preferences.dart';
import 'package:lichess_mobile/src/styles/lichess_colors.dart';
import 'package:lichess_mobile/src/styles/lichess_icons.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
Expand All @@ -32,6 +33,7 @@ class GamePlayer extends StatelessWidget {
this.shouldLinkToUserProfile = true,
this.mePlaying = false,
this.zenMode = false,
this.clockPosition = ClockPosition.right,
super.key,
});

Expand All @@ -45,6 +47,7 @@ class GamePlayer extends StatelessWidget {
final bool shouldLinkToUserProfile;
final bool mePlaying;
final bool zenMode;
final ClockPosition clockPosition;

/// Time left for the player to move at the start of the game.
final Duration? timeToMove;
Expand All @@ -61,7 +64,9 @@ class GamePlayer extends StatelessWidget {
children: [
if (!zenMode)
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: clockPosition == ClockPosition.right
? MainAxisAlignment.start
: MainAxisAlignment.end,
children: [
if (player.user != null) ...[
Icon(
Expand Down Expand Up @@ -144,6 +149,9 @@ class GamePlayer extends StatelessWidget {
MoveExpiration(timeToMove: timeToMove!, mePlaying: mePlaying)
else if (materialDiff != null)
Row(
mainAxisAlignment: clockPosition == ClockPosition.right
? MainAxisAlignment.start
: MainAxisAlignment.end,
children: [
for (final role in Role.values)
for (int i = 0; i < materialDiff!.pieces[role]!; i++)
Expand Down Expand Up @@ -174,6 +182,8 @@ class GamePlayer extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (clock != null && clockPosition == ClockPosition.left)
Flexible(flex: 3, child: clock!),
if (mePlaying && confirmMoveCallbacks != null)
Expanded(
flex: 7,
Expand Down Expand Up @@ -209,7 +219,8 @@ class GamePlayer extends StatelessWidget {
: playerWidget,
),
),
if (clock != null) Flexible(flex: 3, child: clock!),
if (clock != null && clockPosition == ClockPosition.right)
Flexible(flex: 3, child: clock!),
],
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/view/game/game_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class GameSettings extends ConsumerWidget {
onTap: () {
pushPlatformRoute(
context,
fullscreenDialog: true,
screen: const BoardSettingsScreen(),
);
},
Expand Down
1 change: 1 addition & 0 deletions lib/src/view/puzzle/puzzle_settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PuzzleSettingsScreen extends ConsumerWidget {
onTap: () {
pushPlatformRoute(
context,
fullscreenDialog: true,
screen: const BoardSettingsScreen(),
);
},
Expand Down
85 changes: 69 additions & 16 deletions lib/src/view/settings/board_settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ class _Body extends ConsumerWidget {
.togglePieceAnimation();
},
),
SwitchSettingTile(
// TODO: Add l10n
title: const Text('Shape drawing'),
subtitle: const Text(
// TODO: translate
'Draw shapes using two fingers: maintain one finger on an empty square and drag another finger to draw a shape.',
maxLines: 5,
textAlign: TextAlign.justify,
),
value: boardPrefs.enableShapeDrawings,
onChanged: (value) {
ref
.read(boardPreferencesProvider.notifier)
.toggleEnableShapeDrawings();
},
),
],
),
ListSection(
Expand Down Expand Up @@ -183,6 +199,30 @@ class _Body extends ConsumerWidget {
: const SizedBox.shrink(),
orElse: () => const SizedBox.shrink(),
),
SettingsListTile(
//TODO Add l10n
settingsLabel: const Text('Clock position'),
settingsValue: boardPrefs.clockPosition.label,
onTap: () {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: ClockPosition.values,
selectedItem: boardPrefs.clockPosition,
labelBuilder: (t) => Text(t.label),
onSelectedItemChanged: (ClockPosition? value) => ref
.read(boardPreferencesProvider.notifier)
.setClockPosition(value ?? ClockPosition.right),
);
} else {
pushPlatformRoute(
context,
title: 'Clock position',
builder: (context) => const BoardClockPositionScreen(),
);
}
},
),
SwitchSettingTile(
title: Text(
context.l10n.preferencesPieceDestinations,
Expand Down Expand Up @@ -216,22 +256,6 @@ class _Body extends ConsumerWidget {
.toggleShowMaterialDifference();
},
),
SwitchSettingTile(
// TODO: Add l10n
title: const Text('Shape drawing'),
subtitle: const Text(
// TODO: translate
'Draw shapes using two fingers: maintain one finger on an empty square and drag another finger to draw a shape.',
maxLines: 5,
textAlign: TextAlign.justify,
),
value: boardPrefs.enableShapeDrawings,
onChanged: (value) {
ref
.read(boardPreferencesProvider.notifier)
.toggleEnableShapeDrawings();
},
),
],
),
],
Expand Down Expand Up @@ -276,6 +300,35 @@ class PieceShiftMethodSettingsScreen extends ConsumerWidget {
}
}

class BoardClockPositionScreen extends ConsumerWidget {
const BoardClockPositionScreen({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final clockPosition = ref.watch(
boardPreferencesProvider.select((state) => state.clockPosition),
);
void onChanged(ClockPosition? value) => ref
.read(boardPreferencesProvider.notifier)
.setClockPosition(value ?? ClockPosition.right);
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(),
child: SafeArea(
child: ListView(
children: [
ChoicePicker(
choices: ClockPosition.values,
selectedItem: clockPosition,
titleBuilder: (t) => Text(t.label),
onSelectedItemChanged: onChanged,
),
],
),
),
);
}
}

class DragTargetKindSettingsScreen extends ConsumerWidget {
const DragTargetKindSettingsScreen({super.key});

Expand Down

0 comments on commit 88a1242

Please sign in to comment.