diff --git a/lib/src/model/settings/board_preferences.dart b/lib/src/model/settings/board_preferences.dart index 05d9dafd35..dbc35fa5d8 100644 --- a/lib/src/model/settings/board_preferences.dart +++ b/lib/src/model/settings/board_preferences.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:chessground/chessground.dart' hide BoardTheme; -import 'package:flutter/material.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/db/shared_preferences.dart'; import 'package:lichess_mobile/src/utils/color_palette.dart'; @@ -200,40 +199,6 @@ enum BoardTheme { /// Get the [BoardColorScheme] based on system colors on Android 12+. /// /// If the system colors are not available, the default brown theme is used. - static BoardColorScheme get systemColors { - final corePalette = getCorePalette(); - if (corePalette == null) { - return brown.colors; - } - final darkSquare = Color(corePalette.secondary.get(60)); - final lightSquare = Color(corePalette.primary.get(95)); - return BoardColorScheme( - darkSquare: darkSquare, - lightSquare: lightSquare, - background: SolidColorBackground( - lightSquare: lightSquare, - darkSquare: darkSquare, - ), - whiteCoordBackground: SolidColorBackground( - lightSquare: lightSquare, - darkSquare: darkSquare, - coordinates: true, - ), - blackCoordBackground: SolidColorBackground( - lightSquare: lightSquare, - darkSquare: darkSquare, - coordinates: true, - orientation: Side.black, - ), - lastMove: HighlightDetails( - solidColor: Color(corePalette.tertiary.get(80)).withOpacity(0.8), - ), - selected: HighlightDetails( - solidColor: Color(corePalette.tertiary.get(80)).withOpacity(0.6), - ), - validMoves: Color(corePalette.neutral.get(60)).withOpacity(0.45), - validPremoves: - Color(corePalette.neutralVariant.get(60)).withOpacity(0.45), - ); - } + static BoardColorScheme get systemColors => + getBoardColorScheme() ?? BoardColorScheme.brown; } diff --git a/lib/src/utils/color_palette.dart b/lib/src/utils/color_palette.dart index a8f06039b2..e705cb2c8d 100644 --- a/lib/src/utils/color_palette.dart +++ b/lib/src/utils/color_palette.dart @@ -1,12 +1,54 @@ +import 'dart:ui'; + +import 'package:chessground/chessground.dart'; import 'package:material_color_utilities/material_color_utilities.dart'; CorePalette? _corePalette; +BoardColorScheme? _boardColorScheme; + void setCorePalette(CorePalette? palette) { _corePalette = palette; + + if (palette != null) { + final darkSquare = Color(palette.secondary.get(60)); + final lightSquare = Color(palette.primary.get(95)); + _boardColorScheme = BoardColorScheme( + darkSquare: darkSquare, + lightSquare: lightSquare, + background: SolidColorBackground( + lightSquare: lightSquare, + darkSquare: darkSquare, + ), + whiteCoordBackground: SolidColorBackground( + lightSquare: lightSquare, + darkSquare: darkSquare, + coordinates: true, + ), + blackCoordBackground: SolidColorBackground( + lightSquare: lightSquare, + darkSquare: darkSquare, + coordinates: true, + orientation: Side.black, + ), + lastMove: HighlightDetails( + solidColor: Color(palette.tertiary.get(80)).withOpacity(0.8), + ), + selected: HighlightDetails( + solidColor: Color(palette.tertiary.get(80)).withOpacity(0.6), + ), + validMoves: Color(palette.tertiary.get(30)).withOpacity(0.30), + validPremoves: Color(palette.tertiary.get(30)).withOpacity(0.30), + ); + } } /// Get the core palette if available (android 12+ only). CorePalette? getCorePalette() { return _corePalette; } + +/// Get the board colors based on the core palette, if available (android 12+). +BoardColorScheme? getBoardColorScheme() { + return _boardColorScheme; +}