diff --git a/lib/src/view/analysis/tree_view.dart b/lib/src/view/analysis/tree_view.dart index 54c55d7bce..b28e5fac69 100644 --- a/lib/src/view/analysis/tree_view.dart +++ b/lib/src/view/analysis/tree_view.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/analysis/analysis_controller.dart'; +import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart'; import 'package:lichess_mobile/src/model/analysis/opening_service.dart'; import 'package:lichess_mobile/src/model/common/chess.dart'; import 'package:lichess_mobile/src/utils/l10n_context.dart'; @@ -27,6 +28,10 @@ class AnalysisTreeView extends ConsumerWidget { final pgnRootComments = ref.watch( ctrlProvider.select((value) => value.requireValue.pgnRootComments), ); + final prefs = ref.watch(analysisPreferencesProvider); + // enable computer analysis takes effect here only if it's a lichess game + final enableComputerAnalysis = + !options.isLichessGameAnalysis || prefs.enableComputerAnalysis; return CustomScrollView( slivers: [ @@ -41,6 +46,10 @@ class AnalysisTreeView extends ConsumerWidget { currentPath: currentPath, pgnRootComments: pgnRootComments, notifier: ref.read(ctrlProvider.notifier), + shouldShowComputerVariations: enableComputerAnalysis, + shouldShowComments: enableComputerAnalysis && prefs.showPgnComments, + shouldShowAnnotations: + enableComputerAnalysis && prefs.showAnnotations, ), ), ], diff --git a/lib/src/view/study/study_settings.dart b/lib/src/view/study/study_settings.dart index 1064c5a962..d32239d040 100644 --- a/lib/src/view/study/study_settings.dart +++ b/lib/src/view/study/study_settings.dart @@ -135,13 +135,6 @@ class StudySettings extends ConsumerWidget { .read(analysisPreferencesProvider.notifier) .toggleAnnotations(), ), - SwitchSettingTile( - title: Text(context.l10n.mobileShowComments), - value: analysisPrefs.showPgnComments, - onChanged: (_) => ref - .read(analysisPreferencesProvider.notifier) - .togglePgnComments(), - ), SwitchSettingTile( title: Text(context.l10n.sound), value: isSoundEnabled, diff --git a/lib/src/view/study/study_tree_view.dart b/lib/src/view/study/study_tree_view.dart index 751b7c58af..031a2c599c 100644 --- a/lib/src/view/study/study_tree_view.dart +++ b/lib/src/view/study/study_tree_view.dart @@ -2,6 +2,7 @@ import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart'; import 'package:lichess_mobile/src/model/common/id.dart'; import 'package:lichess_mobile/src/model/common/node.dart'; import 'package:lichess_mobile/src/model/study/study_controller.dart'; @@ -36,6 +37,8 @@ class StudyTreeView extends ConsumerWidget { .select((value) => value.requireValue.pgnRootComments), ); + final analysisPrefs = ref.watch(analysisPreferencesProvider); + return CustomScrollView( slivers: [ SliverFillRemaining( @@ -49,6 +52,7 @@ class StudyTreeView extends ConsumerWidget { currentPath: currentPath, pgnRootComments: pgnRootComments, notifier: ref.read(studyControllerProvider(id).notifier), + shouldShowAnnotations: analysisPrefs.showAnnotations, ), ), ], diff --git a/lib/src/widgets/pgn.dart b/lib/src/widgets/pgn.dart index 0dff2207db..9ba8dafed8 100644 --- a/lib/src/widgets/pgn.dart +++ b/lib/src/widgets/pgn.dart @@ -6,7 +6,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/model/account/account_preferences.dart'; -import 'package:lichess_mobile/src/model/analysis/analysis_preferences.dart'; import 'package:lichess_mobile/src/model/common/node.dart'; import 'package:lichess_mobile/src/model/common/uci.dart'; import 'package:lichess_mobile/src/styles/lichess_colors.dart'; @@ -113,6 +112,9 @@ class DebouncedPgnTreeView extends ConsumerStatefulWidget { required this.currentPath, required this.pgnRootComments, required this.notifier, + this.shouldShowComputerVariations = true, + this.shouldShowAnnotations = true, + this.shouldShowComments = true, }); /// Root of the PGN tree to display @@ -127,6 +129,17 @@ class DebouncedPgnTreeView extends ConsumerStatefulWidget { /// Callbacks for when the user interacts with the tree view, e.g. selecting a different move or collapsing variations final PgnTreeNotifier notifier; + /// Whether to show analysis variations. + /// + /// Only applied to lichess game analysis. + final bool shouldShowComputerVariations; + + /// Whether to show NAG annotations like '!' and '??'. + final bool shouldShowAnnotations; + + /// Whether to show comments associated with the moves. + final bool shouldShowComments; + @override ConsumerState createState() => _DebouncedPgnTreeViewState(); @@ -195,32 +208,13 @@ class _DebouncedPgnTreeViewState extends ConsumerState { // using the fast replay buttons. @override Widget build(BuildContext context) { - final withComputerAnalysis = ref.watch( - analysisPreferencesProvider - .select((value) => value.enableComputerAnalysis), - ); - - final shouldShowComments = withComputerAnalysis && - ref.watch( - analysisPreferencesProvider.select( - (value) => value.showPgnComments, - ), - ); - - final shouldShowAnnotations = withComputerAnalysis && - ref.watch( - analysisPreferencesProvider.select( - (value) => value.showAnnotations, - ), - ); - return _PgnTreeView( root: widget.root, rootComments: widget.pgnRootComments, params: ( - withComputerAnalysis: withComputerAnalysis, - shouldShowAnnotations: shouldShowAnnotations, - shouldShowComments: shouldShowComments, + shouldShowComputerVariations: widget.shouldShowComputerVariations, + shouldShowAnnotations: widget.shouldShowAnnotations, + shouldShowComments: widget.shouldShowComments, currentMoveKey: currentMoveKey, pathToCurrentMove: pathToCurrentMove, notifier: widget.notifier, @@ -237,10 +231,8 @@ typedef _PgnTreeViewParams = ({ /// Path to the currently selected move in the tree. UciPath pathToCurrentMove, - /// Whether to show NAG, comments, and analysis variations. - /// - /// Takes precedence over [shouldShowAnnotations], and [shouldShowComments], - bool withComputerAnalysis, + /// Whether to show analysis variations. + bool shouldShowComputerVariations, /// Whether to show NAG annotations like '!' and '??'. bool shouldShowAnnotations, @@ -259,10 +251,10 @@ typedef _PgnTreeViewParams = ({ /// Filter node children when computer analysis is disabled IList _filteredChildren( ViewNode node, - bool withComputerAnalysis, + bool shouldShowComputerVariations, ) { return node.children - .where((c) => withComputerAnalysis || !c.isComputerVariation) + .where((c) => shouldShowComputerVariations || !c.isComputerVariation) .toIList(); } @@ -279,7 +271,7 @@ bool _displaySideLineAsInline(ViewBranch node, [int depth = 0]) { /// Returns whether this node has a sideline that should not be displayed inline. bool _hasNonInlineSideLine(ViewNode node, _PgnTreeViewParams params) { - final children = _filteredChildren(node, params.withComputerAnalysis); + final children = _filteredChildren(node, params.shouldShowComputerVariations); return children.length > 2 || (children.length == 2 && !_displaySideLineAsInline(children[1])); } @@ -429,8 +421,8 @@ class _PgnTreeViewState extends State<_PgnTreeView> { super.didUpdateWidget(oldWidget); _updateLines( fullRebuild: oldWidget.root != widget.root || - oldWidget.params.withComputerAnalysis != - widget.params.withComputerAnalysis || + oldWidget.params.shouldShowComputerVariations != + widget.params.shouldShowComputerVariations || oldWidget.params.shouldShowComments != widget.params.shouldShowComments || oldWidget.params.shouldShowAnnotations != @@ -695,14 +687,15 @@ class _MainLinePart extends ConsumerWidget { TextSpan( children: nodes .takeWhile( - (node) => _filteredChildren(node, params.withComputerAnalysis) - .isNotEmpty, + (node) => + _filteredChildren(node, params.shouldShowComputerVariations) + .isNotEmpty, ) .mapIndexed( (i, node) { final children = _filteredChildren( node, - params.withComputerAnalysis, + params.shouldShowComputerVariations, ); final mainlineNode = children.first; final moves = [ @@ -1248,7 +1241,6 @@ List _comments( text: comment, style: textStyle.copyWith( fontSize: textStyle.fontSize! - 2.0, - fontStyle: FontStyle.italic, ), ), ) diff --git a/pubspec.yaml b/pubspec.yaml index ddb2f85809..e0f3c21950 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: lichess_mobile description: Lichess mobile app V2 publish_to: "none" -version: 0.13.1+001301 # See README.md for details about versioning +version: 0.13.2+001302 # See README.md for details about versioning environment: sdk: ">=3.5.0 <4.0.0"