mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-06 02:59:28 +00:00
progress visibility on item page
This commit is contained in:
parent
be7f5daa88
commit
865a662b56
21 changed files with 1009 additions and 765 deletions
11
lib/shared/extensions/duration_format.dart
Normal file
11
lib/shared/extensions/duration_format.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extension DurationFormat on Duration {
|
||||
/// formats the duration of the book as `10h 30m`
|
||||
///
|
||||
/// will add up all the durations of the audio files first
|
||||
/// then convert them to the given format
|
||||
String get formattedBinary {
|
||||
final hours = inHours;
|
||||
final minutes = inMinutes.remainder(60);
|
||||
return '${hours}h ${minutes}m';
|
||||
}
|
||||
}
|
||||
48
lib/shared/extensions/model_conversions.dart
Normal file
48
lib/shared/extensions/model_conversions.dart
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
|
||||
extension LibraryItemConversion on LibraryItem {
|
||||
LibraryItemExpanded get asExpanded =>
|
||||
LibraryItemExpanded.fromJson(toJson());
|
||||
|
||||
LibraryItemMinified get asMinified =>
|
||||
LibraryItemMinified.fromJson(toJson());
|
||||
}
|
||||
|
||||
extension MediaConversion on Media {
|
||||
Book get asBook => Book.fromJson(toJson());
|
||||
BookExpanded get asBookExpanded => BookExpanded.fromJson(toJson());
|
||||
BookMinified get asBookMinified => BookMinified.fromJson(toJson());
|
||||
|
||||
Podcast get asPodcast => Podcast.fromJson(toJson());
|
||||
PodcastExpanded get asPodcastExpanded => PodcastExpanded.fromJson(toJson());
|
||||
PodcastMinified get asPodcastMinified => PodcastMinified.fromJson(toJson());
|
||||
}
|
||||
|
||||
extension MediaMetadataConversion on MediaMetadata {
|
||||
BookMetadata get asBookMetadata => BookMetadata.fromJson(toJson());
|
||||
BookMetadataExpanded get asBookMetadataExpanded =>
|
||||
BookMetadataExpanded.fromJson(toJson());
|
||||
BookMetadataMinified get asBookMetadataMinified =>
|
||||
BookMetadataMinified.fromJson(toJson());
|
||||
|
||||
BookMetadataSeriesFilter get asBookMetadataSeriesFilter =>
|
||||
BookMetadataSeriesFilter.fromJson(toJson());
|
||||
BookMetadataMinifiedSeriesFilter get asBookMetadataMinifiedSeriesFilter =>
|
||||
BookMetadataMinifiedSeriesFilter.fromJson(toJson());
|
||||
|
||||
PodcastMetadata get asPodcastMetadata => PodcastMetadata.fromJson(toJson());
|
||||
PodcastMetadataExpanded get asPodcastMetadataExpanded =>
|
||||
PodcastMetadataExpanded.fromJson(toJson());
|
||||
}
|
||||
|
||||
extension AuthorConversion on Author {
|
||||
AuthorExpanded get asExpanded => AuthorExpanded.fromJson(toJson());
|
||||
AuthorMinified get asMinified => AuthorMinified.fromJson(toJson());
|
||||
}
|
||||
|
||||
extension ShelfConversion on Shelf {
|
||||
LibraryItemShelf get asLibraryItemShelf =>
|
||||
LibraryItemShelf.fromJson(toJson());
|
||||
SeriesShelf get asSeriesShelf => SeriesShelf.fromJson(toJson());
|
||||
AuthorShelf get asAuthorShelf => AuthorShelf.fromJson(toJson());
|
||||
}
|
||||
17
lib/shared/hooks.dart
Normal file
17
lib/shared/hooks.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
|
||||
void useInterval(VoidCallback callback, Duration delay) {
|
||||
final savedCallback = useRef(callback);
|
||||
savedCallback.value = callback;
|
||||
|
||||
useEffect(
|
||||
() {
|
||||
final timer = Timer.periodic(delay, (_) => savedCallback.value());
|
||||
return timer.cancel;
|
||||
},
|
||||
[delay],
|
||||
);
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
import 'package:whispering_pages/api/image_provider.dart';
|
||||
import 'package:whispering_pages/shared/extensions/model_conversions.dart';
|
||||
import 'package:whispering_pages/shared/widgets/shelves/home_shelf.dart';
|
||||
|
||||
/// A shelf that displays Authors on the home page
|
||||
|
|
@ -39,7 +39,7 @@ class AuthorOnShelf extends HookConsumerWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final author = AuthorMinified.fromJson(item.toJson());
|
||||
final author = item.asMinified;
|
||||
// final coverImage = ref.watch(coverImageProvider(item));
|
||||
|
||||
return Container(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import 'package:whispering_pages/api/image_provider.dart';
|
|||
import 'package:whispering_pages/constants/hero_tag_conventions.dart';
|
||||
import 'package:whispering_pages/router/models/library_item_extras.dart';
|
||||
import 'package:whispering_pages/router/router.dart';
|
||||
import 'package:whispering_pages/shared/extensions/model_conversions.dart';
|
||||
import 'package:whispering_pages/shared/widgets/shelves/home_shelf.dart';
|
||||
|
||||
/// A shelf that displays books on the home page
|
||||
|
|
@ -57,8 +58,8 @@ class BookOnShelf extends HookConsumerWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final book = BookMinified.fromJson(item.media.toJson());
|
||||
final metadata = BookMetadataMinified.fromJson(book.metadata.toJson());
|
||||
final book = item.media.asBookMinified;
|
||||
final metadata = book.metadata.asBookMetadataMinified;
|
||||
final coverImage = ref.watch(coverImageProvider(item));
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
|
|
@ -75,7 +76,6 @@ class BookOnShelf extends HookConsumerWidget {
|
|||
child: Center(
|
||||
child: Hero(
|
||||
tag: HeroTagPrefixes.bookCover + item.id + heroTagSuffix,
|
||||
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// open the book
|
||||
|
|
@ -91,7 +91,6 @@ class BookOnShelf extends HookConsumerWidget {
|
|||
),
|
||||
);
|
||||
},
|
||||
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: coverImage.when(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||
import 'package:whispering_pages/shared/extensions/model_conversions.dart';
|
||||
import 'package:whispering_pages/shared/widgets/shelves/author_shelf.dart';
|
||||
import 'package:whispering_pages/shared/widgets/shelves/book_shelf.dart';
|
||||
|
||||
|
|
@ -24,11 +25,11 @@ class HomeShelf extends HookConsumerWidget {
|
|||
return switch (shelf.type) {
|
||||
ShelfType.book => BookHomeShelf(
|
||||
title: title,
|
||||
shelf: LibraryItemShelf.fromJson(shelf.toJson()),
|
||||
shelf: shelf.asLibraryItemShelf,
|
||||
),
|
||||
ShelfType.authors => AuthorHomeShelf(
|
||||
title: title,
|
||||
shelf: AuthorShelf.fromJson(shelf.toJson()),
|
||||
shelf: shelf.asAuthorShelf,
|
||||
),
|
||||
_ => Container(),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue