Skip to content

Commit

Permalink
Merge upstream/main into broadcast-preview-eval to fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Feb 4, 2025
2 parents 5f32938 + 1057886 commit af84145
Show file tree
Hide file tree
Showing 33 changed files with 1,323 additions and 1,212 deletions.
6 changes: 3 additions & 3 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PODS:
- GoogleUtilities/Reachability (~> 8.0)
- GoogleUtilities/UserDefaults (~> 8.0)
- nanopb (~> 3.30910.0)
- FirebaseRemoteConfigInterop (11.6.0)
- FirebaseRemoteConfigInterop (11.8.0)
- FirebaseSessions (11.6.0):
- FirebaseCore (~> 11.6.0)
- FirebaseCoreExtension (~> 11.6.0)
Expand Down Expand Up @@ -238,7 +238,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/wakelock_plus/ios"

SPEC CHECKSUMS:
app_settings: 3507c575c2b18a462c99948f61d5de21d4420999
app_settings: 5127ae0678de1dcc19f2293271c51d37c89428b2
AppAuth: d4f13a8fe0baf391b2108511793e4b479691fb73
connectivity_plus: 2256d3e20624a7749ed21653aafe291a46446fee
cupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86c
Expand All @@ -253,7 +253,7 @@ SPEC CHECKSUMS:
FirebaseCrashlytics: b21c665fb50138766480bce73ebdb1aa30f7f300
FirebaseInstallations: efc0946fc756e4d22d8113f7c761948120322e8c
FirebaseMessaging: e1aca1fcc23e8b9eddb0e33f375ff90944623021
FirebaseRemoteConfigInterop: e75e348953352a000331eb77caf01e424248e176
FirebaseRemoteConfigInterop: 98897a64aa372eac3c5b3fe2816594ccfaac55ef
FirebaseSessions: 9529d14180868e29a8da164b3a729c036204918b
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_appauth: 914057fda669db5073d3ca9d94ea932e7df3c964
Expand Down
16 changes: 16 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ class _AppState extends ConsumerState<Application> {
blendLevel: 20,
);

const iosMenuTheme = MenuThemeData(
style: MenuStyle(
elevation: WidgetStatePropertyAll(0),
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: kCardBorderRadius)),
),
);

