From 5c36a20631b88af1dc18c4a4df4de720e82caa23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Sat, 16 Nov 2024 15:17:53 +0100 Subject: [PATCH] Use ActivityParameters widgets from flutter_custom_toolbox --- .../metadata/android/en-US/changelogs/17.txt | 1 + .../metadata/android/fr-FR/changelogs/17.txt | 1 + lib/common/config/activity_page.dart | 38 +++++++++--- lib/config/application_config.dart | 38 +++++++++++- lib/config/default_activity_settings.dart | 28 --------- lib/config/default_global_settings.dart | 28 --------- lib/cubit/activity/activity_cubit.dart | 18 +++--- .../settings/settings_activity_cubit.dart | 61 ------------------- .../settings/settings_activity_state.dart | 15 ----- lib/cubit/settings/settings_global_cubit.dart | 59 ------------------ lib/cubit/settings/settings_global_state.dart | 15 ----- lib/main.dart | 9 +-- lib/models/activity/activity.dart | 18 ++---- lib/models/settings/settings_activity.dart | 42 ------------- lib/models/settings/settings_global.dart | 42 ------------- pubspec.lock | 6 +- pubspec.yaml | 4 +- 17 files changed, 88 insertions(+), 335 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/17.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/17.txt delete mode 100644 lib/config/default_activity_settings.dart delete mode 100644 lib/config/default_global_settings.dart delete mode 100644 lib/cubit/settings/settings_activity_cubit.dart delete mode 100644 lib/cubit/settings/settings_activity_state.dart delete mode 100644 lib/cubit/settings/settings_global_cubit.dart delete mode 100644 lib/cubit/settings/settings_global_state.dart delete mode 100644 lib/models/settings/settings_activity.dart delete mode 100644 lib/models/settings/settings_global.dart diff --git a/fastlane/metadata/android/en-US/changelogs/17.txt b/fastlane/metadata/android/en-US/changelogs/17.txt new file mode 100644 index 0000000..c20ed39 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/17.txt @@ -0,0 +1 @@ +Use ActivityParameters widgets from flutter_custom_toolbox. diff --git a/fastlane/metadata/android/fr-FR/changelogs/17.txt b/fastlane/metadata/android/fr-FR/changelogs/17.txt new file mode 100644 index 0000000..f732ebd --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/17.txt @@ -0,0 +1 @@ +Utilisation des widgets ActivityParameters de flutter_custom_toolbox. diff --git a/lib/common/config/activity_page.dart b/lib/common/config/activity_page.dart index 18354dd..f8bb2d8 100644 --- a/lib/common/config/activity_page.dart +++ b/lib/common/config/activity_page.dart @@ -1,19 +1,21 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; +import 'package:stopmotion/cubit/activity/activity_cubit.dart'; import 'package:stopmotion/common/ui/pages/editor.dart'; import 'package:stopmotion/common/ui/pages/home.dart'; import 'package:stopmotion/common/ui/pages/player.dart'; +import 'package:stopmotion/models/activity/activity.dart'; class ActivityPageItem { final String code; final Icon icon; - final Widget page; + final Widget Function({required Activity currentActivity})? builder; const ActivityPageItem({ required this.code, required this.icon, - required this.page, + required this.builder, }); } @@ -21,27 +23,33 @@ class ActivityPage { static const bool displayBottomNavBar = true; static const indexHome = 0; - static const pageHome = ActivityPageItem( + static final ActivityPageItem pageHome = ActivityPageItem( code: 'page_home', icon: Icon(UniconsLine.home), - page: PageHome(), + builder: ({required Activity currentActivity}) { + return PageHome(); + }, ); static const indexEditor = 1; - static const pageEditor = ActivityPageItem( + static final ActivityPageItem pageEditor = ActivityPageItem( code: 'page_editor', icon: Icon(UniconsLine.setting), - page: PageEditor(), + builder: ({required Activity currentActivity}) { + return PageEditor(); + }, ); static const indexPlayer = 2; - static const pagePlayer = ActivityPageItem( + static final ActivityPageItem pagePlayer = ActivityPageItem( code: 'page_player', icon: Icon(UniconsLine.info_circle), - page: PagePlayer(), + builder: ({required Activity currentActivity}) { + return PagePlayer(); + }, ); - static const Map<int, ActivityPageItem> items = { + static final Map<int, ActivityPageItem> items = { indexHome: pageHome, indexEditor: pageEditor, indexPlayer: pagePlayer, @@ -54,6 +62,16 @@ class ActivityPage { } static Widget getWidget(int pageIndex) { - return items[pageIndex]?.page ?? pageHome.page; + return BlocBuilder<ActivityCubit, ActivityState>( + builder: (BuildContext context, ActivityState activityState) { + final Activity currentActivity = activityState.currentActivity; + + if (items.keys.contains(pageIndex)) { + return items[pageIndex]?.builder!(currentActivity: currentActivity) ?? Text('oups'); + } else { + return getWidget(defaultPageIndex); + } + }, + ); } } diff --git a/lib/config/application_config.dart b/lib/config/application_config.dart index 563f237..79a06f9 100644 --- a/lib/config/application_config.dart +++ b/lib/config/application_config.dart @@ -1,3 +1,39 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; + +import 'package:stopmotion/common/cubit/nav/nav_cubit_pages.dart'; + +import 'package:stopmotion/cubit/activity/activity_cubit.dart'; + class ApplicationConfig { - static const String appTitle = 'Stop Motion'; + static const String parameterCodeMovieType = 'activity.movieType'; + + static const String movieTypeValueDefault = 'default'; + + static final ApplicationConfigDefinition config = ApplicationConfigDefinition( + appTitle: 'Stop Motion', + activitySettings: [ + // movie type + ApplicationSettingsParameter( + code: parameterCodeMovieType, + values: [ + ApplicationSettingsParameterItemValue( + value: movieTypeValueDefault, + isDefault: true, + ), + ], + ), + ], + startNewActivity: (BuildContext context) { + BlocProvider.of<ActivityCubit>(context).startNewActivity(context); + BlocProvider.of<NavCubitPage>(context).goToPageHome(); + }, + deleteCurrentActivity: (BuildContext context) { + BlocProvider.of<ActivityCubit>(context).deleteSavedActivity(); + }, + resumeActivity: (BuildContext context) { + BlocProvider.of<ActivityCubit>(context).resumeSavedActivity(); + BlocProvider.of<NavCubitPage>(context).goToPageHome(); + }, + ); } diff --git a/lib/config/default_activity_settings.dart b/lib/config/default_activity_settings.dart deleted file mode 100644 index 601c1a0..0000000 --- a/lib/config/default_activity_settings.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -class DefaultActivitySettings { - // available activity parameters codes - static const String parameterCodeMovieType = 'movieType'; - static const List<String> availableParameters = [ - parameterCodeMovieType, - ]; - - // items count: available values - static const String movieTypeValueDefault = 'default'; - static const List<String> allowedMovieTypeValues = [ - movieTypeValueDefault, - ]; - // items count: default value - static const String defaultMovieTypeValue = movieTypeValueDefault; - - // available values from parameter code - static List<String> getAvailableValues(String parameterCode) { - switch (parameterCode) { - case parameterCodeMovieType: - return DefaultActivitySettings.allowedMovieTypeValues; - } - - printlog('Did not find any available value for activity parameter "$parameterCode".'); - return []; - } -} diff --git a/lib/config/default_global_settings.dart b/lib/config/default_global_settings.dart deleted file mode 100644 index d92229c..0000000 --- a/lib/config/default_global_settings.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -class DefaultGlobalSettings { - // available global parameters codes - static const String parameterCodeSkin = 'skin'; - static const List<String> availableParameters = [ - parameterCodeSkin, - ]; - - // skin: available values - static const String skinValueDefault = 'default'; - static const List<String> allowedSkinValues = [ - skinValueDefault, - ]; - // skin: default value - static const String defaultSkinValue = skinValueDefault; - - // available values from parameter code - static List<String> getAvailableValues(String parameterCode) { - switch (parameterCode) { - case parameterCodeSkin: - return DefaultGlobalSettings.allowedSkinValues; - } - - printlog('Did not find any available value for global parameter "$parameterCode".'); - return []; - } -} diff --git a/lib/cubit/activity/activity_cubit.dart b/lib/cubit/activity/activity_cubit.dart index 640d9c5..95e5086 100644 --- a/lib/cubit/activity/activity_cubit.dart +++ b/lib/cubit/activity/activity_cubit.dart @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:stopmotion/models/activity/activity.dart'; -import 'package:stopmotion/models/settings/settings_activity.dart'; -import 'package:stopmotion/models/settings/settings_global.dart'; part 'activity_state.dart'; @@ -23,7 +21,6 @@ class ActivityCubit extends HydratedCubit<ActivityState> { final Activity activity = Activity( // Settings activitySettings: state.currentActivity.activitySettings, - globalSettings: state.currentActivity.globalSettings, // State isRunning: state.currentActivity.isRunning, isStarted: state.currentActivity.isStarted, @@ -39,14 +36,13 @@ class ActivityCubit extends HydratedCubit<ActivityState> { updateState(activity); } - void startNewActivity({ - required ActivitySettings activitySettings, - required GlobalSettings globalSettings, - }) { + void startNewActivity(BuildContext context) { + final ActivitySettingsCubit activitySettingsCubit = + BlocProvider.of<ActivitySettingsCubit>(context); + final Activity newActivity = Activity.createNew( // Settings - activitySettings: activitySettings, - globalSettings: globalSettings, + activitySettings: activitySettingsCubit.state.settings, ); newActivity.dump(); @@ -55,6 +51,10 @@ class ActivityCubit extends HydratedCubit<ActivityState> { refresh(); } + bool canBeResumed() { + return state.currentActivity.canBeResumed; + } + void quitActivity() { state.currentActivity.isRunning = false; refresh(); diff --git a/lib/cubit/settings/settings_activity_cubit.dart b/lib/cubit/settings/settings_activity_cubit.dart deleted file mode 100644 index 64570f7..0000000 --- a/lib/cubit/settings/settings_activity_cubit.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -import 'package:stopmotion/config/default_activity_settings.dart'; -import 'package:stopmotion/models/settings/settings_activity.dart'; - -part 'settings_activity_state.dart'; - -class ActivitySettingsCubit extends HydratedCubit<ActivitySettingsState> { - ActivitySettingsCubit() - : super(ActivitySettingsState(settings: ActivitySettings.createDefault())); - - void setValues({ - String? movieType, - }) { - emit( - ActivitySettingsState( - settings: ActivitySettings( - movieType: movieType ?? state.settings.movieType, - ), - ), - ); - } - - String getParameterValue(String code) { - switch (code) { - case DefaultActivitySettings.parameterCodeMovieType: - return ActivitySettings.getMovieTypeValueFromUnsafe(state.settings.movieType); - } - - return ''; - } - - void setParameterValue(String code, String value) { - final String movieType = code == DefaultActivitySettings.parameterCodeMovieType - ? value - : getParameterValue(DefaultActivitySettings.parameterCodeMovieType); - - setValues( - movieType: movieType, - ); - } - - @override - ActivitySettingsState? fromJson(Map<String, dynamic> json) { - final String movieType = json[DefaultActivitySettings.parameterCodeMovieType] as String; - - return ActivitySettingsState( - settings: ActivitySettings( - movieType: movieType, - ), - ); - } - - @override - Map<String, dynamic>? toJson(ActivitySettingsState state) { - return <String, dynamic>{ - DefaultActivitySettings.parameterCodeMovieType: state.settings.movieType, - }; - } -} diff --git a/lib/cubit/settings/settings_activity_state.dart b/lib/cubit/settings/settings_activity_state.dart deleted file mode 100644 index 2b2de42..0000000 --- a/lib/cubit/settings/settings_activity_state.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'settings_activity_cubit.dart'; - -@immutable -class ActivitySettingsState extends Equatable { - const ActivitySettingsState({ - required this.settings, - }); - - final ActivitySettings settings; - - @override - List<dynamic> get props => <dynamic>[ - settings, - ]; -} diff --git a/lib/cubit/settings/settings_global_cubit.dart b/lib/cubit/settings/settings_global_cubit.dart deleted file mode 100644 index 428571c..0000000 --- a/lib/cubit/settings/settings_global_cubit.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -import 'package:stopmotion/config/default_global_settings.dart'; -import 'package:stopmotion/models/settings/settings_global.dart'; - -part 'settings_global_state.dart'; - -class GlobalSettingsCubit extends HydratedCubit<GlobalSettingsState> { - GlobalSettingsCubit() : super(GlobalSettingsState(settings: GlobalSettings.createDefault())); - - void setValues({ - String? skin, - }) { - emit( - GlobalSettingsState( - settings: GlobalSettings( - skin: skin ?? state.settings.skin, - ), - ), - ); - } - - String getParameterValue(String code) { - switch (code) { - case DefaultGlobalSettings.parameterCodeSkin: - return GlobalSettings.getSkinValueFromUnsafe(state.settings.skin); - } - return ''; - } - - void setParameterValue(String code, String value) { - final String skin = (code == DefaultGlobalSettings.parameterCodeSkin) - ? value - : getParameterValue(DefaultGlobalSettings.parameterCodeSkin); - - setValues( - skin: skin, - ); - } - - @override - GlobalSettingsState? fromJson(Map<String, dynamic> json) { - final String skin = json[DefaultGlobalSettings.parameterCodeSkin] as String; - - return GlobalSettingsState( - settings: GlobalSettings( - skin: skin, - ), - ); - } - - @override - Map<String, dynamic>? toJson(GlobalSettingsState state) { - return <String, dynamic>{ - DefaultGlobalSettings.parameterCodeSkin: state.settings.skin, - }; - } -} diff --git a/lib/cubit/settings/settings_global_state.dart b/lib/cubit/settings/settings_global_state.dart deleted file mode 100644 index ebcddd7..0000000 --- a/lib/cubit/settings/settings_global_state.dart +++ /dev/null @@ -1,15 +0,0 @@ -part of 'settings_global_cubit.dart'; - -@immutable -class GlobalSettingsState extends Equatable { - const GlobalSettingsState({ - required this.settings, - }); - - final GlobalSettings settings; - - @override - List<dynamic> get props => <dynamic>[ - settings, - ]; -} diff --git a/lib/main.dart b/lib/main.dart index 142d8a0..514ea89 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,8 +9,6 @@ import 'package:stopmotion/common/cubit/nav/nav_cubit_screens.dart'; import 'package:stopmotion/config/application_config.dart'; import 'package:stopmotion/cubit/activity/activity_cubit.dart'; -import 'package:stopmotion/cubit/settings/settings_activity_cubit.dart'; -import 'package:stopmotion/cubit/settings/settings_global_cubit.dart'; import 'package:stopmotion/ui/skeleton.dart'; void main() async { @@ -56,17 +54,14 @@ class MyApp extends StatelessWidget { BlocProvider<ActivityCubit>( create: (context) => ActivityCubit(), ), - BlocProvider<GlobalSettingsCubit>( - create: (context) => GlobalSettingsCubit(), - ), BlocProvider<ActivitySettingsCubit>( - create: (context) => ActivitySettingsCubit(), + create: (context) => ActivitySettingsCubit(appConfig: ApplicationConfig.config), ), ], child: BlocBuilder<ApplicationThemeModeCubit, ApplicationThemeModeState>( builder: (BuildContext context, ApplicationThemeModeState state) { return MaterialApp( - title: ApplicationConfig.appTitle, + title: ApplicationConfig.config.appTitle, home: const SkeletonScreen(), // Theme stuff diff --git a/lib/models/activity/activity.dart b/lib/models/activity/activity.dart index b668028..41052fd 100644 --- a/lib/models/activity/activity.dart +++ b/lib/models/activity/activity.dart @@ -1,14 +1,13 @@ import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; +import 'package:stopmotion/config/application_config.dart'; + import 'package:stopmotion/models/data/picture.dart'; -import 'package:stopmotion/models/settings/settings_activity.dart'; -import 'package:stopmotion/models/settings/settings_global.dart'; class Activity { Activity({ // Settings required this.activitySettings, - required this.globalSettings, // State this.isRunning = false, @@ -25,7 +24,6 @@ class Activity { // Settings final ActivitySettings activitySettings; - final GlobalSettings globalSettings; // State bool isRunning; @@ -42,8 +40,7 @@ class Activity { factory Activity.createNull() { return Activity( // Settings - activitySettings: ActivitySettings.createDefault(), - globalSettings: GlobalSettings.createDefault(), + activitySettings: ActivitySettings.createDefault(appConfig: ApplicationConfig.config), // Base data pictures: [], ); @@ -51,16 +48,13 @@ class Activity { factory Activity.createNew({ ActivitySettings? activitySettings, - GlobalSettings? globalSettings, }) { - final ActivitySettings newActivitySettings = - activitySettings ?? ActivitySettings.createDefault(); - final GlobalSettings newGlobalSettings = globalSettings ?? GlobalSettings.createDefault(); + final ActivitySettings newActivitySettings = activitySettings ?? + ActivitySettings.createDefault(appConfig: ApplicationConfig.config); return Activity( // Settings activitySettings: newActivitySettings, - globalSettings: newGlobalSettings, // State isRunning: true, // Base data @@ -77,7 +71,6 @@ class Activity { printlog('$Activity:'); printlog(' Settings'); activitySettings.dump(); - globalSettings.dump(); printlog(' State'); printlog(' isRunning: $isRunning'); printlog(' isStarted: $isStarted'); @@ -99,7 +92,6 @@ class Activity { return <String, dynamic>{ // Settings 'activitySettings': activitySettings.toJson(), - 'globalSettings': globalSettings.toJson(), // State 'isRunning': isRunning, 'isStarted': isStarted, diff --git a/lib/models/settings/settings_activity.dart b/lib/models/settings/settings_activity.dart deleted file mode 100644 index d1664eb..0000000 --- a/lib/models/settings/settings_activity.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -import 'package:stopmotion/config/default_activity_settings.dart'; - -class ActivitySettings { - final String movieType; - - ActivitySettings({ - required this.movieType, - }); - - static String getMovieTypeValueFromUnsafe(String movieType) { - if (DefaultActivitySettings.allowedMovieTypeValues.contains(movieType)) { - return movieType; - } - - return DefaultActivitySettings.defaultMovieTypeValue; - } - - factory ActivitySettings.createDefault() { - return ActivitySettings( - movieType: DefaultActivitySettings.defaultMovieTypeValue, - ); - } - - void dump() { - printlog('$ActivitySettings:'); - printlog(' ${DefaultActivitySettings.parameterCodeMovieType}: $movieType'); - printlog(''); - } - - @override - String toString() { - return '$ActivitySettings(${toJson()})'; - } - - Map<String, dynamic>? toJson() { - return <String, dynamic>{ - DefaultActivitySettings.parameterCodeMovieType: movieType, - }; - } -} diff --git a/lib/models/settings/settings_global.dart b/lib/models/settings/settings_global.dart deleted file mode 100644 index fb2c3fd..0000000 --- a/lib/models/settings/settings_global.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; - -import 'package:stopmotion/config/default_global_settings.dart'; - -class GlobalSettings { - String skin; - - GlobalSettings({ - required this.skin, - }); - - static String getSkinValueFromUnsafe(String skin) { - if (DefaultGlobalSettings.allowedSkinValues.contains(skin)) { - return skin; - } - - return DefaultGlobalSettings.defaultSkinValue; - } - - factory GlobalSettings.createDefault() { - return GlobalSettings( - skin: DefaultGlobalSettings.defaultSkinValue, - ); - } - - void dump() { - printlog('$GlobalSettings:'); - printlog(' ${DefaultGlobalSettings.parameterCodeSkin}: $skin'); - printlog(''); - } - - @override - String toString() { - return '$GlobalSettings(${toJson()})'; - } - - Map<String, dynamic>? toJson() { - return <String, dynamic>{ - DefaultGlobalSettings.parameterCodeSkin: skin, - }; - } -} diff --git a/pubspec.lock b/pubspec.lock index 9bbb961..8e27905 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -170,11 +170,11 @@ packages: dependency: "direct main" description: path: "." - ref: "0.4.0" - resolved-ref: eb9c090bd00d73324eab8737f74b3339cc24c9e8 + ref: "0.5.0" + resolved-ref: b8164a50489ba981ea57d9f02e2334f09cb8c6a7 url: "https://git.harrault.fr/android/flutter-toolbox.git" source: git - version: "0.4.0" + version: "0.5.0" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9bfe868..17547f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: stop motion assistant publish_to: "none" -version: 0.3.2+16 +version: 0.4.0+17 environment: sdk: "^3.0.0" @@ -16,7 +16,7 @@ dependencies: flutter_custom_toolbox: git: url: https://git.harrault.fr/android/flutter-toolbox.git - ref: 0.4.0 + ref: 0.5.0 # specific camera: ^0.11.0+1 -- GitLab