Skip to content
Merged
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
19 changes: 19 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="https" android:host="lichess.org" />

<data android:pathPattern="/training/....." />
<data android:pathPattern="/study/........" />

<data android:pathPattern="/storm" />
<data android:pathPattern="/streak" />

<!-- Either game or challenge -->
<data android:pathPattern="/........" />
<data android:pathPattern="/......../black" />
<data android:pathPattern="/......../white" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets:
riverpod_generator:
generate_for:
- lib/src/localizations.dart
- lib/src/theme.dart
- lib/src/model/**/*.dart
- lib/src/network/*.dart
- lib/src/db/*.dart
Expand Down
203 changes: 45 additions & 158 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemUiOverlayStyle;
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/l10n/l10n.dart';
import 'package:lichess_mobile/src/app_links.dart';
import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
import 'package:lichess_mobile/src/model/challenge/challenge_service.dart';
Expand All @@ -17,7 +16,8 @@ import 'package:lichess_mobile/src/network/connectivity.dart';
import 'package:lichess_mobile/src/network/http.dart';
import 'package:lichess_mobile/src/network/socket.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/color_palette.dart' show getSystemScheme;
import 'package:lichess_mobile/src/theme.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/utils/screen.dart';

/// Application initialization and main entry point.
Expand Down Expand Up @@ -119,166 +119,53 @@ class _AppState extends ConsumerState<Application> {
@override
Widget build(BuildContext context) {
final generalPrefs = ref.watch(generalPreferencesProvider);
final isTablet = isTabletOrLarger(context);
final (light: themeLight, dark: themeDark) = ref.watch(applicationThemeProvider);

final isIOS = Theme.of(context).platform == TargetPlatform.iOS;
final remainingHeight = estimateRemainingHeightLeftBoard(context);
final systemScheme = getSystemScheme();
final flexScheme =
generalPrefs.systemColors == true && systemScheme != null
? systemScheme
: FlexColor.espresso;
final themeLight = FlexThemeData.light(
colors: flexScheme.light,
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
blendLevel: 10,
cupertinoOverrideTheme: const CupertinoThemeData(applyThemeToAll: true),
appBarStyle: isIOS ? null : FlexAppBarStyle.scaffoldBackground,
);

// Defined in 2 steps to allow for a different scaffold background color.
final darkFlexScheme = FlexColorScheme.dark(
colors: flexScheme.dark,
surfaceMode: FlexSurfaceMode.highSurfaceLowScaffold,
blendLevel: 20,
);
final themeDark = FlexThemeData.dark(
colors: flexScheme.dark,
surfaceMode: FlexSurfaceMode.highSurfaceLowScaffold,
blendLevel: 20,
cupertinoOverrideTheme: const CupertinoThemeData(applyThemeToAll: true),
scaffoldBackground:
darkFlexScheme.scaffoldBackground != null
? lighten(darkFlexScheme.scaffoldBackground!, 0.05)
: null,
appBarStyle: isIOS ? null : FlexAppBarStyle.scaffoldBackground,
);

final floatingActionButtonTheme =
generalPrefs.systemColors
? null
: FloatingActionButtonThemeData(
backgroundColor: themeLight.colorScheme.primaryFixedDim,
foregroundColor: themeLight.colorScheme.onPrimaryFixed,
);

const cupertinoTitleColor = CupertinoDynamicColor.withBrightness(
color: Color(0xFF000000),
darkColor: Color(0xFFF5F5F5),
);

final lightCupertino = CupertinoThemeData(
primaryColor: themeLight.colorScheme.primary,
primaryContrastingColor: themeLight.colorScheme.onPrimary,
brightness: Brightness.light,
scaffoldBackgroundColor: themeLight.scaffoldBackgroundColor,
barBackgroundColor: themeLight.appBarTheme.backgroundColor?.withValues(
alpha: isTablet ? 1.0 : 0.9,
return MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: kSupportedLocales,
onGenerateTitle: (BuildContext context) => 'lichess.org',
locale: generalPrefs.locale,
theme: themeLight.copyWith(
navigationBarTheme: NavigationBarTheme.of(
context,
).copyWith(height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null),
),
textTheme: const CupertinoThemeData().textTheme.copyWith(
primaryColor: themeLight.colorScheme.primary,
textStyle: const CupertinoThemeData().textTheme.textStyle.copyWith(
color: themeLight.colorScheme.onSurface,
),
navTitleTextStyle: const CupertinoThemeData().textTheme.navTitleTextStyle.copyWith(
color: cupertinoTitleColor,
),
navLargeTitleTextStyle: const CupertinoThemeData().textTheme.navLargeTitleTextStyle
.copyWith(color: cupertinoTitleColor),
),
);

final darkCupertino = CupertinoThemeData(
primaryColor: themeDark.colorScheme.primaryFixed,
primaryContrastingColor: themeDark.colorScheme.onPrimaryFixed,
brightness: Brightness.dark,
scaffoldBackgroundColor: themeDark.scaffoldBackgroundColor,
barBackgroundColor: themeDark.appBarTheme.backgroundColor?.withValues(
alpha: isTablet ? 1.0 : 0.9,
),
textTheme: const CupertinoThemeData().textTheme.copyWith(
primaryColor: themeDark.colorScheme.primaryFixed,
textStyle: const CupertinoThemeData().textTheme.textStyle.copyWith(
color: themeDark.colorScheme.onSurface,
),
navTitleTextStyle: const CupertinoThemeData().textTheme.navTitleTextStyle.copyWith(
color: cupertinoTitleColor,
),
navLargeTitleTextStyle: const CupertinoThemeData().textTheme.navLargeTitleTextStyle
.copyWith(color: cupertinoTitleColor),
),
);

// The high blend theme is used only for the navigation bar in light mode.
final highBlendThemeLight = FlexThemeData.light(
colors: flexScheme.light,
surfaceMode: FlexSurfaceMode.highBackgroundLowScaffold,
blendLevel: 20,
);

return AnnotatedRegion<SystemUiOverlayStyle>(
value: FlexColorScheme.themedSystemNavigationBar(
context,
systemNavBarStyle: FlexSystemNavBarStyle.transparent,
),
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: kSupportedLocales,
onGenerateTitle: (BuildContext context) => 'lichess.org',
locale: generalPrefs.locale,
theme: themeLight.copyWith(
cupertinoOverrideTheme: lightCupertino,
splashFactory: isIOS ? NoSplash.splashFactory : null,
textTheme: isIOS ? Typography.blackCupertino : null,
listTileTheme: ListTileTheme.of(context).copyWith(
titleTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
subtitleTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? lightCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? Styles.cupertinoAnchorMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
backgroundColor: highBlendThemeLight.colorScheme.surface,
indicatorColor: darken(highBlendThemeLight.colorScheme.secondaryContainer, 0.05),
elevation: 3,
),
extensions: [lichessCustomColors.harmonized(themeLight.colorScheme)],
),
darkTheme: themeDark.copyWith(
cupertinoOverrideTheme: darkCupertino,
splashFactory: isIOS ? NoSplash.splashFactory : null,
textTheme: isIOS ? Typography.whiteCupertino : null,
listTileTheme: ListTileTheme.of(context).copyWith(
titleTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
subtitleTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
leadingAndTrailingTextStyle: isIOS ? darkCupertino.textTheme.textStyle : null,
),
menuTheme: isIOS ? Styles.cupertinoAnchorMenuTheme : null,
floatingActionButtonTheme: floatingActionButtonTheme,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
backgroundColor: themeDark.colorScheme.surface,
),
extensions: [lichessCustomColors.harmonized(themeDark.colorScheme)],
),
themeMode: switch (generalPrefs.themeMode) {
BackgroundThemeMode.light => ThemeMode.light,
BackgroundThemeMode.dark => ThemeMode.dark,
BackgroundThemeMode.system => ThemeMode.system,
},
builder:
isIOS
? (context, child) => IconTheme.merge(
data: IconThemeData(color: CupertinoTheme.of(context).textTheme.textStyle.color),
child: DefaultTextStyle.merge(
style: CupertinoTheme.of(context).textTheme.textStyle,
child: Material(color: Colors.transparent, child: child),
),
)
: null,
home: const BottomNavScaffold(),
navigatorObservers: [rootNavPageRouteObserver],
darkTheme: themeDark.copyWith(
navigationBarTheme: NavigationBarTheme.of(
context,
).copyWith(height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null),
extensions: [lichessCustomColors.harmonized(themeDark.colorScheme)],
),
themeMode:
generalPrefs.isForcedDarkMode
? ThemeMode.dark
: switch (generalPrefs.themeMode) {
BackgroundThemeMode.light => ThemeMode.light,
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,
onGenerateRoute:
(settings) =>
settings.name != null ? resolveAppLinkUri(context, Uri.parse(settings.name!)) : null,
onGenerateInitialRoutes: (initialRoute) {
final homeRoute = buildScreenRoute<void>(context, screen: const BottomNavScaffold());
return <Route<dynamic>?>[
homeRoute,
resolveAppLinkUri(context, Uri.parse(initialRoute)),
].nonNulls.toList(growable: false);
},
navigatorObservers: [rootNavPageRouteObserver],
);
}
}
51 changes: 51 additions & 0 deletions lib/src/app_links.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/widgets.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/game/archived_game_screen.dart';
import 'package:lichess_mobile/src/view/puzzle/puzzle_screen.dart';
import 'package:lichess_mobile/src/view/puzzle/storm_screen.dart';
import 'package:lichess_mobile/src/view/puzzle/streak_screen.dart';
import 'package:lichess_mobile/src/view/study/study_screen.dart';

Route<dynamic>? resolveAppLinkUri(BuildContext context, Uri appLinkUri) {
if (appLinkUri.pathSegments.length < 2 || appLinkUri.pathSegments[1].isEmpty) {
return null;
}

final id = appLinkUri.pathSegments[1];

switch (appLinkUri.pathSegments[0]) {
case 'streak':
return buildScreenRoute(context, screen: const StreakScreen());
case 'storm':
return buildScreenRoute(context, screen: const StormScreen());
case 'study':
return buildScreenRoute(context, screen: StudyScreen(id: StudyId(id)));
case 'training':
return buildScreenRoute(
context,
screen: PuzzleScreen(angle: PuzzleAngle.fromKey('mix'), puzzleId: PuzzleId(id)),
);
case _:
{
final gameId = GameId(appLinkUri.pathSegments[0]);
final orientation = appLinkUri.pathSegments.getOrNull(2);
if (gameId.isValid) {
return buildScreenRoute(
context,
screen: ArchivedGameScreen(
gameId: gameId,
orientation: orientation == 'black' ? Side.black : Side.white,
),
);
} else {
// TODO if it's not a game, it's a challenge.
// So we should show a accept/decline screen here.
return null;
}
}
}
}
11 changes: 3 additions & 8 deletions lib/src/model/challenge/challenge_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:lichess_mobile/src/model/notifications/notifications.dart';
import 'package:lichess_mobile/src/navigation.dart';
import 'package:lichess_mobile/src/network/socket.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/game/game_screen.dart';
import 'package:lichess_mobile/src/view/user/challenge_requests_screen.dart';
import 'package:lichess_mobile/src/widgets/adaptive_action_sheet.dart';
Expand Down Expand Up @@ -112,11 +111,10 @@ class ChallengeService {
rootNavState.popUntil((route) => route.isFirst);
}

pushPlatformRoute(
Navigator.of(
context,
rootNavigator: true,
builder: (BuildContext context) => GameScreen(initialGameId: fullId),
);
).push(GameScreen.buildRoute(context, initialGameId: fullId));

case 'decline':
final context = ref.read(currentNavigatorKeyProvider).currentContext;
Expand Down Expand Up @@ -144,10 +142,7 @@ class ChallengeService {
if (navState.canPop()) {
navState.popUntil((route) => route.isFirst);
}
pushPlatformRoute(
context,
builder: (BuildContext context) => const ChallengeRequestsScreen(),
);
Navigator.of(context).push(ChallengeRequestsScreen.buildRoute(context));
}
}
}
6 changes: 2 additions & 4 deletions lib/src/model/correspondence/correspondence_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'package:lichess_mobile/src/model/game/playable_game.dart';
import 'package:lichess_mobile/src/navigation.dart';
import 'package:lichess_mobile/src/network/http.dart';
import 'package:lichess_mobile/src/network/socket.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/game/game_screen.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
Expand Down Expand Up @@ -48,11 +47,10 @@ class CorrespondenceService {
rootNavState.popUntil((route) => route.isFirst);
}

pushPlatformRoute(
Navigator.of(
context,
rootNavigator: true,
builder: (_) => GameScreen(initialGameId: fullId),
);
).push(GameScreen.buildRoute(context, initialGameId: fullId));
}

/// Syncs offline correspondence games with the server.
Expand Down
Loading