mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-18 00:49:30 +00:00
chapter selection in player
This commit is contained in:
parent
c24541f1cd
commit
ec8304fdc3
7 changed files with 163 additions and 14 deletions
8
lib/shared/extensions/chapter.dart
Normal file
8
lib/shared/extensions/chapter.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
|
||||
extension ChapterDuration on BookChapter {
|
||||
Duration get duration {
|
||||
// end - start
|
||||
return end - start;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,20 @@
|
|||
extension DurationFormat on Duration {
|
||||
/// formats the duration of the book as `10h 30m`
|
||||
/// formats the duration using only 2 units
|
||||
///
|
||||
/// will add up all the durations of the audio files first
|
||||
/// then convert them to the given format
|
||||
String get formattedBinary {
|
||||
/// if the duration is more than 1 hour, it will return `10h 30m`
|
||||
/// if the duration is less than 1 hour, it will return `30m 20s`
|
||||
/// if the duration is less than 1 minute, it will return `20s`
|
||||
String get smartBinaryFormat {
|
||||
final hours = inHours;
|
||||
final minutes = inMinutes.remainder(60);
|
||||
return '${hours}h ${minutes}m';
|
||||
final seconds = inSeconds.remainder(60);
|
||||
if (hours > 0) {
|
||||
return '${hours}h ${minutes}m';
|
||||
} else if (minutes > 0) {
|
||||
return '${minutes}m ${seconds}s';
|
||||
} else {
|
||||
return '${seconds}s';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,3 +15,16 @@ void useInterval(VoidCallback callback, Duration delay) {
|
|||
[delay],
|
||||
);
|
||||
}
|
||||
|
||||
void useTimer(VoidCallback callback, Duration delay) {
|
||||
final savedCallback = useRef(callback);
|
||||
savedCallback.value = callback;
|
||||
|
||||
useEffect(
|
||||
() {
|
||||
final timer = Timer(delay, savedCallback.value);
|
||||
return timer.cancel;
|
||||
},
|
||||
[delay],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
10
lib/shared/widgets/not_implemented.dart
Normal file
10
lib/shared/widgets/not_implemented.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
void showNotImplementedToast(BuildContext context) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text("Not implemented"),
|
||||
showCloseIcon: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue