-
-
Notifications
You must be signed in to change notification settings - Fork 158
feat: Previous and next chapter buttons #1063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alex-rans
wants to merge
2
commits into
DonutWare:develop
Choose a base branch
from
alex-rans:feature_chapter_buttons
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import 'package:iconsax_plus/iconsax_plus.dart'; | |
| import 'package:screen_brightness/screen_brightness.dart'; | ||
|
|
||
| import 'package:fladder/models/item_base_model.dart'; | ||
| import 'package:fladder/models/items/chapters_model.dart'; | ||
| import 'package:fladder/models/items/media_segments_model.dart'; | ||
| import 'package:fladder/models/items/media_streams_model.dart'; | ||
| import 'package:fladder/models/media_playback_model.dart'; | ||
|
|
@@ -428,6 +429,7 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| ), | ||
| ), | ||
| previousButton, | ||
| previousChapterButton(ref), | ||
| seekBackwardButton(ref), | ||
| IconButton.filledTonal( | ||
| iconSize: 38, | ||
|
|
@@ -439,6 +441,7 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| ), | ||
| ), | ||
| seekForwardButton(ref), | ||
| nextChapterButton(ref), | ||
| nextVideoButton, | ||
| Flexible( | ||
| flex: 2, | ||
|
|
@@ -685,6 +688,66 @@ class _DesktopControlsState extends ConsumerState<DesktopControls> { | |
| ); | ||
| } | ||
|
|
||
| Widget nextChapterButton(WidgetRef ref) { | ||
| return Consumer(builder: (context, ref2, child) { | ||
| final chapters = ref.read(playBackModel.select((value) => value?.chapters)); | ||
| final enabled = chapters?.isNotEmpty == true; | ||
| return IconButton( | ||
| onPressed: enabled ? () => _nextChapter(ref) : null, | ||
| iconSize: 30, | ||
| tooltip: context.localized.nextChapter, | ||
| icon: const Icon(IconsaxPlusLinear.arrow_right_1), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| Widget previousChapterButton(WidgetRef ref) { | ||
| return Consumer(builder: (context, ref2, child) { | ||
| final chapters = ref.read(playBackModel.select((value) => value?.chapters)); | ||
| final enabled = chapters?.isNotEmpty == true; | ||
| return IconButton( | ||
| onPressed: enabled ? () => _previousChapter(ref) : null, | ||
| iconSize: 30, | ||
| tooltip: context.localized.nextChapter, | ||
| icon: const Icon(IconsaxPlusLinear.arrow_left_3), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| void _previousChapter(WidgetRef ref) { | ||
| final chapters = ref.read(playBackModel.select((value) => value?.chapters)) ?? []; | ||
| if (chapters.isEmpty) return; | ||
| final position = ref.read(mediaPlaybackProvider).position; | ||
| final threshold = const Duration(milliseconds: 3000); | ||
| Chapter? prev; | ||
| final earlier = chapters.where((c) => c.startPosition < position - threshold).toList(); | ||
| if (earlier.isNotEmpty) prev = earlier.last; | ||
| final target = prev ?? chapters.first; | ||
| ref.read(videoPlayerProvider).seek(target.startPosition); | ||
| resetTimer(); | ||
| } | ||
|
|
||
| void _nextChapter(WidgetRef ref) { | ||
| final chapters = ref.read(playBackModel.select((value) => value?.chapters)) ?? []; | ||
| if (chapters.isEmpty) return; | ||
| final position = ref.read(mediaPlaybackProvider).position; | ||
| Chapter? next; | ||
| for (final c in chapters) { | ||
| if (c.startPosition > position) { | ||
| next = c; | ||
| break; | ||
| } | ||
| } | ||
| if (next != null) { | ||
| ref.read(videoPlayerProvider).seek(next.startPosition); | ||
| } else { | ||
| // fallback: load next video | ||
| final nextVideo = ref.read(playBackModel.select((value) => value?.nextVideo)); | ||
| if (nextVideo != null) ref.read(playbackModelHelper).loadNewVideo(nextVideo); | ||
| } | ||
|
Comment on lines
+741
to
+747
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about loading the next video. Would it not be better to disable the next chapter button if there is no next chapter? |
||
| resetTimer(); | ||
| } | ||
|
|
||
| void skipToSegmentEnd(MediaSegment? mediaSegment, String? segmentId) { | ||
| final end = mediaSegment?.end; | ||
| if (end != null) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a extension in
chapters_model.dartlets move the next/previous lookups in there and only pass the required paramaters to fetch previous/next chapters.That way we can re-use it when needed.