progress visibility on item page

This commit is contained in:
Dr-Blank 2024-06-16 22:24:32 -04:00
parent be7f5daa88
commit 865a662b56
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
21 changed files with 1009 additions and 765 deletions

View 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';
}
}

View 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
View 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],
);
}

View file

@ -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(

View file

@ -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(

View file

@ -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(),
};