refactor: better way to determine shelf by id so localisation does not affect it

- more settings
- icons
This commit is contained in:
Dr.Blank 2025-05-22 08:10:56 +05:30
parent 2e3f4ad8d4
commit 5377398e1d
No known key found for this signature in database
GPG key ID: BA5F87FF0560C57B
10 changed files with 364 additions and 280 deletions

View file

@ -6,6 +6,8 @@ import 'package:vaani/api/api_provider.dart';
import 'package:vaani/main.dart';
import 'package:vaani/router/router.dart';
import 'package:vaani/settings/api_settings_provider.dart';
import 'package:vaani/settings/app_settings_provider.dart'
show appSettingsProvider;
import '../shared/widgets/shelves/home_shelf.dart';
@ -17,6 +19,8 @@ class HomePage extends HookConsumerWidget {
final views = ref.watch(personalizedViewProvider);
final apiSettings = ref.watch(apiSettingsProvider);
final scrollController = useScrollController();
final appSettings = ref.watch(appSettingsProvider);
final homePageSettings = appSettings.homePageSettings;
return Scaffold(
appBar: AppBar(
title: GestureDetector(
@ -63,9 +67,21 @@ class HomePage extends HookConsumerWidget {
// .where((element) => !element.id.contains('discover'))
.map((shelf) {
appLogger.fine('building shelf ${shelf.label}');
// check if showPlayButton is enabled for the shelf
// using the id of the shelf
final showPlayButton = switch (shelf.id) {
'continue-listening' =>
homePageSettings.showPlayButtonOnContinueListeningShelf,
'continue-series' =>
homePageSettings.showPlayButtonOnContinueSeriesShelf,
'listen-again' =>
homePageSettings.showPlayButtonOnListenAgainShelf,
_ => homePageSettings.showPlayButtonOnAllRemainingShelves,
};
return HomeShelf(
title: shelf.label,
shelf: shelf,
showPlayButton: showPlayButton,
);
}).toList();
return RefreshIndicator(

View file

@ -53,7 +53,7 @@ class Routes {
parentRoute: settings,
);
static const homePageSettings = _SimpleRoute(
pathName: 'home-page',
pathName: 'homePage',
name: 'homePageSettings',
parentRoute: settings,
);

View file

@ -26,17 +26,6 @@ class AppSettings with _$AppSettings {
_$AppSettingsFromJson(json);
}
@freezed
class HomePageSettings with _$HomePageSettings {
const factory HomePageSettings({
@Default(true) bool showPlayButtonOnContinueShelves,
@Default(false) bool showPlayButtonOnAllShelves,
}) = _HomePageSettings;
factory HomePageSettings.fromJson(Map<String, dynamic> json) =>
_$HomePageSettingsFromJson(json);
}
@freezed
class ThemeSettings with _$ThemeSettings {
const factory ThemeSettings({
@ -242,3 +231,16 @@ enum ShakeAction {
}
enum ShakeDetectedFeedback { vibrate, beep }
@freezed
class HomePageSettings with _$HomePageSettings {
const factory HomePageSettings({
@Default(true) bool showPlayButtonOnContinueListeningShelf,
@Default(false) bool showPlayButtonOnContinueSeriesShelf,
@Default(false) bool showPlayButtonOnAllRemainingShelves,
@Default(false) bool showPlayButtonOnListenAgainShelf,
}) = _HomePageSettings;
factory HomePageSettings.fromJson(Map<String, dynamic> json) =>
_$HomePageSettingsFromJson(json);
}

View file

@ -408,188 +408,6 @@ abstract class _AppSettings implements AppSettings {
throw _privateConstructorUsedError;
}
HomePageSettings _$HomePageSettingsFromJson(Map<String, dynamic> json) {
return _HomePageSettings.fromJson(json);
}
/// @nodoc
mixin _$HomePageSettings {
bool get showPlayButtonOnContinueShelves =>
throw _privateConstructorUsedError;
bool get showPlayButtonOnAllShelves => throw _privateConstructorUsedError;
/// Serializes this HomePageSettings to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$HomePageSettingsCopyWith<HomePageSettings> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomePageSettingsCopyWith<$Res> {
factory $HomePageSettingsCopyWith(
HomePageSettings value, $Res Function(HomePageSettings) then) =
_$HomePageSettingsCopyWithImpl<$Res, HomePageSettings>;
@useResult
$Res call(
{bool showPlayButtonOnContinueShelves, bool showPlayButtonOnAllShelves});
}
/// @nodoc
class _$HomePageSettingsCopyWithImpl<$Res, $Val extends HomePageSettings>
implements $HomePageSettingsCopyWith<$Res> {
_$HomePageSettingsCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? showPlayButtonOnContinueShelves = null,
Object? showPlayButtonOnAllShelves = null,
}) {
return _then(_value.copyWith(
showPlayButtonOnContinueShelves: null == showPlayButtonOnContinueShelves
? _value.showPlayButtonOnContinueShelves
: showPlayButtonOnContinueShelves // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnAllShelves: null == showPlayButtonOnAllShelves
? _value.showPlayButtonOnAllShelves
: showPlayButtonOnAllShelves // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$HomePageSettingsImplCopyWith<$Res>
implements $HomePageSettingsCopyWith<$Res> {
factory _$$HomePageSettingsImplCopyWith(_$HomePageSettingsImpl value,
$Res Function(_$HomePageSettingsImpl) then) =
__$$HomePageSettingsImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{bool showPlayButtonOnContinueShelves, bool showPlayButtonOnAllShelves});
}
/// @nodoc
class __$$HomePageSettingsImplCopyWithImpl<$Res>
extends _$HomePageSettingsCopyWithImpl<$Res, _$HomePageSettingsImpl>
implements _$$HomePageSettingsImplCopyWith<$Res> {
__$$HomePageSettingsImplCopyWithImpl(_$HomePageSettingsImpl _value,
$Res Function(_$HomePageSettingsImpl) _then)
: super(_value, _then);
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? showPlayButtonOnContinueShelves = null,
Object? showPlayButtonOnAllShelves = null,
}) {
return _then(_$HomePageSettingsImpl(
showPlayButtonOnContinueShelves: null == showPlayButtonOnContinueShelves
? _value.showPlayButtonOnContinueShelves
: showPlayButtonOnContinueShelves // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnAllShelves: null == showPlayButtonOnAllShelves
? _value.showPlayButtonOnAllShelves
: showPlayButtonOnAllShelves // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$HomePageSettingsImpl implements _HomePageSettings {
const _$HomePageSettingsImpl(
{this.showPlayButtonOnContinueShelves = true,
this.showPlayButtonOnAllShelves = false});
factory _$HomePageSettingsImpl.fromJson(Map<String, dynamic> json) =>
_$$HomePageSettingsImplFromJson(json);
@override
@JsonKey()
final bool showPlayButtonOnContinueShelves;
@override
@JsonKey()
final bool showPlayButtonOnAllShelves;
@override
String toString() {
return 'HomePageSettings(showPlayButtonOnContinueShelves: $showPlayButtonOnContinueShelves, showPlayButtonOnAllShelves: $showPlayButtonOnAllShelves)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$HomePageSettingsImpl &&
(identical(other.showPlayButtonOnContinueShelves,
showPlayButtonOnContinueShelves) ||
other.showPlayButtonOnContinueShelves ==
showPlayButtonOnContinueShelves) &&
(identical(other.showPlayButtonOnAllShelves,
showPlayButtonOnAllShelves) ||
other.showPlayButtonOnAllShelves ==
showPlayButtonOnAllShelves));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType, showPlayButtonOnContinueShelves, showPlayButtonOnAllShelves);
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$HomePageSettingsImplCopyWith<_$HomePageSettingsImpl> get copyWith =>
__$$HomePageSettingsImplCopyWithImpl<_$HomePageSettingsImpl>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$HomePageSettingsImplToJson(
this,
);
}
}
abstract class _HomePageSettings implements HomePageSettings {
const factory _HomePageSettings(
{final bool showPlayButtonOnContinueShelves,
final bool showPlayButtonOnAllShelves}) = _$HomePageSettingsImpl;
factory _HomePageSettings.fromJson(Map<String, dynamic> json) =
_$HomePageSettingsImpl.fromJson;
@override
bool get showPlayButtonOnContinueShelves;
@override
bool get showPlayButtonOnAllShelves;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$HomePageSettingsImplCopyWith<_$HomePageSettingsImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ThemeSettings _$ThemeSettingsFromJson(Map<String, dynamic> json) {
return _ThemeSettings.fromJson(json);
}
@ -3045,3 +2863,248 @@ abstract class _ShakeDetectionSettings implements ShakeDetectionSettings {
_$$ShakeDetectionSettingsImplCopyWith<_$ShakeDetectionSettingsImpl>
get copyWith => throw _privateConstructorUsedError;
}
HomePageSettings _$HomePageSettingsFromJson(Map<String, dynamic> json) {
return _HomePageSettings.fromJson(json);
}
/// @nodoc
mixin _$HomePageSettings {
bool get showPlayButtonOnContinueListeningShelf =>
throw _privateConstructorUsedError;
bool get showPlayButtonOnContinueSeriesShelf =>
throw _privateConstructorUsedError;
bool get showPlayButtonOnAllRemainingShelves =>
throw _privateConstructorUsedError;
bool get showPlayButtonOnListenAgainShelf =>
throw _privateConstructorUsedError;
/// Serializes this HomePageSettings to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$HomePageSettingsCopyWith<HomePageSettings> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $HomePageSettingsCopyWith<$Res> {
factory $HomePageSettingsCopyWith(
HomePageSettings value, $Res Function(HomePageSettings) then) =
_$HomePageSettingsCopyWithImpl<$Res, HomePageSettings>;
@useResult
$Res call(
{bool showPlayButtonOnContinueListeningShelf,
bool showPlayButtonOnContinueSeriesShelf,
bool showPlayButtonOnAllRemainingShelves,
bool showPlayButtonOnListenAgainShelf});
}
/// @nodoc
class _$HomePageSettingsCopyWithImpl<$Res, $Val extends HomePageSettings>
implements $HomePageSettingsCopyWith<$Res> {
_$HomePageSettingsCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? showPlayButtonOnContinueListeningShelf = null,
Object? showPlayButtonOnContinueSeriesShelf = null,
Object? showPlayButtonOnAllRemainingShelves = null,
Object? showPlayButtonOnListenAgainShelf = null,
}) {
return _then(_value.copyWith(
showPlayButtonOnContinueListeningShelf: null ==
showPlayButtonOnContinueListeningShelf
? _value.showPlayButtonOnContinueListeningShelf
: showPlayButtonOnContinueListeningShelf // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnContinueSeriesShelf: null ==
showPlayButtonOnContinueSeriesShelf
? _value.showPlayButtonOnContinueSeriesShelf
: showPlayButtonOnContinueSeriesShelf // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnAllRemainingShelves: null ==
showPlayButtonOnAllRemainingShelves
? _value.showPlayButtonOnAllRemainingShelves
: showPlayButtonOnAllRemainingShelves // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnListenAgainShelf: null == showPlayButtonOnListenAgainShelf
? _value.showPlayButtonOnListenAgainShelf
: showPlayButtonOnListenAgainShelf // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$HomePageSettingsImplCopyWith<$Res>
implements $HomePageSettingsCopyWith<$Res> {
factory _$$HomePageSettingsImplCopyWith(_$HomePageSettingsImpl value,
$Res Function(_$HomePageSettingsImpl) then) =
__$$HomePageSettingsImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{bool showPlayButtonOnContinueListeningShelf,
bool showPlayButtonOnContinueSeriesShelf,
bool showPlayButtonOnAllRemainingShelves,
bool showPlayButtonOnListenAgainShelf});
}
/// @nodoc
class __$$HomePageSettingsImplCopyWithImpl<$Res>
extends _$HomePageSettingsCopyWithImpl<$Res, _$HomePageSettingsImpl>
implements _$$HomePageSettingsImplCopyWith<$Res> {
__$$HomePageSettingsImplCopyWithImpl(_$HomePageSettingsImpl _value,
$Res Function(_$HomePageSettingsImpl) _then)
: super(_value, _then);
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? showPlayButtonOnContinueListeningShelf = null,
Object? showPlayButtonOnContinueSeriesShelf = null,
Object? showPlayButtonOnAllRemainingShelves = null,
Object? showPlayButtonOnListenAgainShelf = null,
}) {
return _then(_$HomePageSettingsImpl(
showPlayButtonOnContinueListeningShelf: null ==
showPlayButtonOnContinueListeningShelf
? _value.showPlayButtonOnContinueListeningShelf
: showPlayButtonOnContinueListeningShelf // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnContinueSeriesShelf: null ==
showPlayButtonOnContinueSeriesShelf
? _value.showPlayButtonOnContinueSeriesShelf
: showPlayButtonOnContinueSeriesShelf // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnAllRemainingShelves: null ==
showPlayButtonOnAllRemainingShelves
? _value.showPlayButtonOnAllRemainingShelves
: showPlayButtonOnAllRemainingShelves // ignore: cast_nullable_to_non_nullable
as bool,
showPlayButtonOnListenAgainShelf: null == showPlayButtonOnListenAgainShelf
? _value.showPlayButtonOnListenAgainShelf
: showPlayButtonOnListenAgainShelf // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$HomePageSettingsImpl implements _HomePageSettings {
const _$HomePageSettingsImpl(
{this.showPlayButtonOnContinueListeningShelf = true,
this.showPlayButtonOnContinueSeriesShelf = false,
this.showPlayButtonOnAllRemainingShelves = false,
this.showPlayButtonOnListenAgainShelf = false});
factory _$HomePageSettingsImpl.fromJson(Map<String, dynamic> json) =>
_$$HomePageSettingsImplFromJson(json);
@override
@JsonKey()
final bool showPlayButtonOnContinueListeningShelf;
@override
@JsonKey()
final bool showPlayButtonOnContinueSeriesShelf;
@override
@JsonKey()
final bool showPlayButtonOnAllRemainingShelves;
@override
@JsonKey()
final bool showPlayButtonOnListenAgainShelf;
@override
String toString() {
return 'HomePageSettings(showPlayButtonOnContinueListeningShelf: $showPlayButtonOnContinueListeningShelf, showPlayButtonOnContinueSeriesShelf: $showPlayButtonOnContinueSeriesShelf, showPlayButtonOnAllRemainingShelves: $showPlayButtonOnAllRemainingShelves, showPlayButtonOnListenAgainShelf: $showPlayButtonOnListenAgainShelf)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$HomePageSettingsImpl &&
(identical(other.showPlayButtonOnContinueListeningShelf,
showPlayButtonOnContinueListeningShelf) ||
other.showPlayButtonOnContinueListeningShelf ==
showPlayButtonOnContinueListeningShelf) &&
(identical(other.showPlayButtonOnContinueSeriesShelf,
showPlayButtonOnContinueSeriesShelf) ||
other.showPlayButtonOnContinueSeriesShelf ==
showPlayButtonOnContinueSeriesShelf) &&
(identical(other.showPlayButtonOnAllRemainingShelves,
showPlayButtonOnAllRemainingShelves) ||
other.showPlayButtonOnAllRemainingShelves ==
showPlayButtonOnAllRemainingShelves) &&
(identical(other.showPlayButtonOnListenAgainShelf,
showPlayButtonOnListenAgainShelf) ||
other.showPlayButtonOnListenAgainShelf ==
showPlayButtonOnListenAgainShelf));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType,
showPlayButtonOnContinueListeningShelf,
showPlayButtonOnContinueSeriesShelf,
showPlayButtonOnAllRemainingShelves,
showPlayButtonOnListenAgainShelf);
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$HomePageSettingsImplCopyWith<_$HomePageSettingsImpl> get copyWith =>
__$$HomePageSettingsImplCopyWithImpl<_$HomePageSettingsImpl>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$HomePageSettingsImplToJson(
this,
);
}
}
abstract class _HomePageSettings implements HomePageSettings {
const factory _HomePageSettings(
{final bool showPlayButtonOnContinueListeningShelf,
final bool showPlayButtonOnContinueSeriesShelf,
final bool showPlayButtonOnAllRemainingShelves,
final bool showPlayButtonOnListenAgainShelf}) = _$HomePageSettingsImpl;
factory _HomePageSettings.fromJson(Map<String, dynamic> json) =
_$HomePageSettingsImpl.fromJson;
@override
bool get showPlayButtonOnContinueListeningShelf;
@override
bool get showPlayButtonOnContinueSeriesShelf;
@override
bool get showPlayButtonOnAllRemainingShelves;
@override
bool get showPlayButtonOnListenAgainShelf;
/// Create a copy of HomePageSettings
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$HomePageSettingsImplCopyWith<_$HomePageSettingsImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View file

@ -49,23 +49,6 @@ Map<String, dynamic> _$$AppSettingsImplToJson(_$AppSettingsImpl instance) =>
'homePageSettings': instance.homePageSettings,
};
_$HomePageSettingsImpl _$$HomePageSettingsImplFromJson(
Map<String, dynamic> json) =>
_$HomePageSettingsImpl(
showPlayButtonOnContinueShelves:
json['showPlayButtonOnContinueShelves'] as bool? ?? true,
showPlayButtonOnAllShelves:
json['showPlayButtonOnAllShelves'] as bool? ?? false,
);
Map<String, dynamic> _$$HomePageSettingsImplToJson(
_$HomePageSettingsImpl instance) =>
<String, dynamic>{
'showPlayButtonOnContinueShelves':
instance.showPlayButtonOnContinueShelves,
'showPlayButtonOnAllShelves': instance.showPlayButtonOnAllShelves,
};
_$ThemeSettingsImpl _$$ThemeSettingsImplFromJson(Map<String, dynamic> json) =>
_$ThemeSettingsImpl(
themeMode: $enumDecodeNullable(_$ThemeModeEnumMap, json['themeMode']) ??
@ -373,3 +356,29 @@ const _$ShakeDetectedFeedbackEnumMap = {
ShakeDetectedFeedback.vibrate: 'vibrate',
ShakeDetectedFeedback.beep: 'beep',
};
_$HomePageSettingsImpl _$$HomePageSettingsImplFromJson(
Map<String, dynamic> json) =>
_$HomePageSettingsImpl(
showPlayButtonOnContinueListeningShelf:
json['showPlayButtonOnContinueListeningShelf'] as bool? ?? true,
showPlayButtonOnContinueSeriesShelf:
json['showPlayButtonOnContinueSeriesShelf'] as bool? ?? false,
showPlayButtonOnAllRemainingShelves:
json['showPlayButtonOnAllRemainingShelves'] as bool? ?? false,
showPlayButtonOnListenAgainShelf:
json['showPlayButtonOnListenAgainShelf'] as bool? ?? false,
);
Map<String, dynamic> _$$HomePageSettingsImplToJson(
_$HomePageSettingsImpl instance) =>
<String, dynamic>{
'showPlayButtonOnContinueListeningShelf':
instance.showPlayButtonOnContinueListeningShelf,
'showPlayButtonOnContinueSeriesShelf':
instance.showPlayButtonOnContinueSeriesShelf,
'showPlayButtonOnAllRemainingShelves':
instance.showPlayButtonOnAllRemainingShelves,
'showPlayButtonOnListenAgainShelf':
instance.showPlayButtonOnListenAgainShelf,
};

View file

@ -124,7 +124,7 @@ class AppSettingsPage extends HookConsumerWidget {
leading: const Icon(Icons.home_filled),
title: const Text('Home Page Settings'),
description: const Text(
'Customize the home page shelves',
'Customize the home page',
),
onPressed: (context) {
context.pushNamed(Routes.homePageSettings.name);

View file

@ -17,30 +17,79 @@ class HomePageSettingsPage extends HookConsumerWidget {
title: Text('Home Page Settings'),
sections: [
SettingsSection(
title: const Text('Quick Play'),
margin: const EdgeInsetsDirectional.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
tiles: [
SettingsTile.switchTile(
title: const Text('Show play button on continue shelves'),
initialValue:
appSettings.homePageSettings.showPlayButtonOnContinueShelves,
initialValue: appSettings
.homePageSettings.showPlayButtonOnContinueListeningShelf,
title: const Text('Continue Listening'),
leading: const Icon(Icons.play_arrow),
description: const Text(
'Show play button for books in currently listening shelf',
),
onToggle: (value) {
appSettingsNotifier.update(
appSettings.copyWith(
homePageSettings: appSettings.homePageSettings.copyWith(
showPlayButtonOnContinueShelves: value,
showPlayButtonOnContinueListeningShelf: value,
),
),
);
},
),
SettingsTile.switchTile(
title: const Text('Show play button on all shelves'),
initialValue:
appSettings.homePageSettings.showPlayButtonOnAllShelves,
title: const Text('Continue Series'),
leading: const Icon(Icons.play_arrow),
description: const Text(
'Show play button for books in continue series shelf',
),
initialValue: appSettings
.homePageSettings.showPlayButtonOnContinueSeriesShelf,
onToggle: (value) {
appSettingsNotifier.update(
appSettings.copyWith(
homePageSettings: appSettings.homePageSettings.copyWith(
showPlayButtonOnAllShelves: value,
showPlayButtonOnContinueSeriesShelf: value,
),
),
);
},
),
SettingsTile.switchTile(
title: const Text('Other shelves'),
leading: const Icon(Icons.all_inclusive),
description: const Text(
'Show play button for all books in all remaining shelves',
),
initialValue: appSettings
.homePageSettings.showPlayButtonOnAllRemainingShelves,
onToggle: (value) {
appSettingsNotifier.update(
appSettings.copyWith(
homePageSettings: appSettings.homePageSettings.copyWith(
showPlayButtonOnAllRemainingShelves: value,
),
),
);
},
),
SettingsTile.switchTile(
title: const Text('Listen Again'),
leading: const Icon(Icons.replay),
description: const Text(
'Show play button for all books in listen again shelf',
),
initialValue:
appSettings.homePageSettings.showPlayButtonOnListenAgainShelf,
onToggle: (value) {
appSettingsNotifier.update(
appSettings.copyWith(
homePageSettings: appSettings.homePageSettings.copyWith(
showPlayButtonOnListenAgainShelf: value,
),
),
);

View file

@ -25,22 +25,15 @@ class BookHomeShelf extends HookConsumerWidget {
super.key,
required this.shelf,
required this.title,
this.showPlayButton = false,
});
final String title;
final LibraryItemShelf shelf;
final bool showPlayButton;
@override
Widget build(BuildContext context, WidgetRef ref) {
final appSettings = ref.watch(appSettingsProvider);
final homePageSettings = appSettings.homePageSettings;
final bool showPlayButton;
if (title == 'Continue Listening' || title == 'Continue Series') {
showPlayButton = homePageSettings.showPlayButtonOnContinueShelves;
} else {
showPlayButton = homePageSettings.showPlayButtonOnAllShelves;
}
return SimpleHomeShelf(
title: title,

View file

@ -15,10 +15,12 @@ class HomeShelf extends HookConsumerWidget {
super.key,
required this.shelf,
required this.title,
this.showPlayButton = false,
});
final String title;
final Shelf shelf;
final bool showPlayButton;
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -26,6 +28,7 @@ class HomeShelf extends HookConsumerWidget {
ShelfType.book => BookHomeShelf(
title: title,
shelf: shelf.asLibraryItemShelf,
showPlayButton: showPlayButton,
),
ShelfType.authors => AuthorHomeShelf(
title: title,

View file

@ -1,51 +0,0 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:vaani/settings/models/app_settings.dart';
void main() {
group('AppSettings', () {
test('initializes with default HomePageSettings', () {
const appSettings = AppSettings();
expect(appSettings.homePageSettings.showPlayButtonOnContinueShelves, isTrue);
expect(appSettings.homePageSettings.showPlayButtonOnAllShelves, isFalse);
});
test('HomePageSettings can be updated', () {
const initialSettings = AppSettings();
final updatedSettings = initialSettings.copyWith(
homePageSettings: initialSettings.homePageSettings.copyWith(
showPlayButtonOnContinueShelves: false,
showPlayButtonOnAllShelves: true,
),
);
expect(updatedSettings.homePageSettings.showPlayButtonOnContinueShelves, isFalse);
expect(updatedSettings.homePageSettings.showPlayButtonOnAllShelves, isTrue);
});
test('HomePageSettings are correctly serialized and deserialized', () {
const originalSettings = AppSettings(
homePageSettings: HomePageSettings(
showPlayButtonOnContinueShelves: false,
showPlayButtonOnAllShelves: true,
),
);
final json = originalSettings.toJson();
final deserializedSettings = AppSettings.fromJson(json);
expect(deserializedSettings.homePageSettings.showPlayButtonOnContinueShelves, isFalse);
expect(deserializedSettings.homePageSettings.showPlayButtonOnAllShelves, isTrue);
expect(deserializedSettings, originalSettings);
});
test('Default AppSettings serialization and deserialization', () {
const originalSettings = AppSettings();
final json = originalSettings.toJson();
final deserializedSettings = AppSettings.fromJson(json);
expect(deserializedSettings.homePageSettings.showPlayButtonOnContinueShelves, isTrue);
expect(deserializedSettings.homePageSettings.showPlayButtonOnAllShelves, isFalse);
expect(deserializedSettings, originalSettings);
});
});
}