return AnnotatedRegion<SystemUiOverlayStyle>(
value: FlexColorScheme.themedSystemNavigationBar(
context,
Expand All @@ -234,6 +241,7 @@ class _AppState extends ConsumerState<Application> {
subtitleTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? iosMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
Expand All @@ -252,6 +260,7 @@ class _AppState extends ConsumerState<Application> {
subtitleTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? iosMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
Expand All @@ -264,6 +273,13 @@ class _AppState extends ConsumerState<Application> {
BackgroundThemeMode.dark => ThemeMode.dark,
BackgroundThemeMode.system => ThemeMode.system,
},
builder:
isIOS
? (context, child) => IconTheme.merge(
data: IconThemeData(color: CupertinoTheme.of(context).textTheme.textStyle.color),
child: Material(color: Colors.transparent, child: child),
)
: null,
home: const BottomNavScaffold(),
navigatorObservers: [rootNavPageRouteObserver],
),
Expand Down
16 changes: 15 additions & 1 deletion lib/src/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ Future<void> setupFirstLaunch() async {
final installedVersion = prefs.getString('installed_version');

// TODO remove this migration code after a few releases
if (installedVersion != null && Version.parse(installedVersion) < Version(0, 13, 14)) {
if (installedVersion != null && Version.parse(installedVersion) < Version(0, 14, 2)) {
_migrateThemeSettings();
_migrateHomePrefs();
}

if (installedVersion == null || Version.parse(installedVersion) != appVersion) {
Expand All @@ -54,6 +55,19 @@ Future<void> setupFirstLaunch() async {
}
}

Future<void> _migrateHomePrefs() async {
final prefs = LichessBinding.instance.sharedPreferences;
try {
final stored = prefs.getString(PrefCategory.home.storageKey);
if (stored == null) {
return;
}
await prefs.setString(PrefCategory.home.storageKey, jsonEncode(null));
} catch (e) {
_logger.warning('Failed to migrate home preferences: $e');
}
}

Future<void> _migrateThemeSettings() async {
if (getCorePalette() == null) {
return;
Expand Down
38 changes: 29 additions & 9 deletions lib/src/model/settings/board_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ String dragTargetKindLabel(DragTargetKind kind) => switch (kind) {

enum BoardBackgroundTheme {
/// The background theme is based on the chess board
board(20, 30),
board(30, 34),
blue(30, 34, FlexScheme.blue, 'Blue'),
indigo(30, 34, FlexScheme.indigo, 'indigo'),
green(30, 34, FlexScheme.jungle, 'Green'),
Expand All @@ -420,12 +420,15 @@ enum BoardBackgroundTheme {
purple(30, 34, FlexScheme.purpleM3, 'Purple'),
sepia(28, 34, FlexScheme.sepia, 'Sepia'),

dimRed(16, 20, FlexScheme.redWine, 'Dim Red'),
dimPurple(16, 20, FlexScheme.purpleM3, 'Dim Purple'),
dimIndigo(16, 20, FlexScheme.indigo, 'Dim indigo'),
dimGold(16, 20, FlexScheme.gold, 'Dim Gold'),
dimBlue(16, 20, FlexScheme.blue, 'Dim Blue'),
dimGreen(16, 20, FlexScheme.greenM3, 'Dim Green');
dimBoard(20, 24),
dimBlue(20, 24, FlexScheme.blue, 'Blue dim'),
dimIndigo(20, 24, FlexScheme.indigo, 'Indigo dim'),
dimGreen(20, 24, FlexScheme.jungle, 'Green dim'),
dimBrown(20, 24, FlexScheme.purpleBrown, 'Brown dim'),
dimGold(20, 24, FlexScheme.gold, 'Gold dim'),
dimRed(24, 24, FlexScheme.redWine, 'Red dim'),
dimPurple(20, 24, FlexScheme.purpleM3, 'Purple dim'),
dimSepia(18, 24, FlexScheme.sepia, 'Sepia dim');

final int lightBlend;
final int darkBlend;
Expand All @@ -434,10 +437,15 @@ enum BoardBackgroundTheme {

const BoardBackgroundTheme(this.lightBlend, this.darkBlend, [this.scheme, this._label]);

String label(AppLocalizations l10n) => this == BoardBackgroundTheme.board ? l10n.board : _label!;
String label(AppLocalizations l10n) =>
this == BoardBackgroundTheme.board || this == BoardBackgroundTheme.dimBoard
? l10n.board
: _label!;

FlexSchemeData getFlexScheme(BoardTheme boardTheme) =>
this == BoardBackgroundTheme.board ? boardTheme.flexScheme : scheme!.data;
this == BoardBackgroundTheme.board || this == BoardBackgroundTheme.dimBoard
? boardTheme.flexScheme
: scheme!.data;
}

@freezed
Expand All @@ -451,6 +459,10 @@ class BoardBackgroundImage with _$BoardBackgroundImage {
required bool isBlurred,
required ColorScheme darkColors,
required double meanLuminance,
required double width,
required double height,
required double viewportWidth,
required double viewportHeight,
}) = _BoardBackgroundImage;

static Color getFilterColor(ColorScheme scheme, double meanLuminance) =>
Expand Down Expand Up @@ -518,6 +530,10 @@ class BoardBackgroundImageConverter
isBlurred: json['isBlurred'] as bool,
darkColors: darkColors,
meanLuminance: json['meanLuminance'] as double,
width: json['width'] as double,
height: json['height'] as double,
viewportWidth: json['viewportWidth'] as double,
viewportHeight: json['viewportHeight'] as double,
);
}

Expand Down Expand Up @@ -549,6 +565,10 @@ class BoardBackgroundImageConverter
'isBlurred': object.isBlurred,
...darkColors,
'meanLuminance': object.meanLuminance,
'width': object.width,
'height': object.height,
'viewportWidth': object.viewportWidth,
'viewportHeight': object.viewportHeight,
};
}
}
82 changes: 77 additions & 5 deletions lib/src/model/settings/home_preferences.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:lichess_mobile/src/model/settings/preferences_storage.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand All @@ -24,24 +25,95 @@ class HomePreferences extends _$HomePreferences with PreferencesStorage<HomePref
}

Future<void> toggleWidget(EnabledWidget widget) {
if (widget == EnabledWidget.ongoingGames) {
return Future.value();
}
final newState = state.copyWith(
enabledWidgets:
state.enabledWidgets.contains(widget)
? state.enabledWidgets.difference({widget})
: state.enabledWidgets.union({widget}),
? state.enabledWidgets.remove(widget)
: state.enabledWidgets.add(widget),
);
return save(newState);
}

Future<void> moveToTop(EnabledWidget widget) {
final newState = state.copyWith(
enabledWidgets: [widget, ...state.enabledWidgets.where((w) => w != widget)].lock,
);
return save(newState);
}

Future<void> moveToBottom(EnabledWidget widget) {
final newState = state.copyWith(
enabledWidgets: [...state.enabledWidgets.where((w) => w != widget), widget].lock,
);
return save(newState);
}

Future<void> moveUp(EnabledWidget widget) {
final index = state.enabledWidgets.indexOf(widget);
if (index == 0) {
return moveToBottom(widget);
}
final newState = state.copyWith(
enabledWidgets:
[
...state.enabledWidgets.sublist(0, index - 1),
widget,
state.enabledWidgets[index - 1],
...state.enabledWidgets.sublist(index + 1),
].lock,
);
return save(newState);
}

Future<void> moveDown(EnabledWidget widget) {
final index = state.enabledWidgets.indexOf(widget);
if (index == state.enabledWidgets.length - 1) {
return moveToTop(widget);
}
final newState = state.copyWith(
enabledWidgets:
[
...state.enabledWidgets.sublist(0, index),
state.enabledWidgets[index + 1],
widget,
...state.enabledWidgets.sublist(index + 2),
].lock,
);
return save(newState);
}
}

enum EnabledWidget { hello, perfCards, quickPairing }
enum EnabledWidget {
ongoingGames,
hello,
perfCards,
quickPairing,
recentGames;

String get label => switch (this) {
EnabledWidget.ongoingGames => 'Ongoing Games',
EnabledWidget.hello => 'Hello',
EnabledWidget.perfCards => 'Performance Cards',
EnabledWidget.quickPairing => 'Quick Pairing',
EnabledWidget.recentGames => 'Recent Games',
};
}

@Freezed(fromJson: true, toJson: true)
class HomePrefs with _$HomePrefs implements Serializable {
const factory HomePrefs({required Set<EnabledWidget> enabledWidgets}) = _HomePrefs;
const factory HomePrefs({required IList<EnabledWidget> enabledWidgets}) = _HomePrefs;

static const defaults = HomePrefs(
enabledWidgets: {EnabledWidget.hello, EnabledWidget.perfCards, EnabledWidget.quickPairing},
enabledWidgets: IListConst([
EnabledWidget.ongoingGames,
EnabledWidget.hello,
EnabledWidget.perfCards,
EnabledWidget.quickPairing,
EnabledWidget.recentGames,
]),
);

factory HomePrefs.fromJson(Map<String, dynamic> json) {
Expand Down
29 changes: 13 additions & 16 deletions lib/src/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:lichess_mobile/src/view/puzzle/puzzle_tab_screen.dart';
import 'package:lichess_mobile/src/view/settings/settings_tab_screen.dart';
import 'package:lichess_mobile/src/view/tools/tools_tab_screen.dart';
import 'package:lichess_mobile/src/view/watch/watch_tab_screen.dart';
import 'package:lichess_mobile/src/widgets/cupertino.dart';
import 'package:lichess_mobile/src/widgets/feedback.dart';

enum BottomTab {
Expand Down Expand Up @@ -177,21 +176,19 @@ class BottomNavScaffold extends ConsumerWidget {
);
case TargetPlatform.iOS:
final isOnline = ref.watch(connectivityChangesProvider).valueOrNull?.isOnline ?? true;
return CupertinoMaterialWrapper(
child: CupertinoTabScaffold(
tabBuilder: _iOSTabBuilder,
controller: _cupertinoTabController,
tabBar: CupertinoTabBar(
currentIndex: currentTab.index,
items: [
for (final tab in BottomTab.values)
BottomNavigationBarItem(
icon: Icon(tab == currentTab ? tab.activeIcon : tab.icon),
label: tab.label(context.l10n),
),
],
onTap: (i) => _onItemTapped(ref, i, isOnline: isOnline),
),
return CupertinoTabScaffold(
tabBuilder: _iOSTabBuilder,
controller: _cupertinoTabController,
tabBar: CupertinoTabBar(
currentIndex: currentTab.index,
items: [
for (final tab in BottomTab.values)
BottomNavigationBarItem(
icon: Icon(tab == currentTab ? tab.activeIcon : tab.icon),
label: tab.label(context.l10n),
),
],
onTap: (i) => _onItemTapped(ref, i, isOnline: isOnline),
),
);
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AnalysisScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BackgroundThemeWidget(
return FullScreenBackgroundTheme(
child: _AnalysisScreen(options: options, enableDrawingShapes: enableDrawingShapes),
);
}
Expand Down
Loading

0 comments on commit af84145

Please sign in to comment.