mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-09 12:39:29 +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
|
|
@ -6,6 +6,7 @@ import 'package:shelfsdk/audiobookshelf_api.dart' as shelfsdk;
|
|||
import 'package:whispering_pages/api/api_provider.dart';
|
||||
import 'package:whispering_pages/db/cache/cache_key.dart';
|
||||
import 'package:whispering_pages/db/cache_manager.dart';
|
||||
import 'package:whispering_pages/shared/extensions/model_conversions.dart';
|
||||
|
||||
part 'library_item_provider.g.dart';
|
||||
|
||||
|
|
@ -13,10 +14,10 @@ part 'library_item_provider.g.dart';
|
|||
@riverpod
|
||||
class LibraryItem extends _$LibraryItem {
|
||||
@override
|
||||
Stream<shelfsdk.LibraryItem> build(String id) async* {
|
||||
Stream<shelfsdk.LibraryItemExpanded> build(String id) async* {
|
||||
final api = ref.watch(authenticatedApiProvider);
|
||||
|
||||
debugPrint('fetching library item: $id');
|
||||
debugPrint('LibraryItemProvider fetching library item: $id');
|
||||
|
||||
// ! this is a mock delay
|
||||
// await Future.delayed(const Duration(seconds: 10));
|
||||
|
|
@ -26,27 +27,41 @@ class LibraryItem extends _$LibraryItem {
|
|||
final cachedFile = await apiResponseCacheManager.getFileFromMemory(key) ??
|
||||
await apiResponseCacheManager.getFileFromCache(key);
|
||||
if (cachedFile != null) {
|
||||
debugPrint('reading from cache for $id from ${cachedFile.file}');
|
||||
debugPrint('LibraryItemProvider reading from cache for $id from ${cachedFile.file}');
|
||||
// read file as json
|
||||
final cachedItem = shelfsdk.LibraryItem.fromJson(
|
||||
final cachedItem = shelfsdk.LibraryItemExpanded.fromJson(
|
||||
jsonDecode(await cachedFile.file.readAsString()),
|
||||
);
|
||||
yield cachedItem;
|
||||
} else {
|
||||
debugPrint('LibraryItemProvider cache miss for $id');
|
||||
}
|
||||
|
||||
// ! this is a mock delay
|
||||
// await Future.delayed(const Duration(seconds: 3));
|
||||
|
||||
final item = await api.items.get(
|
||||
libraryItemId: id,
|
||||
parameters: const shelfsdk.GetItemReqParams(expanded: true),
|
||||
parameters: const shelfsdk.GetItemReqParams(
|
||||
expanded: true,
|
||||
include: [
|
||||
shelfsdk.GetItemIncludeOption.progress,
|
||||
shelfsdk.GetItemIncludeOption.rssFeed,
|
||||
shelfsdk.GetItemIncludeOption.authors,
|
||||
shelfsdk.GetItemIncludeOption.downloads,
|
||||
],
|
||||
),
|
||||
);
|
||||
if (item != null) {
|
||||
// save to cache
|
||||
final newFile = await apiResponseCacheManager.putFile(
|
||||
key,
|
||||
utf8.encode(jsonEncode(item)),
|
||||
utf8.encode(jsonEncode(item.asExpanded.toJson())),
|
||||
fileExtension: 'json',
|
||||
key: key,
|
||||
);
|
||||
debugPrint('writing to cache: $newFile');
|
||||
yield item;
|
||||
yield item.asExpanded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue