-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc09d4
commit c5a3b59
Showing
6 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:app_links/app_links.dart' as lib_app_links; | ||
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/view/game/archived_game_screen.dart'; | ||
import 'package:lichess_mobile/src/view/puzzle/puzzle_screen.dart'; | ||
import 'package:lichess_mobile/src/view/study/study_screen.dart'; | ||
import 'package:lichess_mobile/src/view/game/game_screen.dart'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'app_links.g.dart'; | ||
|
||
final _logger = Logger('App Links'); | ||
|
||
WidgetBuilder? resolveAppLinkUri(Uri appLinkUri) { | ||
if (appLinkUri.pathSegments.length < 2 || appLinkUri.pathSegments[1].isEmpty) { | ||
return null; | ||
} | ||
|
||
final id = appLinkUri.pathSegments[1]; | ||
|
||
switch (appLinkUri.pathSegments[0]) { | ||
case 'study': | ||
return (context) => StudyScreen(id: StudyId(id)); | ||
case 'training': | ||
return (context) => 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 (context) => ArchivedGameScreen( | ||
gameId: gameId, | ||
// TODO preload game and check if it's our own game, then set orientation to our pov | ||
orientation: orientation == 'black' ? Side.black : Side.white, | ||
); | ||
} else { | ||
// TODO if it's not a game, it's a challenge | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// TODO doc | ||
@Riverpod(keepAlive: true) | ||
class AppLinks extends _$AppLinks { | ||
StreamSubscription<Uri>? _appLinkSubscription; | ||
|
||
@override | ||
Future<Uri?> build() { | ||
ref.onDispose(() { | ||
_appLinkSubscription?.cancel(); | ||
}); | ||
|
||
_appLinkSubscription?.cancel(); | ||
|
||
_appLinkSubscription = lib_app_links.AppLinks().uriLinkStream.listen((uri) { | ||
_logger.info('Received new app link: $uri'); | ||
state = AsyncValue.data(uri); | ||
}); | ||
|
||
return lib_app_links.AppLinks().getInitialLink(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters