From ea35bdcd97e89998d1cee11fd1cceecec47d27f0 Mon Sep 17 00:00:00 2001 From: yorifuji Date: Sat, 27 Apr 2024 14:15:46 +0900 Subject: [PATCH] refactor: Rename enum and update references --- README.md | 4 ++ lib/app.dart | 3 +- lib/i18n/strings.g.dart | 2 +- lib/repository/preference_repository.dart | 24 ++++----- lib/repository/preference_repository.g.dart | 49 ++++++++++--------- lib/service/video_service.dart | 2 +- lib/service/video_service.g.dart | 2 +- lib/store/app_color_notifier.dart | 5 +- lib/store/app_color_notifier.g.dart | 2 +- lib/store/locale_notifier.dart | 4 +- lib/store/locale_notifier.g.dart | 2 +- lib/store/theme_notifier.dart | 4 +- lib/store/theme_notifier.g.dart | 2 +- lib/store/{ => video}/search_state_store.dart | 0 .../search_state_store.freezed.dart | 0 .../{ => video}/search_state_store.g.dart | 0 lib/ui/favorite/favorite_page.dart | 2 +- lib/ui/settings/settings_page.dart | 5 +- lib/ui/video/search_page.dart | 4 +- lib/ui/walkthrough/walkthrough_page.dart | 3 +- test/golden_test/search_page_golden_test.dart | 2 +- .../settings_page_golden_test.dart | 2 +- 22 files changed, 66 insertions(+), 57 deletions(-) rename lib/store/{ => video}/search_state_store.dart (100%) rename lib/store/{ => video}/search_state_store.freezed.dart (100%) rename lib/store/{ => video}/search_state_store.g.dart (100%) diff --git a/README.md b/README.md index 8d8d85b..e608a6e 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,10 @@ Android および iOS のみ対応、`--dart-define=FLAVOR=...` で切り替え - GitHub Pages - Nightly build +# 素材 + +- https://loosedrawing.com/ + # Related repository - [yorifuji/buzz_recipe_importer](https://github.com/yorifuji/buzz_recipe_importer) diff --git a/lib/app.dart b/lib/app.dart index 37de1b4..b239151 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -29,7 +29,8 @@ class App extends ConsumerWidget { GlobalCupertinoLocalizations.delegate, ], supportedLocales: LocalePreference.supportedLocaleList(), - home: ref.watch(boolPreferenceProvider(BoolKey.shouldShowWalkthrough)) + home: ref.watch( + boolPreferenceProvider(BoolPreferenceKey.shouldShowWalkthrough)) ? const WalkthroughPage() : const NavigationPage(), ), diff --git a/lib/i18n/strings.g.dart b/lib/i18n/strings.g.dart index c841854..f48c709 100644 --- a/lib/i18n/strings.g.dart +++ b/lib/i18n/strings.g.dart @@ -6,7 +6,7 @@ /// Locales: 2 /// Strings: 142 (71 per locale) /// -/// Built on 2024-04-17 at 10:16 UTC +/// Built on 2024-04-27 at 05:12 UTC // coverage:ignore-file // ignore_for_file: type=lint diff --git a/lib/repository/preference_repository.dart b/lib/repository/preference_repository.dart index 01b5fe9..1e066c7 100644 --- a/lib/repository/preference_repository.dart +++ b/lib/repository/preference_repository.dart @@ -4,32 +4,32 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'preference_repository.g.dart'; -enum BoolKey { +enum BoolPreferenceKey { useInternalPlayer('use_internal_player', true), shouldShowWalkthrough('should_show_walkthrough', true), ; // ignore: avoid_positional_boolean_parameters - const BoolKey(this.key, this.defaultValue); + const BoolPreferenceKey(this.key, this.defaultValue); final String key; final bool defaultValue; } -enum IntKey { +enum IntPreferenceKey { themeMode('theme_mode', 0), locale('locale', 0), ; - const IntKey(this.key, this.defaultValue); + const IntPreferenceKey(this.key, this.defaultValue); final String key; final int defaultValue; } -enum StringKey { +enum StringPreferenceKey { appColor('app_color', ''), ; - const StringKey(this.key, this.defaultValue); + const StringPreferenceKey(this.key, this.defaultValue); final String key; final String defaultValue; } @@ -37,7 +37,7 @@ enum StringKey { @riverpod class BoolPreference extends _$BoolPreference { @override - bool build(BoolKey keyValue) => + bool build(BoolPreferenceKey keyValue) => ref.watch(sharedPreferencesProvider).getBool(keyValue.key) ?? keyValue.defaultValue; @@ -51,7 +51,7 @@ class BoolPreference extends _$BoolPreference { @riverpod class IntPreference extends _$IntPreference { @override - int build(IntKey keyValue) => + int build(IntPreferenceKey keyValue) => ref.watch(sharedPreferencesProvider).getInt(keyValue.key) ?? keyValue.defaultValue; @@ -64,7 +64,7 @@ class IntPreference extends _$IntPreference { @riverpod class StringPreference extends _$StringPreference { @override - String build(StringKey keyValue) => + String build(StringPreferenceKey keyValue) => ref.watch(sharedPreferencesProvider).getString(keyValue.key) ?? keyValue.defaultValue; @@ -78,14 +78,14 @@ class FakeTruePreference extends _$BoolPreference with Mock implements BoolPreference { @override - bool build(BoolKey keyValue) => true; + bool build(BoolPreferenceKey keyValue) => true; } class FakeFalsePreference extends _$BoolPreference with Mock implements BoolPreference { @override - bool build(BoolKey keyValue) => false; + bool build(BoolPreferenceKey keyValue) => false; } class FakeIntPreference extends _$IntPreference @@ -96,5 +96,5 @@ class FakeIntPreference extends _$IntPreference // ignore: avoid_public_notifier_properties final int value; @override - int build(IntKey keyValue) => value; + int build(IntPreferenceKey keyValue) => value; } diff --git a/lib/repository/preference_repository.g.dart b/lib/repository/preference_repository.g.dart index 7917426..665e8c9 100644 --- a/lib/repository/preference_repository.g.dart +++ b/lib/repository/preference_repository.g.dart @@ -8,7 +8,7 @@ part of 'preference_repository.dart'; // RiverpodGenerator // ************************************************************************** -String _$boolPreferenceHash() => r'afe11a237008cbbdd4b355ed8abc9c4d653f0db9'; +String _$boolPreferenceHash() => r'c968a3b978f217e59b428e9190853ac291b184bf'; /// Copied from Dart SDK class _SystemHash { @@ -32,10 +32,10 @@ class _SystemHash { } abstract class _$BoolPreference extends BuildlessAutoDisposeNotifier { - late final BoolKey keyValue; + late final BoolPreferenceKey keyValue; bool build( - BoolKey keyValue, + BoolPreferenceKey keyValue, ); } @@ -50,7 +50,7 @@ class BoolPreferenceFamily extends Family { /// See also [BoolPreference]. BoolPreferenceProvider call( - BoolKey keyValue, + BoolPreferenceKey keyValue, ) { return BoolPreferenceProvider( keyValue, @@ -86,7 +86,7 @@ class BoolPreferenceProvider extends AutoDisposeNotifierProviderImpl { /// See also [BoolPreference]. BoolPreferenceProvider( - BoolKey keyValue, + BoolPreferenceKey keyValue, ) : this._internal( () => BoolPreference()..keyValue = keyValue, from: boolPreferenceProvider, @@ -111,7 +111,7 @@ class BoolPreferenceProvider required this.keyValue, }) : super.internal(); - final BoolKey keyValue; + final BoolPreferenceKey keyValue; @override bool runNotifierBuild( @@ -159,7 +159,7 @@ class BoolPreferenceProvider mixin BoolPreferenceRef on AutoDisposeNotifierProviderRef { /// The parameter `keyValue` of this provider. - BoolKey get keyValue; + BoolPreferenceKey get keyValue; } class _BoolPreferenceProviderElement @@ -168,16 +168,16 @@ class _BoolPreferenceProviderElement _BoolPreferenceProviderElement(super.provider); @override - BoolKey get keyValue => (origin as BoolPreferenceProvider).keyValue; + BoolPreferenceKey get keyValue => (origin as BoolPreferenceProvider).keyValue; } -String _$intPreferenceHash() => r'8c68ac08a0eef123dcf477c1dfc4311f8f07f2d0'; +String _$intPreferenceHash() => r'7401b640241cd0d70f271dbed2b798e580bc4fa2'; abstract class _$IntPreference extends BuildlessAutoDisposeNotifier { - late final IntKey keyValue; + late final IntPreferenceKey keyValue; int build( - IntKey keyValue, + IntPreferenceKey keyValue, ); } @@ -192,7 +192,7 @@ class IntPreferenceFamily extends Family { /// See also [IntPreference]. IntPreferenceProvider call( - IntKey keyValue, + IntPreferenceKey keyValue, ) { return IntPreferenceProvider( keyValue, @@ -228,7 +228,7 @@ class IntPreferenceProvider extends AutoDisposeNotifierProviderImpl { /// See also [IntPreference]. IntPreferenceProvider( - IntKey keyValue, + IntPreferenceKey keyValue, ) : this._internal( () => IntPreference()..keyValue = keyValue, from: intPreferenceProvider, @@ -253,7 +253,7 @@ class IntPreferenceProvider required this.keyValue, }) : super.internal(); - final IntKey keyValue; + final IntPreferenceKey keyValue; @override int runNotifierBuild( @@ -301,7 +301,7 @@ class IntPreferenceProvider mixin IntPreferenceRef on AutoDisposeNotifierProviderRef { /// The parameter `keyValue` of this provider. - IntKey get keyValue; + IntPreferenceKey get keyValue; } class _IntPreferenceProviderElement @@ -310,16 +310,16 @@ class _IntPreferenceProviderElement _IntPreferenceProviderElement(super.provider); @override - IntKey get keyValue => (origin as IntPreferenceProvider).keyValue; + IntPreferenceKey get keyValue => (origin as IntPreferenceProvider).keyValue; } -String _$stringPreferenceHash() => r'6581e46aac1cad29ceba82b458b04bbc16226209'; +String _$stringPreferenceHash() => r'933d0fb02cd450274b22eb41164869f018a8a293'; abstract class _$StringPreference extends BuildlessAutoDisposeNotifier { - late final StringKey keyValue; + late final StringPreferenceKey keyValue; String build( - StringKey keyValue, + StringPreferenceKey keyValue, ); } @@ -334,7 +334,7 @@ class StringPreferenceFamily extends Family { /// See also [StringPreference]. StringPreferenceProvider call( - StringKey keyValue, + StringPreferenceKey keyValue, ) { return StringPreferenceProvider( keyValue, @@ -370,7 +370,7 @@ class StringPreferenceProvider extends AutoDisposeNotifierProviderImpl { /// See also [StringPreference]. StringPreferenceProvider( - StringKey keyValue, + StringPreferenceKey keyValue, ) : this._internal( () => StringPreference()..keyValue = keyValue, from: stringPreferenceProvider, @@ -395,7 +395,7 @@ class StringPreferenceProvider required this.keyValue, }) : super.internal(); - final StringKey keyValue; + final StringPreferenceKey keyValue; @override String runNotifierBuild( @@ -443,7 +443,7 @@ class StringPreferenceProvider mixin StringPreferenceRef on AutoDisposeNotifierProviderRef { /// The parameter `keyValue` of this provider. - StringKey get keyValue; + StringPreferenceKey get keyValue; } class _StringPreferenceProviderElement @@ -452,7 +452,8 @@ class _StringPreferenceProviderElement _StringPreferenceProviderElement(super.provider); @override - StringKey get keyValue => (origin as StringPreferenceProvider).keyValue; + StringPreferenceKey get keyValue => + (origin as StringPreferenceProvider).keyValue; } // 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/service/video_service.dart b/lib/service/video_service.dart index 60e2902..938f908 100644 --- a/lib/service/video_service.dart +++ b/lib/service/video_service.dart @@ -2,7 +2,7 @@ import 'package:buzz_recipe_viewer/model/sort_index.dart'; import 'package:buzz_recipe_viewer/provider/flavor_provider.dart'; import 'package:buzz_recipe_viewer/repository/video_repository.dart'; import 'package:buzz_recipe_viewer/repository/video_repository_mock.dart'; -import 'package:buzz_recipe_viewer/store/search_state_store.dart'; +import 'package:buzz_recipe_viewer/store/video/search_state_store.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'video_service.g.dart'; diff --git a/lib/service/video_service.g.dart b/lib/service/video_service.g.dart index 6185540..ea5d540 100644 --- a/lib/service/video_service.g.dart +++ b/lib/service/video_service.g.dart @@ -8,7 +8,7 @@ part of 'video_service.dart'; // RiverpodGenerator // ************************************************************************** -String _$videoServiceHash() => r'355707605438c282fd9ee9cfc674ad493683afc3'; +String _$videoServiceHash() => r'4591e5af695bb412921eb7602d4e9b53b87bf0b2'; /// See also [videoService]. @ProviderFor(videoService) diff --git a/lib/store/app_color_notifier.dart b/lib/store/app_color_notifier.dart index d6d6f70..645e72d 100644 --- a/lib/store/app_color_notifier.dart +++ b/lib/store/app_color_notifier.dart @@ -8,13 +8,14 @@ part 'app_color_notifier.g.dart'; class AppColorNotifer extends _$AppColorNotifer { @override AppColor build() { - final appColor = ref.watch(stringPreferenceProvider(StringKey.appColor)); + final appColor = + ref.watch(stringPreferenceProvider(StringPreferenceKey.appColor)); return AppColor.fromName(appColor); } Future update(AppColor appColor) async { await ref - .read(stringPreferenceProvider(StringKey.appColor).notifier) + .read(stringPreferenceProvider(StringPreferenceKey.appColor).notifier) .update(appColor.name); ref.invalidateSelf(); } diff --git a/lib/store/app_color_notifier.g.dart b/lib/store/app_color_notifier.g.dart index 225fc86..283781d 100644 --- a/lib/store/app_color_notifier.g.dart +++ b/lib/store/app_color_notifier.g.dart @@ -8,7 +8,7 @@ part of 'app_color_notifier.dart'; // RiverpodGenerator // ************************************************************************** -String _$appColorNotiferHash() => r'84c6f3f45fd99904b9fa962bb5758a579d2ff2f5'; +String _$appColorNotiferHash() => r'f60068aac45bcb7f9631e37d551ff33a333567ef'; /// See also [AppColorNotifer]. @ProviderFor(AppColorNotifer) diff --git a/lib/store/locale_notifier.dart b/lib/store/locale_notifier.dart index 935739f..c638f87 100644 --- a/lib/store/locale_notifier.dart +++ b/lib/store/locale_notifier.dart @@ -9,7 +9,7 @@ part 'locale_notifier.g.dart'; class LocaleNotifer extends _$LocaleNotifer { @override LocalePreference build() { - final index = ref.watch(intPreferenceProvider(IntKey.locale)); + final index = ref.watch(intPreferenceProvider(IntPreferenceKey.locale)); final localePreference = LocalePreference.fromIndex(index); _applyLocaleSettings(localePreference); return localePreference; @@ -17,7 +17,7 @@ class LocaleNotifer extends _$LocaleNotifer { Future update(LocalePreference localePreference) async { await ref - .read(intPreferenceProvider(IntKey.locale).notifier) + .read(intPreferenceProvider(IntPreferenceKey.locale).notifier) .update(localePreference.index); ref.invalidateSelf(); } diff --git a/lib/store/locale_notifier.g.dart b/lib/store/locale_notifier.g.dart index 3202120..55c706c 100644 --- a/lib/store/locale_notifier.g.dart +++ b/lib/store/locale_notifier.g.dart @@ -8,7 +8,7 @@ part of 'locale_notifier.dart'; // RiverpodGenerator // ************************************************************************** -String _$localeNotiferHash() => r'793bda9df29531a1158b9364ae761dae0ccd5082'; +String _$localeNotiferHash() => r'e4357e9cbbf6281c4147bb944217b489987d8ee3'; /// See also [LocaleNotifer]. @ProviderFor(LocaleNotifer) diff --git a/lib/store/theme_notifier.dart b/lib/store/theme_notifier.dart index 6b5ebee..ebd8ed2 100644 --- a/lib/store/theme_notifier.dart +++ b/lib/store/theme_notifier.dart @@ -8,13 +8,13 @@ part 'theme_notifier.g.dart'; class ThemeNotifer extends _$ThemeNotifer { @override ThemePreference build() { - final index = ref.watch(intPreferenceProvider(IntKey.themeMode)); + final index = ref.watch(intPreferenceProvider(IntPreferenceKey.themeMode)); return ThemePreference.fromIndex(index); } Future update(ThemePreference themeModePreference) async { await ref - .read(intPreferenceProvider(IntKey.themeMode).notifier) + .read(intPreferenceProvider(IntPreferenceKey.themeMode).notifier) .update(themeModePreference.index); ref.invalidateSelf(); } diff --git a/lib/store/theme_notifier.g.dart b/lib/store/theme_notifier.g.dart index 1f5d5ef..a557012 100644 --- a/lib/store/theme_notifier.g.dart +++ b/lib/store/theme_notifier.g.dart @@ -8,7 +8,7 @@ part of 'theme_notifier.dart'; // RiverpodGenerator // ************************************************************************** -String _$themeNotiferHash() => r'99a0b8cffe3cd83bfac8346e86e02d77c35c3f62'; +String _$themeNotiferHash() => r'92710f2a9cdf1b1dcfc8e190f62602d0df165185'; /// See also [ThemeNotifer]. @ProviderFor(ThemeNotifer) diff --git a/lib/store/search_state_store.dart b/lib/store/video/search_state_store.dart similarity index 100% rename from lib/store/search_state_store.dart rename to lib/store/video/search_state_store.dart diff --git a/lib/store/search_state_store.freezed.dart b/lib/store/video/search_state_store.freezed.dart similarity index 100% rename from lib/store/search_state_store.freezed.dart rename to lib/store/video/search_state_store.freezed.dart diff --git a/lib/store/search_state_store.g.dart b/lib/store/video/search_state_store.g.dart similarity index 100% rename from lib/store/search_state_store.g.dart rename to lib/store/video/search_state_store.g.dart diff --git a/lib/ui/favorite/favorite_page.dart b/lib/ui/favorite/favorite_page.dart index 1c5ccf7..be98082 100644 --- a/lib/ui/favorite/favorite_page.dart +++ b/lib/ui/favorite/favorite_page.dart @@ -81,7 +81,7 @@ class _FavoriteContainer extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final isInternalPlayerAvailable = !kIsWeb && !Platform.isMacOS; final useInternalPlayer = isInternalPlayerAvailable && - ref.watch(boolPreferenceProvider(BoolKey.useInternalPlayer)); + ref.watch(boolPreferenceProvider(BoolPreferenceKey.useInternalPlayer)); return Dismissible( key: UniqueKey(), diff --git a/lib/ui/settings/settings_page.dart b/lib/ui/settings/settings_page.dart index 427878a..eb07cd4 100644 --- a/lib/ui/settings/settings_page.dart +++ b/lib/ui/settings/settings_page.dart @@ -29,7 +29,7 @@ class SettingsPage extends ConsumerWidget { final packageInfo = ref.watch(packageInfoProvider); final isInternalPlayerAvailable = !kIsWeb && !Platform.isMacOS; final useInternalPlayer = isInternalPlayerAvailable && - ref.watch(boolPreferenceProvider(BoolKey.useInternalPlayer)); + ref.watch(boolPreferenceProvider(BoolPreferenceKey.useInternalPlayer)); return Scaffold( appBar: AppBar( @@ -118,7 +118,8 @@ class SettingsPage extends ConsumerWidget { enabled: isInternalPlayerAvailable, onToggle: (value) => ref .read( - boolPreferenceProvider(BoolKey.useInternalPlayer) + boolPreferenceProvider( + BoolPreferenceKey.useInternalPlayer) .notifier, ) .update(value), diff --git a/lib/ui/video/search_page.dart b/lib/ui/video/search_page.dart index 8731003..8e27f71 100644 --- a/lib/ui/video/search_page.dart +++ b/lib/ui/video/search_page.dart @@ -6,7 +6,7 @@ import 'package:buzz_recipe_viewer/model/loading_state.dart'; import 'package:buzz_recipe_viewer/model/sort_index.dart'; import 'package:buzz_recipe_viewer/repository/preference_repository.dart'; import 'package:buzz_recipe_viewer/service/favorite_service.dart'; -import 'package:buzz_recipe_viewer/store/search_state_store.dart'; +import 'package:buzz_recipe_viewer/store/video/search_state_store.dart'; import 'package:buzz_recipe_viewer/ui/common/search_hit/video_image_container.dart'; import 'package:buzz_recipe_viewer/ui/common/search_hit/video_information_container.dart'; import 'package:buzz_recipe_viewer/ui/video/search_view_model.dart'; @@ -88,7 +88,7 @@ class _VideoListContainer extends HookConsumerWidget { ref.watch(searchStateStoreProvider.select((value) => value.nextPage)); final isInternalPlayerAvailable = !kIsWeb && !Platform.isMacOS; final useInternalPlayer = isInternalPlayerAvailable && - ref.watch(boolPreferenceProvider(BoolKey.useInternalPlayer)); + ref.watch(boolPreferenceProvider(BoolPreferenceKey.useInternalPlayer)); if (hitList.isEmpty) { return Center(child: Text(t.common.searchEmpty)); diff --git a/lib/ui/walkthrough/walkthrough_page.dart b/lib/ui/walkthrough/walkthrough_page.dart index 51580bd..4a3448e 100644 --- a/lib/ui/walkthrough/walkthrough_page.dart +++ b/lib/ui/walkthrough/walkthrough_page.dart @@ -36,7 +36,8 @@ class WalkthroughPage extends ConsumerWidget { onDone: () { ref .read( - boolPreferenceProvider(BoolKey.shouldShowWalkthrough).notifier, + boolPreferenceProvider(BoolPreferenceKey.shouldShowWalkthrough) + .notifier, ) .update(false); }, diff --git a/test/golden_test/search_page_golden_test.dart b/test/golden_test/search_page_golden_test.dart index 165ed6f..37a9ea4 100644 --- a/test/golden_test/search_page_golden_test.dart +++ b/test/golden_test/search_page_golden_test.dart @@ -15,7 +15,7 @@ void main() { widget: ProviderScope( overrides: [ searchViewModelProvider.overrideWith(FakeSearchViewModel.new), - boolPreferenceProvider(BoolKey.useInternalPlayer) + boolPreferenceProvider(BoolPreferenceKey.useInternalPlayer) .overrideWith(FakeTruePreference.new), ], child: const SearchPage(), diff --git a/test/golden_test/settings_page_golden_test.dart b/test/golden_test/settings_page_golden_test.dart index fa4a7b2..ec242fe 100644 --- a/test/golden_test/settings_page_golden_test.dart +++ b/test/golden_test/settings_page_golden_test.dart @@ -25,7 +25,7 @@ void main() { buildNumber: '1', ), ), - boolPreferenceProvider(BoolKey.useInternalPlayer) + boolPreferenceProvider(BoolPreferenceKey.useInternalPlayer) .overrideWith(FakeTruePreference.new), themeDataProvider().overrideWith((ref) => ThemeData.light()), themeDataProvider(isDarkMode: true)