feat: Implement TTS playback store and enhance reading progress synchronization
- Added ReaderTtsPlaybackStore to manage TTS start requests with a maximum of 4 pending requests. - Updated app configuration to use a production API URL. - Enhanced BookmarkModel to infer type when not provided by the API for backward compatibility. - Introduced methods in LocalStore for saving, loading, and clearing the last route path. - Implemented syncProgress method in BookshelfNotifier to update reading progress and bookmarks from the server. - Modified ReaderScreen to handle chapter navigation and TTS playback more effectively, including auto-start logic. - Updated TtsPlayerWidget to accept additional parameters for chapter navigation. - Enhanced TtsNotifier to handle new parameters for TTS requests and manage playback state. - Improved SplashScreen to restore the last visited route after splash screen display.
This commit is contained in:
@@ -11,7 +11,7 @@ class AppConfig {
|
||||
}
|
||||
|
||||
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
|
||||
return 'http://10.0.2.2:8000';
|
||||
return 'https://reader-api.fevirtus.dev';
|
||||
}
|
||||
|
||||
return 'http://localhost:8000';
|
||||
|
||||
@@ -39,13 +39,28 @@ class BookmarkModel extends Equatable {
|
||||
factory BookmarkModel.fromJson(Map<String, dynamic> json) => BookmarkModel(
|
||||
id: json['id'] as String,
|
||||
novelId: json['novelId'] as String,
|
||||
type: BookmarkType.fromString(json['type'] as String?),
|
||||
lastChapterId: json['lastChapterId'] as String?,
|
||||
lastChapterNumber: json['lastChapterNumber'] as int?,
|
||||
readChapters: (json['readChapters'] as List<dynamic>?)
|
||||
?.map((e) => (e as num).toInt())
|
||||
.toList() ??
|
||||
[],
|
||||
type: () {
|
||||
final explicitType = BookmarkType.fromString(json['type'] as String?);
|
||||
if ((json['type'] as String?) != null) {
|
||||
return explicitType;
|
||||
}
|
||||
|
||||
// Backward-compatible inference when API does not return `type`.
|
||||
final inferredLastChapter = json['lastChapterNumber'] as int?;
|
||||
final inferredReadChapters = (json['readChapters'] as List<dynamic>?)
|
||||
?.map((e) => (e as num).toInt())
|
||||
.toList() ??
|
||||
const <int>[];
|
||||
return (inferredLastChapter != null || inferredReadChapters.isNotEmpty)
|
||||
? BookmarkType.reading
|
||||
: BookmarkType.bookmarked;
|
||||
}(),
|
||||
novel: json['novel'] != null
|
||||
? NovelModel.fromJson(json['novel'] as Map<String, dynamic>)
|
||||
: null,
|
||||
|
||||
@@ -16,6 +16,7 @@ class LocalStore {
|
||||
static const _kProgressChapterId = 'progress_chapter_id_';
|
||||
static const _kProgressChapterNum = 'progress_chapter_num_';
|
||||
static const _kProgressOffset = 'progress_offset_';
|
||||
static const _kLastRoutePath = 'last_route_path';
|
||||
|
||||
// ── Reading settings ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -86,6 +87,27 @@ class LocalStore {
|
||||
'scrollOffset': prefs.getDouble('$_kProgressOffset$novelId') ?? 0.0,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Last route restore (cold start after process reclaim) ───────────────
|
||||
|
||||
Future<void> saveLastRoutePath(String path) async {
|
||||
final normalized = path.trim();
|
||||
if (normalized.isEmpty || normalized == '/') return;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_kLastRoutePath, normalized);
|
||||
}
|
||||
|
||||
Future<String?> loadLastRoutePath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final value = prefs.getString(_kLastRoutePath)?.trim();
|
||||
if (value == null || value.isEmpty) return null;
|
||||
return value;
|
||||
}
|
||||
|
||||
Future<void> clearLastRoutePath() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.remove(_kLastRoutePath);
|
||||
}
|
||||
}
|
||||
|
||||
final localStoreProvider = Provider<LocalStore>((_) => LocalStore());
|
||||
|
||||
Reference in New Issue
Block a user