From cf17603b0333ceb7627ddfc00233f798d431d315 Mon Sep 17 00:00:00 2001 From: kodjomoustapha <107993382+kodjodevf@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:05:06 +0100 Subject: [PATCH] Fix Reader Keyboad listener --- l10n.yaml | 2 +- lib/modules/anime/anime_player_view.dart | 16 ++++- lib/modules/manga/reader/reader_view.dart | 87 +++++++++++++++-------- pubspec.lock | 2 +- pubspec.yaml | 2 +- 5 files changed, 74 insertions(+), 35 deletions(-) diff --git a/l10n.yaml b/l10n.yaml index 539efd3f..6754e313 100644 --- a/l10n.yaml +++ b/l10n.yaml @@ -1,4 +1,4 @@ arb-dir: lib/l10n template-arb-file: app_en.arb -untranslated-messages-file: untranslated_messages.txt +# untranslated-messages-file: untranslated_messages.txt output-localization-file: app_localizations.dart \ No newline at end of file diff --git a/lib/modules/anime/anime_player_view.dart b/lib/modules/anime/anime_player_view.dart index 47aaa2a4..117eae3b 100644 --- a/lib/modules/anime/anime_player_view.dart +++ b/lib/modules/anime/anime_player_view.dart @@ -792,6 +792,9 @@ class _AnimeStreamPageState extends riv.ConsumerState { if (hasPrevEpisode) IconButton( onPressed: () { + if (isFullScreen) { + _key.currentState?.exitFullscreen(); + } pushReplacementMangaReaderView( context: context, chapter: _streamController.getPrevEpisode()); @@ -805,6 +808,9 @@ class _AnimeStreamPageState extends riv.ConsumerState { if (hasNextEpisode) IconButton( onPressed: () { + if (isFullScreen) { + _key.currentState?.exitFullscreen(); + } pushReplacementMangaReaderView( context: context, chapter: _streamController.getNextEpisode(), @@ -1022,7 +1028,7 @@ class _AnimeStreamPageState extends riv.ConsumerState { }, seekBarPositionColor: primaryColor(context), seekBarThumbColor: primaryColor(context), - primaryButtonBar: _mobilePrimaryButtonBar(), + primaryButtonBar: _mobilePrimaryButtonBar(isFullScreen), topButtonBarMargin: const EdgeInsets.all(0), topButtonBar: _topButtonBar(context, isFullScreen), bottomButtonBarMargin: const EdgeInsets.only(left: 8, right: 8), @@ -1033,7 +1039,7 @@ class _AnimeStreamPageState extends riv.ConsumerState { child: _videoPlayer(context)); } - List _mobilePrimaryButtonBar() { + List _mobilePrimaryButtonBar(bool isFullScreen) { bool hasPrevEpisode = _streamController.getEpisodeIndex().$1 + 1 != _streamController .getEpisodesLength(_streamController.getEpisodeIndex().$2); @@ -1043,6 +1049,9 @@ class _AnimeStreamPageState extends riv.ConsumerState { IconButton( onPressed: hasPrevEpisode ? () { + if (isFullScreen) { + _key.currentState?.exitFullscreen(); + } pushReplacementMangaReaderView( context: context, chapter: _streamController.getPrevEpisode()); @@ -1060,6 +1069,9 @@ class _AnimeStreamPageState extends riv.ConsumerState { IconButton( onPressed: hasNextEpisode ? () { + if (isFullScreen) { + _key.currentState?.exitFullscreen(); + } pushReplacementMangaReaderView( context: context, chapter: _streamController.getNextEpisode(), diff --git a/lib/modules/manga/reader/reader_view.dart b/lib/modules/manga/reader/reader_view.dart index c3723843..fa5757c7 100644 --- a/lib/modules/manga/reader/reader_view.dart +++ b/lib/modules/manga/reader/reader_view.dart @@ -268,45 +268,72 @@ class _MangaChapterPageGalleryState _goBack(context); return false; }, - child: KeyboardListener( + child: RawKeyboardListener( autofocus: true, focusNode: FocusNode(), - onKeyEvent: (event) { - if (event is KeyDownEvent) { - return; - } + onKey: (event) { bool hasNextChapter = _readerController.getChapterIndex().$1 != 0; bool hasPrevChapter = _readerController.getChapterIndex().$1 + 1 != _readerController .getChaptersLength(_readerController.getChapterIndex().$2); final action = switch (event.logicalKey) { - LogicalKeyboardKey.escape => _goBack(context), - LogicalKeyboardKey.backspace => _goBack(context), + LogicalKeyboardKey.escape => + (!event.isKeyPressed(LogicalKeyboardKey.escape) || event.repeat) + ? _goBack(context) + : null, + LogicalKeyboardKey.backspace => + (!event.isKeyPressed(LogicalKeyboardKey.backspace) || + event.repeat) + ? _goBack(context) + : null, LogicalKeyboardKey.arrowUp => - _onBtnTapped(_currentIndex! - 1, true), - LogicalKeyboardKey.arrowLeft => _isReverseHorizontal - ? _onBtnTapped(_currentIndex! + 1, false) - : _onBtnTapped(_currentIndex! - 1, true), - LogicalKeyboardKey.arrowRight => _isReverseHorizontal - ? _onBtnTapped(_currentIndex! - 1, true) - : _onBtnTapped(_currentIndex! + 1, false), + (!event.isKeyPressed(LogicalKeyboardKey.arrowUp) || event.repeat) + ? _onBtnTapped(_currentIndex! - 1, true) + : null, + LogicalKeyboardKey.arrowLeft => + (!event.isKeyPressed(LogicalKeyboardKey.arrowLeft) || + event.repeat) + ? _isReverseHorizontal + ? _onBtnTapped(_currentIndex! + 1, false) + : _onBtnTapped(_currentIndex! - 1, true) + : null, + LogicalKeyboardKey.arrowRight => + (!event.isKeyPressed(LogicalKeyboardKey.arrowRight) || + event.repeat) + ? _isReverseHorizontal + ? _onBtnTapped(_currentIndex! - 1, true) + : _onBtnTapped(_currentIndex! + 1, false) + : null, LogicalKeyboardKey.arrowDown => - _onBtnTapped(_currentIndex! + 1, true), - LogicalKeyboardKey.keyN || LogicalKeyboardKey.pageDown => switch ( - hasNextChapter) { - true => pushReplacementMangaReaderView( - context: context, - chapter: _readerController.getNextChapter(), - ), - _ => null - }, - LogicalKeyboardKey.keyP || LogicalKeyboardKey.pageUp => switch ( - hasPrevChapter) { - true => pushReplacementMangaReaderView( - context: context, - chapter: _readerController.getPrevChapter()), - _ => null - }, + (!event.isKeyPressed(LogicalKeyboardKey.arrowDown) || + event.repeat) + ? _onBtnTapped(_currentIndex! + 1, true) + : null, + LogicalKeyboardKey.keyN || + LogicalKeyboardKey.pageDown => + ((!event.isKeyPressed(LogicalKeyboardKey.keyN) || + !event.isKeyPressed(LogicalKeyboardKey.pageDown)) || + event.repeat) + ? switch (hasNextChapter) { + true => pushReplacementMangaReaderView( + context: context, + chapter: _readerController.getNextChapter(), + ), + _ => null + } + : null, + LogicalKeyboardKey.keyP || + LogicalKeyboardKey.pageUp => + ((!event.isKeyPressed(LogicalKeyboardKey.keyP) || + !event.isKeyPressed(LogicalKeyboardKey.pageUp)) || + event.repeat) + ? switch (hasPrevChapter) { + true => pushReplacementMangaReaderView( + context: context, + chapter: _readerController.getPrevChapter()), + _ => null + } + : null, _ => null }; action; diff --git a/pubspec.lock b/pubspec.lock index f166f1ab..e291f912 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1597,5 +1597,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0 <4.0.0" + dart: ">=3.2.3 <4.0.0" flutter: ">=3.16.0" diff --git a/pubspec.yaml b/pubspec.yaml index 8e6c7c55..2a3798aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' version: 0.1.45+38 environment: - sdk: '>=3.2.0 <4.0.0' + sdk: '>=3.2.3 <4.0.0' dependencies: