Skip to content

Commit

Permalink
Fix Reader Keyboad listener
Browse files Browse the repository at this point in the history
  • Loading branch information
kodjodevf committed Dec 22, 2023
1 parent 8af1175 commit cf17603
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 35 deletions.
2 changes: 1 addition & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions lib/modules/anime/anime_player_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
if (hasPrevEpisode)
IconButton(
onPressed: () {
if (isFullScreen) {
_key.currentState?.exitFullscreen();
}
pushReplacementMangaReaderView(
context: context,
chapter: _streamController.getPrevEpisode());
Expand All @@ -805,6 +808,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
if (hasNextEpisode)
IconButton(
onPressed: () {
if (isFullScreen) {
_key.currentState?.exitFullscreen();
}
pushReplacementMangaReaderView(
context: context,
chapter: _streamController.getNextEpisode(),
Expand Down Expand Up @@ -1022,7 +1028,7 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
},
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),
Expand All @@ -1033,7 +1039,7 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
child: _videoPlayer(context));
}

List<Widget> _mobilePrimaryButtonBar() {
List<Widget> _mobilePrimaryButtonBar(bool isFullScreen) {
bool hasPrevEpisode = _streamController.getEpisodeIndex().$1 + 1 !=
_streamController
.getEpisodesLength(_streamController.getEpisodeIndex().$2);
Expand All @@ -1043,6 +1049,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
IconButton(
onPressed: hasPrevEpisode
? () {
if (isFullScreen) {
_key.currentState?.exitFullscreen();
}
pushReplacementMangaReaderView(
context: context,
chapter: _streamController.getPrevEpisode());
Expand All @@ -1060,6 +1069,9 @@ class _AnimeStreamPageState extends riv.ConsumerState<AnimeStreamPage> {
IconButton(
onPressed: hasNextEpisode
? () {
if (isFullScreen) {
_key.currentState?.exitFullscreen();
}
pushReplacementMangaReaderView(
context: context,
chapter: _streamController.getNextEpisode(),
Expand Down
87 changes: 57 additions & 30 deletions lib/modules/manga/reader/reader_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cf17603

Please sign in to comment.