diff --git a/lib/db/available_boxes.dart b/lib/db/available_boxes.dart index 790d591..ff01acc 100644 --- a/lib/db/available_boxes.dart +++ b/lib/db/available_boxes.dart @@ -1,5 +1,6 @@ import 'package:flutter/foundation.dart' show immutable; import 'package:hive/hive.dart'; +import 'package:vaani/features/per_book_settings/models/book_settings.dart'; import 'package:vaani/settings/models/models.dart'; @immutable @@ -19,4 +20,8 @@ class AvailableHiveBoxes { /// stores the a list of [AuthenticatedUser] static final authenticatedUserBox = Hive.box(name: 'authenticatedUser'); + + /// stores the a list of [BookSettings] + static final individualBookSettingsBox = + Hive.box(name: 'bookSettings'); } diff --git a/lib/db/register_models.dart b/lib/db/register_models.dart index 16dc718..e185e33 100644 --- a/lib/db/register_models.dart +++ b/lib/db/register_models.dart @@ -1,4 +1,5 @@ import 'package:hive/hive.dart'; +import 'package:vaani/features/per_book_settings/models/book_settings.dart'; import 'package:vaani/settings/models/models.dart'; // register all models to Hive for serialization @@ -19,4 +20,12 @@ Future registerModels() async { 'AuthenticatedUser', ((json) => AuthenticatedUser.fromJson(json)), ); + Hive.registerAdapter( + 'BookSettings', + ((json) => BookSettings.fromJson(json)), + ); + Hive.registerAdapter( + '_\$BookSettingsImpl', // hack because of freezed + ((json) => BookSettings.fromJson(json)), + ); } diff --git a/lib/features/item_viewer/view/library_item_actions.dart b/lib/features/item_viewer/view/library_item_actions.dart index 7be83f4..f92d32d 100644 --- a/lib/features/item_viewer/view/library_item_actions.dart +++ b/lib/features/item_viewer/view/library_item_actions.dart @@ -11,6 +11,7 @@ import 'package:vaani/features/downloads/providers/download_manager.dart' downloadStatusProvider, simpleDownloadManagerProvider; import 'package:vaani/features/item_viewer/view/library_item_page.dart'; +import 'package:vaani/features/per_book_settings/providers/book_settings_provider.dart'; import 'package:vaani/features/player/providers/audiobook_player.dart'; import 'package:vaani/features/player/providers/player_form.dart'; import 'package:vaani/main.dart'; @@ -423,6 +424,7 @@ class DynamicItemPlayIcon extends StatelessWidget { } } +/// Handles the play button pressed on the library item Future libraryItemPlayButtonOnPressed({ required WidgetRef ref, required shelfsdk.BookExpanded book, @@ -434,6 +436,7 @@ Future libraryItemPlayButtonOnPressed({ final isCurrentBookSetInPlayer = player.book == book; final isPlayingThisBook = player.playing && isCurrentBookSetInPlayer; + Future? setSourceFuture; // set the book to the player if not already set if (!isCurrentBookSetInPlayer) { debugPrint('Setting the book ${book.libraryItemId}'); @@ -442,7 +445,7 @@ Future libraryItemPlayButtonOnPressed({ final libItem = await ref.read(libraryItemProvider(book.libraryItemId).future); final downloadedUris = await downloadManager.getDownloadedFiles(libItem); - await player.setSourceAudiobook( + setSourceFuture = player.setSourceAudiobook( book, initialPosition: userMediaProgress?.currentTime, downloadedUris: downloadedUris, @@ -455,10 +458,32 @@ Future libraryItemPlayButtonOnPressed({ return; } } + // set the volume as this is the first time playing and dismissing causes the volume to go to 0 + var bookPlayerSettings = + ref.read(bookSettingsProvider(book.libraryItemId)).playerSettings; + var appPlayerSettings = ref.read(appSettingsProvider).playerSettings; + + var configurePlayerForEveryBook = + appPlayerSettings.configurePlayerForEveryBook; + + await Future.wait([ + setSourceFuture ?? Future.value(), + // set the volume + player.setVolume( + configurePlayerForEveryBook + ? bookPlayerSettings.preferredDefaultVolume ?? + appPlayerSettings.preferredDefaultVolume + : appPlayerSettings.preferredDefaultVolume, + ), + // set the speed + player.setSpeed( + configurePlayerForEveryBook + ? bookPlayerSettings.preferredDefaultSpeed ?? + appPlayerSettings.preferredDefaultSpeed + : appPlayerSettings.preferredDefaultSpeed, + ), + ]); + // toggle play/pause await player.play(); - // set the volume as this is the first time playing and dismissing causes the volume to go to 0 - await player.setVolume( - ref.read(appSettingsProvider).playerSettings.preferredDefaultVolume, - ); } diff --git a/lib/features/per_book_settings/models/book_settings.dart b/lib/features/per_book_settings/models/book_settings.dart new file mode 100644 index 0000000..b4f0cda --- /dev/null +++ b/lib/features/per_book_settings/models/book_settings.dart @@ -0,0 +1,17 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:vaani/features/per_book_settings/models/nullable_player_settings.dart'; + +part 'book_settings.freezed.dart'; +part 'book_settings.g.dart'; + +/// per book settings +@freezed +class BookSettings with _$BookSettings { + const factory BookSettings({ + required String bookId, + @Default(NullablePlayerSettings()) NullablePlayerSettings playerSettings, + }) = _BookSettings; + + factory BookSettings.fromJson(Map json) => + _$BookSettingsFromJson(json); +} diff --git a/lib/features/per_book_settings/models/book_settings.freezed.dart b/lib/features/per_book_settings/models/book_settings.freezed.dart new file mode 100644 index 0000000..63b55da --- /dev/null +++ b/lib/features/per_book_settings/models/book_settings.freezed.dart @@ -0,0 +1,203 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'book_settings.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +BookSettings _$BookSettingsFromJson(Map json) { + return _BookSettings.fromJson(json); +} + +/// @nodoc +mixin _$BookSettings { + String get bookId => throw _privateConstructorUsedError; + NullablePlayerSettings get playerSettings => + throw _privateConstructorUsedError; + + /// Serializes this BookSettings to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $BookSettingsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $BookSettingsCopyWith<$Res> { + factory $BookSettingsCopyWith( + BookSettings value, $Res Function(BookSettings) then) = + _$BookSettingsCopyWithImpl<$Res, BookSettings>; + @useResult + $Res call({String bookId, NullablePlayerSettings playerSettings}); + + $NullablePlayerSettingsCopyWith<$Res> get playerSettings; +} + +/// @nodoc +class _$BookSettingsCopyWithImpl<$Res, $Val extends BookSettings> + implements $BookSettingsCopyWith<$Res> { + _$BookSettingsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? bookId = null, + Object? playerSettings = null, + }) { + return _then(_value.copyWith( + bookId: null == bookId + ? _value.bookId + : bookId // ignore: cast_nullable_to_non_nullable + as String, + playerSettings: null == playerSettings + ? _value.playerSettings + : playerSettings // ignore: cast_nullable_to_non_nullable + as NullablePlayerSettings, + ) as $Val); + } + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $NullablePlayerSettingsCopyWith<$Res> get playerSettings { + return $NullablePlayerSettingsCopyWith<$Res>(_value.playerSettings, + (value) { + return _then(_value.copyWith(playerSettings: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$BookSettingsImplCopyWith<$Res> + implements $BookSettingsCopyWith<$Res> { + factory _$$BookSettingsImplCopyWith( + _$BookSettingsImpl value, $Res Function(_$BookSettingsImpl) then) = + __$$BookSettingsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String bookId, NullablePlayerSettings playerSettings}); + + @override + $NullablePlayerSettingsCopyWith<$Res> get playerSettings; +} + +/// @nodoc +class __$$BookSettingsImplCopyWithImpl<$Res> + extends _$BookSettingsCopyWithImpl<$Res, _$BookSettingsImpl> + implements _$$BookSettingsImplCopyWith<$Res> { + __$$BookSettingsImplCopyWithImpl( + _$BookSettingsImpl _value, $Res Function(_$BookSettingsImpl) _then) + : super(_value, _then); + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? bookId = null, + Object? playerSettings = null, + }) { + return _then(_$BookSettingsImpl( + bookId: null == bookId + ? _value.bookId + : bookId // ignore: cast_nullable_to_non_nullable + as String, + playerSettings: null == playerSettings + ? _value.playerSettings + : playerSettings // ignore: cast_nullable_to_non_nullable + as NullablePlayerSettings, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$BookSettingsImpl implements _BookSettings { + const _$BookSettingsImpl( + {required this.bookId, + this.playerSettings = const NullablePlayerSettings()}); + + factory _$BookSettingsImpl.fromJson(Map json) => + _$$BookSettingsImplFromJson(json); + + @override + final String bookId; + @override + @JsonKey() + final NullablePlayerSettings playerSettings; + + @override + String toString() { + return 'BookSettings(bookId: $bookId, playerSettings: $playerSettings)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$BookSettingsImpl && + (identical(other.bookId, bookId) || other.bookId == bookId) && + (identical(other.playerSettings, playerSettings) || + other.playerSettings == playerSettings)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, bookId, playerSettings); + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$BookSettingsImplCopyWith<_$BookSettingsImpl> get copyWith => + __$$BookSettingsImplCopyWithImpl<_$BookSettingsImpl>(this, _$identity); + + @override + Map toJson() { + return _$$BookSettingsImplToJson( + this, + ); + } +} + +abstract class _BookSettings implements BookSettings { + const factory _BookSettings( + {required final String bookId, + final NullablePlayerSettings playerSettings}) = _$BookSettingsImpl; + + factory _BookSettings.fromJson(Map json) = + _$BookSettingsImpl.fromJson; + + @override + String get bookId; + @override + NullablePlayerSettings get playerSettings; + + /// Create a copy of BookSettings + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$BookSettingsImplCopyWith<_$BookSettingsImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/features/per_book_settings/models/book_settings.g.dart b/lib/features/per_book_settings/models/book_settings.g.dart new file mode 100644 index 0000000..a66fba1 --- /dev/null +++ b/lib/features/per_book_settings/models/book_settings.g.dart @@ -0,0 +1,22 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'book_settings.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$BookSettingsImpl _$$BookSettingsImplFromJson(Map json) => + _$BookSettingsImpl( + bookId: json['bookId'] as String, + playerSettings: json['playerSettings'] == null + ? const NullablePlayerSettings() + : NullablePlayerSettings.fromJson( + json['playerSettings'] as Map), + ); + +Map _$$BookSettingsImplToJson(_$BookSettingsImpl instance) => + { + 'bookId': instance.bookId, + 'playerSettings': instance.playerSettings, + }; diff --git a/lib/features/per_book_settings/models/nullable_player_settings.dart b/lib/features/per_book_settings/models/nullable_player_settings.dart new file mode 100644 index 0000000..39135d7 --- /dev/null +++ b/lib/features/per_book_settings/models/nullable_player_settings.dart @@ -0,0 +1,21 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:vaani/settings/models/app_settings.dart'; + +part 'nullable_player_settings.freezed.dart'; +part 'nullable_player_settings.g.dart'; + +@freezed +class NullablePlayerSettings with _$NullablePlayerSettings { + const factory NullablePlayerSettings({ + MinimizedPlayerSettings? miniPlayerSettings, + ExpandedPlayerSettings? expandedPlayerSettings, + double? preferredDefaultVolume, + double? preferredDefaultSpeed, + List? speedOptions, + SleepTimerSettings? sleepTimerSettings, + Duration? playbackReportInterval, + }) = _NullablePlayerSettings; + + factory NullablePlayerSettings.fromJson(Map json) => + _$NullablePlayerSettingsFromJson(json); +} diff --git a/lib/features/per_book_settings/models/nullable_player_settings.freezed.dart b/lib/features/per_book_settings/models/nullable_player_settings.freezed.dart new file mode 100644 index 0000000..9450ed4 --- /dev/null +++ b/lib/features/per_book_settings/models/nullable_player_settings.freezed.dart @@ -0,0 +1,377 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'nullable_player_settings.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +NullablePlayerSettings _$NullablePlayerSettingsFromJson( + Map json) { + return _NullablePlayerSettings.fromJson(json); +} + +/// @nodoc +mixin _$NullablePlayerSettings { + MinimizedPlayerSettings? get miniPlayerSettings => + throw _privateConstructorUsedError; + ExpandedPlayerSettings? get expandedPlayerSettings => + throw _privateConstructorUsedError; + double? get preferredDefaultVolume => throw _privateConstructorUsedError; + double? get preferredDefaultSpeed => throw _privateConstructorUsedError; + List? get speedOptions => throw _privateConstructorUsedError; + SleepTimerSettings? get sleepTimerSettings => + throw _privateConstructorUsedError; + Duration? get playbackReportInterval => throw _privateConstructorUsedError; + + /// Serializes this NullablePlayerSettings to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $NullablePlayerSettingsCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $NullablePlayerSettingsCopyWith<$Res> { + factory $NullablePlayerSettingsCopyWith(NullablePlayerSettings value, + $Res Function(NullablePlayerSettings) then) = + _$NullablePlayerSettingsCopyWithImpl<$Res, NullablePlayerSettings>; + @useResult + $Res call( + {MinimizedPlayerSettings? miniPlayerSettings, + ExpandedPlayerSettings? expandedPlayerSettings, + double? preferredDefaultVolume, + double? preferredDefaultSpeed, + List? speedOptions, + SleepTimerSettings? sleepTimerSettings, + Duration? playbackReportInterval}); + + $MinimizedPlayerSettingsCopyWith<$Res>? get miniPlayerSettings; + $ExpandedPlayerSettingsCopyWith<$Res>? get expandedPlayerSettings; + $SleepTimerSettingsCopyWith<$Res>? get sleepTimerSettings; +} + +/// @nodoc +class _$NullablePlayerSettingsCopyWithImpl<$Res, + $Val extends NullablePlayerSettings> + implements $NullablePlayerSettingsCopyWith<$Res> { + _$NullablePlayerSettingsCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? miniPlayerSettings = freezed, + Object? expandedPlayerSettings = freezed, + Object? preferredDefaultVolume = freezed, + Object? preferredDefaultSpeed = freezed, + Object? speedOptions = freezed, + Object? sleepTimerSettings = freezed, + Object? playbackReportInterval = freezed, + }) { + return _then(_value.copyWith( + miniPlayerSettings: freezed == miniPlayerSettings + ? _value.miniPlayerSettings + : miniPlayerSettings // ignore: cast_nullable_to_non_nullable + as MinimizedPlayerSettings?, + expandedPlayerSettings: freezed == expandedPlayerSettings + ? _value.expandedPlayerSettings + : expandedPlayerSettings // ignore: cast_nullable_to_non_nullable + as ExpandedPlayerSettings?, + preferredDefaultVolume: freezed == preferredDefaultVolume + ? _value.preferredDefaultVolume + : preferredDefaultVolume // ignore: cast_nullable_to_non_nullable + as double?, + preferredDefaultSpeed: freezed == preferredDefaultSpeed + ? _value.preferredDefaultSpeed + : preferredDefaultSpeed // ignore: cast_nullable_to_non_nullable + as double?, + speedOptions: freezed == speedOptions + ? _value.speedOptions + : speedOptions // ignore: cast_nullable_to_non_nullable + as List?, + sleepTimerSettings: freezed == sleepTimerSettings + ? _value.sleepTimerSettings + : sleepTimerSettings // ignore: cast_nullable_to_non_nullable + as SleepTimerSettings?, + playbackReportInterval: freezed == playbackReportInterval + ? _value.playbackReportInterval + : playbackReportInterval // ignore: cast_nullable_to_non_nullable + as Duration?, + ) as $Val); + } + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $MinimizedPlayerSettingsCopyWith<$Res>? get miniPlayerSettings { + if (_value.miniPlayerSettings == null) { + return null; + } + + return $MinimizedPlayerSettingsCopyWith<$Res>(_value.miniPlayerSettings!, + (value) { + return _then(_value.copyWith(miniPlayerSettings: value) as $Val); + }); + } + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $ExpandedPlayerSettingsCopyWith<$Res>? get expandedPlayerSettings { + if (_value.expandedPlayerSettings == null) { + return null; + } + + return $ExpandedPlayerSettingsCopyWith<$Res>(_value.expandedPlayerSettings!, + (value) { + return _then(_value.copyWith(expandedPlayerSettings: value) as $Val); + }); + } + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $SleepTimerSettingsCopyWith<$Res>? get sleepTimerSettings { + if (_value.sleepTimerSettings == null) { + return null; + } + + return $SleepTimerSettingsCopyWith<$Res>(_value.sleepTimerSettings!, + (value) { + return _then(_value.copyWith(sleepTimerSettings: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$NullablePlayerSettingsImplCopyWith<$Res> + implements $NullablePlayerSettingsCopyWith<$Res> { + factory _$$NullablePlayerSettingsImplCopyWith( + _$NullablePlayerSettingsImpl value, + $Res Function(_$NullablePlayerSettingsImpl) then) = + __$$NullablePlayerSettingsImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {MinimizedPlayerSettings? miniPlayerSettings, + ExpandedPlayerSettings? expandedPlayerSettings, + double? preferredDefaultVolume, + double? preferredDefaultSpeed, + List? speedOptions, + SleepTimerSettings? sleepTimerSettings, + Duration? playbackReportInterval}); + + @override + $MinimizedPlayerSettingsCopyWith<$Res>? get miniPlayerSettings; + @override + $ExpandedPlayerSettingsCopyWith<$Res>? get expandedPlayerSettings; + @override + $SleepTimerSettingsCopyWith<$Res>? get sleepTimerSettings; +} + +/// @nodoc +class __$$NullablePlayerSettingsImplCopyWithImpl<$Res> + extends _$NullablePlayerSettingsCopyWithImpl<$Res, + _$NullablePlayerSettingsImpl> + implements _$$NullablePlayerSettingsImplCopyWith<$Res> { + __$$NullablePlayerSettingsImplCopyWithImpl( + _$NullablePlayerSettingsImpl _value, + $Res Function(_$NullablePlayerSettingsImpl) _then) + : super(_value, _then); + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? miniPlayerSettings = freezed, + Object? expandedPlayerSettings = freezed, + Object? preferredDefaultVolume = freezed, + Object? preferredDefaultSpeed = freezed, + Object? speedOptions = freezed, + Object? sleepTimerSettings = freezed, + Object? playbackReportInterval = freezed, + }) { + return _then(_$NullablePlayerSettingsImpl( + miniPlayerSettings: freezed == miniPlayerSettings + ? _value.miniPlayerSettings + : miniPlayerSettings // ignore: cast_nullable_to_non_nullable + as MinimizedPlayerSettings?, + expandedPlayerSettings: freezed == expandedPlayerSettings + ? _value.expandedPlayerSettings + : expandedPlayerSettings // ignore: cast_nullable_to_non_nullable + as ExpandedPlayerSettings?, + preferredDefaultVolume: freezed == preferredDefaultVolume + ? _value.preferredDefaultVolume + : preferredDefaultVolume // ignore: cast_nullable_to_non_nullable + as double?, + preferredDefaultSpeed: freezed == preferredDefaultSpeed + ? _value.preferredDefaultSpeed + : preferredDefaultSpeed // ignore: cast_nullable_to_non_nullable + as double?, + speedOptions: freezed == speedOptions + ? _value._speedOptions + : speedOptions // ignore: cast_nullable_to_non_nullable + as List?, + sleepTimerSettings: freezed == sleepTimerSettings + ? _value.sleepTimerSettings + : sleepTimerSettings // ignore: cast_nullable_to_non_nullable + as SleepTimerSettings?, + playbackReportInterval: freezed == playbackReportInterval + ? _value.playbackReportInterval + : playbackReportInterval // ignore: cast_nullable_to_non_nullable + as Duration?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$NullablePlayerSettingsImpl implements _NullablePlayerSettings { + const _$NullablePlayerSettingsImpl( + {this.miniPlayerSettings, + this.expandedPlayerSettings, + this.preferredDefaultVolume, + this.preferredDefaultSpeed, + final List? speedOptions, + this.sleepTimerSettings, + this.playbackReportInterval}) + : _speedOptions = speedOptions; + + factory _$NullablePlayerSettingsImpl.fromJson(Map json) => + _$$NullablePlayerSettingsImplFromJson(json); + + @override + final MinimizedPlayerSettings? miniPlayerSettings; + @override + final ExpandedPlayerSettings? expandedPlayerSettings; + @override + final double? preferredDefaultVolume; + @override + final double? preferredDefaultSpeed; + final List? _speedOptions; + @override + List? get speedOptions { + final value = _speedOptions; + if (value == null) return null; + if (_speedOptions is EqualUnmodifiableListView) return _speedOptions; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + final SleepTimerSettings? sleepTimerSettings; + @override + final Duration? playbackReportInterval; + + @override + String toString() { + return 'NullablePlayerSettings(miniPlayerSettings: $miniPlayerSettings, expandedPlayerSettings: $expandedPlayerSettings, preferredDefaultVolume: $preferredDefaultVolume, preferredDefaultSpeed: $preferredDefaultSpeed, speedOptions: $speedOptions, sleepTimerSettings: $sleepTimerSettings, playbackReportInterval: $playbackReportInterval)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$NullablePlayerSettingsImpl && + (identical(other.miniPlayerSettings, miniPlayerSettings) || + other.miniPlayerSettings == miniPlayerSettings) && + (identical(other.expandedPlayerSettings, expandedPlayerSettings) || + other.expandedPlayerSettings == expandedPlayerSettings) && + (identical(other.preferredDefaultVolume, preferredDefaultVolume) || + other.preferredDefaultVolume == preferredDefaultVolume) && + (identical(other.preferredDefaultSpeed, preferredDefaultSpeed) || + other.preferredDefaultSpeed == preferredDefaultSpeed) && + const DeepCollectionEquality() + .equals(other._speedOptions, _speedOptions) && + (identical(other.sleepTimerSettings, sleepTimerSettings) || + other.sleepTimerSettings == sleepTimerSettings) && + (identical(other.playbackReportInterval, playbackReportInterval) || + other.playbackReportInterval == playbackReportInterval)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + miniPlayerSettings, + expandedPlayerSettings, + preferredDefaultVolume, + preferredDefaultSpeed, + const DeepCollectionEquality().hash(_speedOptions), + sleepTimerSettings, + playbackReportInterval); + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$NullablePlayerSettingsImplCopyWith<_$NullablePlayerSettingsImpl> + get copyWith => __$$NullablePlayerSettingsImplCopyWithImpl< + _$NullablePlayerSettingsImpl>(this, _$identity); + + @override + Map toJson() { + return _$$NullablePlayerSettingsImplToJson( + this, + ); + } +} + +abstract class _NullablePlayerSettings implements NullablePlayerSettings { + const factory _NullablePlayerSettings( + {final MinimizedPlayerSettings? miniPlayerSettings, + final ExpandedPlayerSettings? expandedPlayerSettings, + final double? preferredDefaultVolume, + final double? preferredDefaultSpeed, + final List? speedOptions, + final SleepTimerSettings? sleepTimerSettings, + final Duration? playbackReportInterval}) = _$NullablePlayerSettingsImpl; + + factory _NullablePlayerSettings.fromJson(Map json) = + _$NullablePlayerSettingsImpl.fromJson; + + @override + MinimizedPlayerSettings? get miniPlayerSettings; + @override + ExpandedPlayerSettings? get expandedPlayerSettings; + @override + double? get preferredDefaultVolume; + @override + double? get preferredDefaultSpeed; + @override + List? get speedOptions; + @override + SleepTimerSettings? get sleepTimerSettings; + @override + Duration? get playbackReportInterval; + + /// Create a copy of NullablePlayerSettings + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$NullablePlayerSettingsImplCopyWith<_$NullablePlayerSettingsImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/features/per_book_settings/models/nullable_player_settings.g.dart b/lib/features/per_book_settings/models/nullable_player_settings.g.dart new file mode 100644 index 0000000..28eb3bc --- /dev/null +++ b/lib/features/per_book_settings/models/nullable_player_settings.g.dart @@ -0,0 +1,47 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'nullable_player_settings.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$NullablePlayerSettingsImpl _$$NullablePlayerSettingsImplFromJson( + Map json) => + _$NullablePlayerSettingsImpl( + miniPlayerSettings: json['miniPlayerSettings'] == null + ? null + : MinimizedPlayerSettings.fromJson( + json['miniPlayerSettings'] as Map), + expandedPlayerSettings: json['expandedPlayerSettings'] == null + ? null + : ExpandedPlayerSettings.fromJson( + json['expandedPlayerSettings'] as Map), + preferredDefaultVolume: + (json['preferredDefaultVolume'] as num?)?.toDouble(), + preferredDefaultSpeed: + (json['preferredDefaultSpeed'] as num?)?.toDouble(), + speedOptions: (json['speedOptions'] as List?) + ?.map((e) => (e as num).toDouble()) + .toList(), + sleepTimerSettings: json['sleepTimerSettings'] == null + ? null + : SleepTimerSettings.fromJson( + json['sleepTimerSettings'] as Map), + playbackReportInterval: json['playbackReportInterval'] == null + ? null + : Duration( + microseconds: (json['playbackReportInterval'] as num).toInt()), + ); + +Map _$$NullablePlayerSettingsImplToJson( + _$NullablePlayerSettingsImpl instance) => + { + 'miniPlayerSettings': instance.miniPlayerSettings, + 'expandedPlayerSettings': instance.expandedPlayerSettings, + 'preferredDefaultVolume': instance.preferredDefaultVolume, + 'preferredDefaultSpeed': instance.preferredDefaultSpeed, + 'speedOptions': instance.speedOptions, + 'sleepTimerSettings': instance.sleepTimerSettings, + 'playbackReportInterval': instance.playbackReportInterval?.inMicroseconds, + }; diff --git a/lib/features/per_book_settings/providers/book_settings_provider.dart b/lib/features/per_book_settings/providers/book_settings_provider.dart new file mode 100644 index 0000000..ca460b6 --- /dev/null +++ b/lib/features/per_book_settings/providers/book_settings_provider.dart @@ -0,0 +1,57 @@ +import 'package:logging/logging.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:vaani/db/available_boxes.dart'; +import 'package:vaani/features/per_book_settings/models/book_settings.dart' + as model; +import 'package:vaani/features/per_book_settings/models/nullable_player_settings.dart'; + +part 'book_settings_provider.g.dart'; + +final _box = AvailableHiveBoxes.individualBookSettingsBox; + +final _logger = Logger('BookSettingsProvider'); + +model.BookSettings readFromBoxOrCreate(String bookId) { + final foundSettings = _box.get(bookId); + if (foundSettings != null) { + _logger.fine('found book settings for $bookId in box: $foundSettings'); + return foundSettings; + } else { + // create a new settings object + final settings = model.BookSettings( + bookId: bookId, + playerSettings: const NullablePlayerSettings(), + ); + _logger.fine('created new book settings for $bookId: $settings'); + writeToBox(settings); + return settings; + } +} + +void writeToBox(model.BookSettings newSettings) { + _box.put(newSettings.bookId, newSettings); + _logger.fine( + 'wrote book settings for ${newSettings.bookId} to box: $newSettings', + ); +} + +void updateState(model.BookSettings newSettings, {bool force = false}) { + // check if the settings are different + final foundSettings = _box.get(newSettings.bookId); + if (foundSettings == newSettings && !force) { + return; + } + writeToBox(newSettings); +} + +@riverpod +class BookSettings extends _$BookSettings { + @override + model.BookSettings build(String bookId) { + return readFromBoxOrCreate(bookId); + } + + void update(model.BookSettings newSettings, {bool force = false}) { + updateState(newSettings, force: force); + } +} diff --git a/lib/features/per_book_settings/providers/book_settings_provider.g.dart b/lib/features/per_book_settings/providers/book_settings_provider.g.dart new file mode 100644 index 0000000..943bd55 --- /dev/null +++ b/lib/features/per_book_settings/providers/book_settings_provider.g.dart @@ -0,0 +1,174 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'book_settings_provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$bookSettingsHash() => r'b976df954edf98ec6ccb3eb41e9d07dd4a9193eb'; + +/// Copied from Dart SDK +class _SystemHash { + _SystemHash._(); + + static int combine(int hash, int value) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + value); + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); + return hash ^ (hash >> 6); + } + + static int finish(int hash) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); + // ignore: parameter_assignments + hash = hash ^ (hash >> 11); + return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); + } +} + +abstract class _$BookSettings + extends BuildlessAutoDisposeNotifier { + late final String bookId; + + model.BookSettings build( + String bookId, + ); +} + +/// See also [BookSettings]. +@ProviderFor(BookSettings) +const bookSettingsProvider = BookSettingsFamily(); + +/// See also [BookSettings]. +class BookSettingsFamily extends Family { + /// See also [BookSettings]. + const BookSettingsFamily(); + + /// See also [BookSettings]. + BookSettingsProvider call( + String bookId, + ) { + return BookSettingsProvider( + bookId, + ); + } + + @override + BookSettingsProvider getProviderOverride( + covariant BookSettingsProvider provider, + ) { + return call( + provider.bookId, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'bookSettingsProvider'; +} + +/// See also [BookSettings]. +class BookSettingsProvider + extends AutoDisposeNotifierProviderImpl { + /// See also [BookSettings]. + BookSettingsProvider( + String bookId, + ) : this._internal( + () => BookSettings()..bookId = bookId, + from: bookSettingsProvider, + name: r'bookSettingsProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$bookSettingsHash, + dependencies: BookSettingsFamily._dependencies, + allTransitiveDependencies: + BookSettingsFamily._allTransitiveDependencies, + bookId: bookId, + ); + + BookSettingsProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.bookId, + }) : super.internal(); + + final String bookId; + + @override + model.BookSettings runNotifierBuild( + covariant BookSettings notifier, + ) { + return notifier.build( + bookId, + ); + } + + @override + Override overrideWith(BookSettings Function() create) { + return ProviderOverride( + origin: this, + override: BookSettingsProvider._internal( + () => create()..bookId = bookId, + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + bookId: bookId, + ), + ); + } + + @override + AutoDisposeNotifierProviderElement + createElement() { + return _BookSettingsProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is BookSettingsProvider && other.bookId == bookId; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, bookId.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin BookSettingsRef on AutoDisposeNotifierProviderRef { + /// The parameter `bookId` of this provider. + String get bookId; +} + +class _BookSettingsProviderElement + extends AutoDisposeNotifierProviderElement + with BookSettingsRef { + _BookSettingsProviderElement(super.provider); + + @override + String get bookId => (origin as BookSettingsProvider).bookId; +} +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/features/player/view/widgets/player_speed_adjust_button.dart b/lib/features/player/view/widgets/player_speed_adjust_button.dart index c071369..e13d278 100644 --- a/lib/features/player/view/widgets/player_speed_adjust_button.dart +++ b/lib/features/player/view/widgets/player_speed_adjust_button.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:logging/logging.dart'; +import 'package:vaani/features/per_book_settings/providers/book_settings_provider.dart'; import 'package:vaani/features/player/providers/audiobook_player.dart'; import 'package:vaani/features/player/view/player_when_expanded.dart'; import 'package:vaani/features/player/view/widgets/speed_selector.dart'; +import 'package:vaani/settings/app_settings_provider.dart'; final _logger = Logger('PlayerSpeedAdjustButton'); @@ -15,6 +17,9 @@ class PlayerSpeedAdjustButton extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final player = ref.watch(audiobookPlayerProvider); + final bookId = player.book?.libraryItemId ?? '_'; + final bookSettings = ref.watch(bookSettingsProvider(bookId)); + final appSettings = ref.watch(appSettingsProvider); final notifier = ref.watch(audiobookPlayerProvider.notifier); return TextButton( child: Text('${player.speed}x'), @@ -31,6 +36,25 @@ class PlayerSpeedAdjustButton extends HookConsumerWidget { return SpeedSelector( onSpeedSelected: (speed) { notifier.setSpeed(speed); + if (appSettings.playerSettings.configurePlayerForEveryBook) { + ref + .read( + bookSettingsProvider(bookId).notifier, + ) + .update( + bookSettings.copyWith + .playerSettings(preferredDefaultSpeed: speed), + ); + } else { + ref + .read( + appSettingsProvider.notifier, + ) + .update( + appSettings.copyWith + .playerSettings(preferredDefaultSpeed: speed), + ); + } }, ); }, diff --git a/lib/settings/app_settings_provider.dart b/lib/settings/app_settings_provider.dart index 84afd3f..b23d18d 100644 --- a/lib/settings/app_settings_provider.dart +++ b/lib/settings/app_settings_provider.dart @@ -48,7 +48,7 @@ class AppSettings extends _$AppSettings { .themeSettings(isDarkMode: !state.themeSettings.isDarkMode); } - void updateState(model.AppSettings newSettings) { + void update(model.AppSettings newSettings) { state = newSettings; } diff --git a/lib/settings/app_settings_provider.g.dart b/lib/settings/app_settings_provider.g.dart index 88c8b5c..4956783 100644 --- a/lib/settings/app_settings_provider.g.dart +++ b/lib/settings/app_settings_provider.g.dart @@ -6,7 +6,7 @@ part of 'app_settings_provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$appSettingsHash() => r'ab8fa4602242704a71b34dc2bb5dcb0c91092797'; +String _$appSettingsHash() => r'e0e132b782b97f11d9791d4f1e45bf4ee67dd99b'; /// See also [AppSettings]. @ProviderFor(AppSettings) diff --git a/lib/settings/models/app_settings.dart b/lib/settings/models/app_settings.dart index 34dc7e6..0591e9f 100644 --- a/lib/settings/models/app_settings.dart +++ b/lib/settings/models/app_settings.dart @@ -44,6 +44,7 @@ class PlayerSettings with _$PlayerSettings { @Default([0.75, 1, 1.25, 1.5, 1.75, 2]) List speedOptions, @Default(SleepTimerSettings()) SleepTimerSettings sleepTimerSettings, @Default(Duration(seconds: 10)) Duration playbackReportInterval, + @Default(true) bool configurePlayerForEveryBook, }) = _PlayerSettings; factory PlayerSettings.fromJson(Map json) => diff --git a/lib/settings/models/app_settings.freezed.dart b/lib/settings/models/app_settings.freezed.dart index 17311fb..90d2cd2 100644 --- a/lib/settings/models/app_settings.freezed.dart +++ b/lib/settings/models/app_settings.freezed.dart @@ -478,6 +478,7 @@ mixin _$PlayerSettings { SleepTimerSettings get sleepTimerSettings => throw _privateConstructorUsedError; Duration get playbackReportInterval => throw _privateConstructorUsedError; + bool get configurePlayerForEveryBook => throw _privateConstructorUsedError; /// Serializes this PlayerSettings to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -502,7 +503,8 @@ abstract class $PlayerSettingsCopyWith<$Res> { double preferredDefaultSpeed, List speedOptions, SleepTimerSettings sleepTimerSettings, - Duration playbackReportInterval}); + Duration playbackReportInterval, + bool configurePlayerForEveryBook}); $MinimizedPlayerSettingsCopyWith<$Res> get miniPlayerSettings; $ExpandedPlayerSettingsCopyWith<$Res> get expandedPlayerSettings; @@ -531,6 +533,7 @@ class _$PlayerSettingsCopyWithImpl<$Res, $Val extends PlayerSettings> Object? speedOptions = null, Object? sleepTimerSettings = null, Object? playbackReportInterval = null, + Object? configurePlayerForEveryBook = null, }) { return _then(_value.copyWith( miniPlayerSettings: null == miniPlayerSettings @@ -561,6 +564,10 @@ class _$PlayerSettingsCopyWithImpl<$Res, $Val extends PlayerSettings> ? _value.playbackReportInterval : playbackReportInterval // ignore: cast_nullable_to_non_nullable as Duration, + configurePlayerForEveryBook: null == configurePlayerForEveryBook + ? _value.configurePlayerForEveryBook + : configurePlayerForEveryBook // ignore: cast_nullable_to_non_nullable + as bool, ) as $Val); } @@ -613,7 +620,8 @@ abstract class _$$PlayerSettingsImplCopyWith<$Res> double preferredDefaultSpeed, List speedOptions, SleepTimerSettings sleepTimerSettings, - Duration playbackReportInterval}); + Duration playbackReportInterval, + bool configurePlayerForEveryBook}); @override $MinimizedPlayerSettingsCopyWith<$Res> get miniPlayerSettings; @@ -643,6 +651,7 @@ class __$$PlayerSettingsImplCopyWithImpl<$Res> Object? speedOptions = null, Object? sleepTimerSettings = null, Object? playbackReportInterval = null, + Object? configurePlayerForEveryBook = null, }) { return _then(_$PlayerSettingsImpl( miniPlayerSettings: null == miniPlayerSettings @@ -673,6 +682,10 @@ class __$$PlayerSettingsImplCopyWithImpl<$Res> ? _value.playbackReportInterval : playbackReportInterval // ignore: cast_nullable_to_non_nullable as Duration, + configurePlayerForEveryBook: null == configurePlayerForEveryBook + ? _value.configurePlayerForEveryBook + : configurePlayerForEveryBook // ignore: cast_nullable_to_non_nullable + as bool, )); } } @@ -687,7 +700,8 @@ class _$PlayerSettingsImpl implements _PlayerSettings { this.preferredDefaultSpeed = 1, final List speedOptions = const [0.75, 1, 1.25, 1.5, 1.75, 2], this.sleepTimerSettings = const SleepTimerSettings(), - this.playbackReportInterval = const Duration(seconds: 10)}) + this.playbackReportInterval = const Duration(seconds: 10), + this.configurePlayerForEveryBook = true}) : _speedOptions = speedOptions; factory _$PlayerSettingsImpl.fromJson(Map json) => @@ -720,10 +734,13 @@ class _$PlayerSettingsImpl implements _PlayerSettings { @override @JsonKey() final Duration playbackReportInterval; + @override + @JsonKey() + final bool configurePlayerForEveryBook; @override String toString() { - return 'PlayerSettings(miniPlayerSettings: $miniPlayerSettings, expandedPlayerSettings: $expandedPlayerSettings, preferredDefaultVolume: $preferredDefaultVolume, preferredDefaultSpeed: $preferredDefaultSpeed, speedOptions: $speedOptions, sleepTimerSettings: $sleepTimerSettings, playbackReportInterval: $playbackReportInterval)'; + return 'PlayerSettings(miniPlayerSettings: $miniPlayerSettings, expandedPlayerSettings: $expandedPlayerSettings, preferredDefaultVolume: $preferredDefaultVolume, preferredDefaultSpeed: $preferredDefaultSpeed, speedOptions: $speedOptions, sleepTimerSettings: $sleepTimerSettings, playbackReportInterval: $playbackReportInterval, configurePlayerForEveryBook: $configurePlayerForEveryBook)'; } @override @@ -744,7 +761,11 @@ class _$PlayerSettingsImpl implements _PlayerSettings { (identical(other.sleepTimerSettings, sleepTimerSettings) || other.sleepTimerSettings == sleepTimerSettings) && (identical(other.playbackReportInterval, playbackReportInterval) || - other.playbackReportInterval == playbackReportInterval)); + other.playbackReportInterval == playbackReportInterval) && + (identical(other.configurePlayerForEveryBook, + configurePlayerForEveryBook) || + other.configurePlayerForEveryBook == + configurePlayerForEveryBook)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -757,7 +778,8 @@ class _$PlayerSettingsImpl implements _PlayerSettings { preferredDefaultSpeed, const DeepCollectionEquality().hash(_speedOptions), sleepTimerSettings, - playbackReportInterval); + playbackReportInterval, + configurePlayerForEveryBook); /// Create a copy of PlayerSettings /// with the given fields replaced by the non-null parameter values. @@ -784,7 +806,8 @@ abstract class _PlayerSettings implements PlayerSettings { final double preferredDefaultSpeed, final List speedOptions, final SleepTimerSettings sleepTimerSettings, - final Duration playbackReportInterval}) = _$PlayerSettingsImpl; + final Duration playbackReportInterval, + final bool configurePlayerForEveryBook}) = _$PlayerSettingsImpl; factory _PlayerSettings.fromJson(Map json) = _$PlayerSettingsImpl.fromJson; @@ -803,6 +826,8 @@ abstract class _PlayerSettings implements PlayerSettings { SleepTimerSettings get sleepTimerSettings; @override Duration get playbackReportInterval; + @override + bool get configurePlayerForEveryBook; /// Create a copy of PlayerSettings /// with the given fields replaced by the non-null parameter values. diff --git a/lib/settings/models/app_settings.g.dart b/lib/settings/models/app_settings.g.dart index 54d4a80..8986989 100644 --- a/lib/settings/models/app_settings.g.dart +++ b/lib/settings/models/app_settings.g.dart @@ -72,6 +72,8 @@ _$PlayerSettingsImpl _$$PlayerSettingsImplFromJson(Map json) => ? const Duration(seconds: 10) : Duration( microseconds: (json['playbackReportInterval'] as num).toInt()), + configurePlayerForEveryBook: + json['configurePlayerForEveryBook'] as bool? ?? true, ); Map _$$PlayerSettingsImplToJson( @@ -84,6 +86,7 @@ Map _$$PlayerSettingsImplToJson( 'speedOptions': instance.speedOptions, 'sleepTimerSettings': instance.sleepTimerSettings, 'playbackReportInterval': instance.playbackReportInterval.inMicroseconds, + 'configurePlayerForEveryBook': instance.configurePlayerForEveryBook, }; _$ExpandedPlayerSettingsImpl _$$ExpandedPlayerSettingsImplFromJson( diff --git a/lib/settings/view/app_settings_page.dart b/lib/settings/view/app_settings_page.dart index 594ff69..6cf2298 100644 --- a/lib/settings/view/app_settings_page.dart +++ b/lib/settings/view/app_settings_page.dart @@ -65,7 +65,7 @@ class AppSettingsPage extends HookConsumerWidget { ? const Icon(Icons.auto_fix_high) : const Icon(Icons.auto_fix_off), onToggle: (value) { - ref.read(appSettingsProvider.notifier).updateState( + ref.read(appSettingsProvider.notifier).update( appSettings.copyWith.themeSettings( useMaterialThemeOnItemPage: value, ), @@ -114,7 +114,7 @@ class AppSettingsPage extends HookConsumerWidget { Switch( value: sleepTimerSettings.autoTurnOnTimer, onChanged: (value) { - ref.read(appSettingsProvider.notifier).updateState( + ref.read(appSettingsProvider.notifier).update( appSettings.copyWith.playerSettings .sleepTimerSettings( autoTurnOnTimer: value, @@ -208,7 +208,7 @@ class AppSettingsPage extends HookConsumerWidget { ); ref .read(appSettingsProvider.notifier) - .updateState(newSettings); + .update(newSettings); Navigator.of(context).pop(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( diff --git a/lib/settings/view/auto_sleep_timer_settings_page.dart b/lib/settings/view/auto_sleep_timer_settings_page.dart index c92430e..2383ba1 100644 --- a/lib/settings/view/auto_sleep_timer_settings_page.dart +++ b/lib/settings/view/auto_sleep_timer_settings_page.dart @@ -36,7 +36,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { ? const Icon(Icons.timer) : const Icon(Icons.timer_off), onToggle: (value) { - ref.read(appSettingsProvider.notifier).updateState( + ref.read(appSettingsProvider.notifier).update( appSettings.copyWith.playerSettings.sleepTimerSettings( autoTurnOnTimer: value, ), @@ -59,7 +59,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { sleepTimerSettings.autoTurnOnTime.toTimeOfDay(), ); if (selected != null) { - ref.read(appSettingsProvider.notifier).updateState( + ref.read(appSettingsProvider.notifier).update( appSettings.copyWith.playerSettings .sleepTimerSettings( autoTurnOnTime: selected.toDuration(), @@ -87,7 +87,7 @@ class AutoSleepTimerSettingsPage extends HookConsumerWidget { sleepTimerSettings.autoTurnOffTime.toTimeOfDay(), ); if (selected != null) { - ref.read(appSettingsProvider.notifier).updateState( + ref.read(appSettingsProvider.notifier).update( appSettings.copyWith.playerSettings .sleepTimerSettings( autoTurnOffTime: selected.toDuration(),