From d2889e49a454a2c09a37ff83e4f96b073574d03b Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Wed, 7 Feb 2024 20:16:01 +0200 Subject: [PATCH 1/2] Folding scenes to folders by area --- lib/presentation/pages/add_new_area_page.dart | 10 ++++-- .../pages/home_page/home_page.dart | 4 +-- .../scenes_in_folders_tab.dart | 34 +++++++++---------- lib/presentation/pages/splash_page.dart | 24 +++---------- 4 files changed, 31 insertions(+), 41 deletions(-) rename lib/presentation/pages/home_page/tabs/{scenes_in_folders_tab => }/scenes_in_folders_tab.dart (82%) diff --git a/lib/presentation/pages/add_new_area_page.dart b/lib/presentation/pages/add_new_area_page.dart index c1fc037f..a3da0f49 100644 --- a/lib/presentation/pages/add_new_area_page.dart +++ b/lib/presentation/pages/add_new_area_page.dart @@ -93,6 +93,12 @@ class _AddNewAreaFormState extends State { Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; + final List purposesList = + List.from(AreaPurposesTypes.values); + + purposesList + .removeWhere((element) => element == AreaPurposesTypes.undefined); + return MarginedExpandedAtom( child: Column( children: [ @@ -133,8 +139,8 @@ class _AddNewAreaFormState extends State { cancelText: const Text('CANCEL').tr(), confirmText: const Text('OK').tr(), title: const TextAtom('Select'), - items: AreaPurposesTypes.values - .map((AreaPurposesTypes areaPurposeType) { + items: + purposesList.map((AreaPurposesTypes areaPurposeType) { final String tempAreaName = areaPurposeType.name .substring(1, areaPurposeType.name.length); String areaNameEdited = diff --git a/lib/presentation/pages/home_page/home_page.dart b/lib/presentation/pages/home_page/home_page.dart index 47c75d59..efbca16e 100644 --- a/lib/presentation/pages/home_page/home_page.dart +++ b/lib/presentation/pages/home_page/home_page.dart @@ -7,7 +7,7 @@ import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; -import 'package:cybearjinni/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart'; +import 'package:cybearjinni/presentation/pages/home_page/tabs/scenes_in_folders_tab.dart'; import 'package:cybearjinni/presentation/pages/home_page/tabs/smart_devices_tab/entities_by_area_tab.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -197,7 +197,7 @@ class _HomePageState extends State { }, controller: _pageController, children: [ - ScenesInFoldersTab(scenes), + ScenesInFoldersTab(areas: areas, scenes: scenes), EntitiesByAreaTab(areas: areas!, entities: entities!), // BindingsPage(), ], diff --git a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab.dart similarity index 82% rename from lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart rename to lib/presentation/pages/home_page/tabs/scenes_in_folders_tab.dart index dce8ec8f..8f55ca37 100644 --- a/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab/scenes_in_folders_tab.dart +++ b/lib/presentation/pages/home_page/tabs/scenes_in_folders_tab.dart @@ -9,8 +9,10 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class ScenesInFoldersTab extends StatelessWidget { - const ScenesInFoldersTab(this.scenes); + const ScenesInFoldersTab({required this.scenes, this.areas}); + final HashMap? scenes; + final HashMap? areas; Widget scenesFoldersWidget( BuildContext context, @@ -88,6 +90,7 @@ class ScenesInFoldersTab extends StatelessWidget { ), ); } + areas!.removeWhere((key, value) => value.scenesId.getOrCrash().isEmpty); return Column( children: [ @@ -97,25 +100,20 @@ class ScenesInFoldersTab extends StatelessWidget { leftIconFunction: (BuildContext context) {}, ), Expanded( - child: ScenesGridMolecule( - scenes: scenes!.values.toList(), + child: ListView.builder( + reverse: true, + padding: EdgeInsets.zero, + itemBuilder: (context, index) { + final AreaEntity sceneFolder = areas!.values.elementAt(index); + + return scenesFoldersWidget( + context, + sceneFolder, + ); + }, + itemCount: areas!.length, ), ), - // TODO: Code for room folders - // Expanded( - // child: ListView.builder( - // reverse: true, - // padding: EdgeInsets.zero, - // itemBuilder: (context, index) { - // final AreaEntity sceneFolder = scenes![index]; - // return scenesFoldersWidget( - // context, - // sceneFolder, - // ); - // }, - // itemCount: allAreasWithScenes!.length, - // ), - // ), ], ); } diff --git a/lib/presentation/pages/splash_page.dart b/lib/presentation/pages/splash_page.dart index 79487910..28ea0a1c 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -12,7 +12,6 @@ import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; import 'package:hive_flutter/hive_flutter.dart'; @RoutePage() @@ -74,24 +73,11 @@ class _SplashPageState extends State { @override Widget build(BuildContext context) { - return Scaffold( - body: Container( - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.centerRight, - end: Alignment.centerLeft, - stops: const [0.06, 0.9], - colors: [ - HexColor('#ca6ce3'), - HexColor('#aa5fe4'), - ], - ), - ), - child: const Center( - child: ImageAtom( - 'assets/cbj_logo.png', - hero: 'full_logo', - ), + return const Scaffold( + body: Center( + child: ImageAtom( + 'assets/cbj_logo.png', + hero: 'full_logo', ), ), ); From 40b3581a5c2e87c54315660b437eb3183863f822 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sat, 10 Feb 2024 15:08:34 +0200 Subject: [PATCH 2/2] You can now add value to scenes --- lib/presentation/core/ad_state.dart | 29 -- .../organisms/empty_open_area_organism.dart | 4 +- lib/presentation/pages/add_action_page.dart | 319 ++++++++++-------- lib/presentation/pages/add_binding_page.dart | 15 +- lib/presentation/pages/add_new_area_page.dart | 3 - .../choose_device_vendor_to_add_page.dart | 5 +- .../widgets/vendor_widget.dart | 1 - lib/presentation/pages/add_routine_page.dart | 15 +- lib/presentation/pages/add_scene_page.dart | 80 ++--- 9 files changed, 223 insertions(+), 248 deletions(-) delete mode 100644 lib/presentation/core/ad_state.dart diff --git a/lib/presentation/core/ad_state.dart b/lib/presentation/core/ad_state.dart deleted file mode 100644 index aaa7edf5..00000000 --- a/lib/presentation/core/ad_state.dart +++ /dev/null @@ -1,29 +0,0 @@ -// import 'dart:io'; - -// import 'package:cybearjinni/infrastructure/core/logger.dart'; -// import 'package:google_mobile_ads/google_mobile_ads.dart'; - -// class AdState { -// AdState(this.initialization); - -// Future initialization; - -// String get bannerAdUnitId => Platform.isAndroid -// ? 'ca-app-pub-3940256099942544/6300978111' -// : 'ca-app-pub-3940256099942544/2934735716'; - -// BannerAdListener get adListener => _adListener; - -// final BannerAdListener _adListener = AdManagerBannerAdListener( -// onAdLoaded: (ad) => logger.t('Ad loaded: ${ad.adUnitId}.'), -// onAdClosed: (ad) => logger.t('Ad closed: ${ad.adUnitId}.'), -// onAdFailedToLoad: (ad, error) => -// logger.t('Ad failed to load: ${ad.adUnitId}, $error.'), -// onAdOpened: (ad) => logger.t('Ad opened: ${ad.adUnitId}.'), -// onAppEvent: (ad, name, data) => -// logger.t('App event: ${ad.adUnitId}, $name, $data'), -// onAdImpression: (ad) => logger.t('Ad impression: ${ad.adUnitId}.'), -// onAdWillDismissScreen: (ad) => -// logger.t('Ad dismiss screen: ${ad.adUnitId}.'), -// ); -// } diff --git a/lib/presentation/organisms/empty_open_area_organism.dart b/lib/presentation/organisms/empty_open_area_organism.dart index 9e102753..e3d46273 100644 --- a/lib/presentation/organisms/empty_open_area_organism.dart +++ b/lib/presentation/organisms/empty_open_area_organism.dart @@ -19,9 +19,7 @@ class EmptyOpenAreaOrganism extends StatelessWidget { ), ), TextButton( - onPressed: () { - context.router.pop(); - }, + onPressed: context.router.pop, child: TextAtom( 'No device found', style: TextStyle( diff --git a/lib/presentation/pages/add_action_page.dart b/lib/presentation/pages/add_action_page.dart index fbeb3d55..9cdcbd27 100644 --- a/lib/presentation/pages/add_action_page.dart +++ b/lib/presentation/pages/add_action_page.dart @@ -7,7 +7,7 @@ import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/organisms/organisms.dart'; import 'package:flutter/material.dart'; -@RoutePage() +@RoutePage() class AddActionPage extends StatefulWidget { const AddActionPage({required this.entities}); @@ -21,6 +21,9 @@ class _AddActionPageState extends State { DeviceEntityBase? selectedEntity; EntityProperties? selectedProperty; EntityActions? selectedAction; + String? fieldValues; + ActionValues? actionType; + String? actionValue; void onEntitySelect(String entityId) { setState(() { @@ -40,160 +43,194 @@ class _AddActionPageState extends State { }); } + void onSelectedActionType(String value) { + setState(() { + actionType = ActionValues.values.elementAt(int.parse(value)); + }); + } + @override Widget build(BuildContext context) { return PageOrganism( pageName: 'Add Action', - child: SingleChildScrollView( - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 10), - child: Column( - children: [ - const SizedBox( - height: 30, - ), - const SizedBox( - height: 70, - ), - const Row( - children: [ - TextAtom( - 'Choose Action', - style: TextStyle(fontSize: 27), - ), - ], - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - selectedEntity?.cbjEntityName.getOrCrash() ?? 'Choose Entity', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 10), + child: Column( + children: [ + const SeparatorAtom(), + const Row( + children: [ + TextAtom( + 'Choose Action', + style: TextStyle(fontSize: 27), ), - onChanged: (value) => onEntitySelect(value!), - items: - widget.entities.values.map>((e) { - return DropdownMenuItem( - value: e.getCbjEntityId, - child: TextAtom(e.cbjEntityName.getOrCrash()!), - ); - }).toList(), - ), - const SizedBox( - height: 40, - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - selectedProperty?.name ?? 'Select Property', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) => _onPropertySelected(value!), - items: selectedEntity - ?.getListOfPropertiesToChange() + ], + ), + Expanded( + child: Column( + children: [ + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + selectedEntity?.cbjEntityName.getOrCrash() ?? 'Entity', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => onEntitySelect(value!), + items: widget.entities.values .map>((e) { return DropdownMenuItem( - value: e.index.toString(), - child: TextAtom(e.name), - ); - }).toList() ?? - >[ - const DropdownMenuItem( - value: 'Choose entity first', - child: TextAtom('Choose entity first'), - ), - ], - ), - const SizedBox( - height: 40, - ), - DropdownButton( - dropdownColor: Colors.black, - style: const TextStyle(color: Colors.white), - icon: const Icon(Icons.arrow_drop_down), - hint: TextAtom( - selectedAction?.name ?? 'Choose Action', - style: const TextStyle(color: Colors.white), - ), - elevation: 16, - underline: Container( - height: 2, - ), - onChanged: (value) => onActionSelected(value!), - items: (selectedProperty != null && - selectedProperty!.getActions.isNotEmpty) - ? selectedProperty!.getActions - .map>((e) { - return DropdownMenuItem( - value: e.index.toString(), - child: TextAtom(e.name), - ); - }).toList() - : const >[ - DropdownMenuItem( - value: 'Choose property first', - child: TextAtom('Choose property first'), - ), - ], - ), - const SizedBox( - height: 70, - ), - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () { - SnackBarService().show(context, 'Add action'); - if (selectedEntity == null || - selectedProperty == null || - selectedAction == null) { - return; - } - final EntityActionObject entityActionObject = - EntityActionObject( - entity: selectedEntity!, - property: selectedProperty!, - action: selectedAction!, + value: e.getCbjEntityId, + child: TextAtom(e.cbjEntityName.getOrCrash()!), ); - // TODO: Add pop - context.router - .pop(entityActionObject); - }, - child: const TextAtom( - 'Done', - style: TextStyle(fontSize: 20), + }).toList(), + ), + const SeparatorAtom(variant: SeparatorVariant.farAppart), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + selectedProperty?.name ?? 'Property', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => _onPropertySelected(value!), + items: selectedEntity + ?.getListOfPropertiesToChange() + .map>((e) { + return DropdownMenuItem( + value: e.index.toString(), + child: TextAtom(e.name), + ); + }).toList() ?? + >[ + const DropdownMenuItem( + value: 'Choose entity first', + child: TextAtom('Choose entity first'), + ), + ], + ), + const SeparatorAtom(variant: SeparatorVariant.farAppart), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + selectedAction?.name ?? 'Action', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => onActionSelected(value!), + items: (selectedProperty != null && + selectedProperty!.getActions.isNotEmpty) + ? selectedProperty!.getActions + .map>((e) { + return DropdownMenuItem( + value: e.index.toString(), + child: TextAtom(e.name), + ); + }).toList() + : const >[ + DropdownMenuItem( + value: 'Choose property first', + child: TextAtom('Choose property first'), + ), + ], + ), + const SeparatorAtom(variant: SeparatorVariant.farAppart), + const TextAtom('Field value'), + const SeparatorAtom(), + DropdownButton( + dropdownColor: Colors.black, + style: const TextStyle(color: Colors.white), + icon: const Icon(Icons.arrow_drop_down), + hint: TextAtom( + actionType?.name ?? 'Value', + style: const TextStyle(color: Colors.white), + ), + elevation: 16, + underline: Container( + height: 2, + ), + onChanged: (value) => onSelectedActionType(value!), + items: (selectedAction != null) + ? ActionValues.values + .map>((e) { + return DropdownMenuItem( + value: e.index.toString(), + child: TextAtom(e.name), + ); + }).toList() + : const >[ + DropdownMenuItem( + value: 'Choose action first', + child: TextAtom('Choose action first'), + ), + ], + ), + const SeparatorAtom(), + Container( + margin: const EdgeInsets.symmetric(horizontal: 100), + child: TextFormFieldAtom( + onChanged: (c) { + fieldValues = c; + }, ), ), ], ), - ], - ), + ), + const SeparatorAtom(variant: SeparatorVariant.farAppart), + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () { + SnackBarService().show(context, 'Add action'); + if (selectedEntity == null || + selectedProperty == null || + selectedAction == null) { + return; + } + final RequestActionObject entityActionObject = + RequestActionObject( + entityIds: HashSet.from([selectedEntity!.getCbjEntityId]), + property: selectedProperty!, + actionType: selectedAction!, + value: actionType == null || + fieldValues == null || + fieldValues!.isEmpty + ? null + : HashMap.fromEntries( + [MapEntry(actionType!, fieldValues)], + ), + ); + context.router + .pop(entityActionObject); + }, + child: const TextAtom( + 'Done', + style: TextStyle(fontSize: 20), + ), + ), + ], + ), + const SeparatorAtom(), + ], ), ), ); } } - -class EntityActionObject { - EntityActionObject({ - required this.entity, - required this.property, - required this.action, - }); - - final DeviceEntityBase entity; - final EntityProperties property; - final EntityActions action; -} diff --git a/lib/presentation/pages/add_binding_page.dart b/lib/presentation/pages/add_binding_page.dart index 9b9d4c38..86ffb5f2 100644 --- a/lib/presentation/pages/add_binding_page.dart +++ b/lib/presentation/pages/add_binding_page.dart @@ -9,7 +9,6 @@ import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; -import 'package:cybearjinni/presentation/pages/add_action_page.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -37,7 +36,7 @@ class _AddBindingPageState extends State { String bindingName = ''; /// List of devices with entities, will be treated as actions - HashSet allDevicesWithNewAction = HashSet(); + HashSet allDevicesWithNewAction = HashSet(); Set> allEntityActions = {}; bool showErrorMessages = false; bool isSubmitting = false; @@ -59,7 +58,7 @@ class _AddBindingPageState extends State { // ); } - Future _addFullAction(EntityActionObject value) async { + Future _addFullAction(RequestActionObject value) async { setState(() { allDevicesWithNewAction.add(value); }); @@ -106,7 +105,7 @@ class _AddBindingPageState extends State { child: ListView.builder( itemCount: allDevicesWithNewAction.length, itemBuilder: (BuildContext context, int index) { - final EntityActionObject currentDevice = + final RequestActionObject currentDevice = allDevicesWithNewAction.elementAt(index); return Container( @@ -119,11 +118,11 @@ class _AddBindingPageState extends State { color: Colors.yellow, ), title: AutoSizeText( - '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + '${entities![currentDevice.entityIds.first]!.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', maxLines: 2, ), trailing: AutoSizeText( - currentDevice.action.name, + currentDevice.actionType.name, style: const TextStyle(color: Colors.black), ), ), @@ -153,9 +152,9 @@ class _AddBindingPageState extends State { ), ), onPressed: (_) async { - final EntityActionObject? actionList = + final RequestActionObject? actionList = await context.router - .push( + .push( AddActionRoute(entities: entities!), ); if (actionList != null) { diff --git a/lib/presentation/pages/add_new_area_page.dart b/lib/presentation/pages/add_new_area_page.dart index a3da0f49..ff981d3d 100644 --- a/lib/presentation/pages/add_new_area_page.dart +++ b/lib/presentation/pages/add_new_area_page.dart @@ -132,9 +132,6 @@ class _AddNewAreaFormState extends State { MultiSelectDialogField( buttonText: const Text( 'Select_Purposes_Of_The_Area', - style: TextStyle( - color: Colors.black, - ), ).tr(), cancelText: const Text('CANCEL').tr(), confirmText: const Text('OK').tr(), diff --git a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/choose_device_vendor_to_add_page.dart b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/choose_device_vendor_to_add_page.dart index 689a701c..8a0c24e9 100644 --- a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/choose_device_vendor_to_add_page.dart +++ b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/choose_device_vendor_to_add_page.dart @@ -4,7 +4,6 @@ import 'package:cybearjinni/presentation/molecules/molecules.dart'; import 'package:cybearjinni/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendors_list.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:hexcolor/hexcolor.dart'; @RoutePage() class ChooseDeviceVendorToAddPage extends StatelessWidget { @@ -26,9 +25,9 @@ class ChooseDeviceVendorToAddPage extends StatelessWidget { Container( margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 40), alignment: Alignment.centerLeft, - child: TextAtom( + child: const TextAtom( 'Vendors:', - style: TextStyle(color: HexColor('#6599CA'), fontSize: 20), + style: TextStyle(fontSize: 20), ), ), Expanded( diff --git a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart index cc5ce96b..f6053bd7 100644 --- a/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart +++ b/lib/presentation/pages/add_new_devices_process/choose_device_vendor_to_add/widgets/vendor_widget.dart @@ -49,7 +49,6 @@ class VendorWidget extends StatelessWidget { TextAtom( vendorInformation.displayName, style: const TextStyle( - color: Colors.black, fontSize: 22, ), ), diff --git a/lib/presentation/pages/add_routine_page.dart b/lib/presentation/pages/add_routine_page.dart index 00ae2044..2bbfb926 100644 --- a/lib/presentation/pages/add_routine_page.dart +++ b/lib/presentation/pages/add_routine_page.dart @@ -9,7 +9,6 @@ import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/molecules/molecules.dart'; -import 'package:cybearjinni/presentation/pages/add_action_page.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; @@ -45,7 +44,7 @@ class _AddRoutinePageState extends State { RoutineCbjRepeatDateMinute? minutesToRepeat; /// List of devices with entities, will be treated as actions - HashSet allDevicesWithNewAction = HashSet(); + HashSet allDevicesWithNewAction = HashSet(); Set> allEntityActions = {}; bool showErrorMessages = false; @@ -82,7 +81,7 @@ class _AddRoutinePageState extends State { routineName = value; } - Future _addFullAction(EntityActionObject value) async { + Future _addFullAction(RequestActionObject value) async { setState(() { allDevicesWithNewAction.add(value); }); @@ -130,7 +129,7 @@ class _AddRoutinePageState extends State { child: ListView.builder( itemCount: allDevicesWithNewAction.length, itemBuilder: (BuildContext context, int index) { - final EntityActionObject currentDevice = + final RequestActionObject currentDevice = allDevicesWithNewAction.elementAt(index); return Container( @@ -143,11 +142,11 @@ class _AddRoutinePageState extends State { color: Colors.yellow, ), title: AutoSizeText( - '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + '${entities![currentDevice.entityIds.first]!.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', maxLines: 2, ), trailing: AutoSizeText( - currentDevice.action.name, + currentDevice.actionType.name, style: const TextStyle(color: Colors.black), ), ), @@ -177,9 +176,9 @@ class _AddRoutinePageState extends State { ), ), onPressed: (_) async { - final EntityActionObject? actionList = + final RequestActionObject? actionList = await context.router - .push( + .push( AddActionRoute(entities: entities!), ); if (actionList != null) { diff --git a/lib/presentation/pages/add_scene_page.dart b/lib/presentation/pages/add_scene_page.dart index f793d94e..9cd4f151 100644 --- a/lib/presentation/pages/add_scene_page.dart +++ b/lib/presentation/pages/add_scene_page.dart @@ -6,10 +6,10 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/domain/connections_service.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; +import 'package:cybearjinni/presentation/core/entities_utils.dart'; import 'package:cybearjinni/presentation/core/routes/app_router.gr.dart'; import 'package:cybearjinni/presentation/core/snack_bar_service.dart'; import 'package:cybearjinni/presentation/organisms/organisms.dart'; -import 'package:cybearjinni/presentation/pages/add_action_page.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -31,7 +31,7 @@ class _AddScenePageState extends State { HashMap? entities; /// List of devices with entities, will be treated as actions - HashSet entitiesWithActions = HashSet(); + HashSet entitiesWithActions = HashSet(); Future initialzeEntities() async { final HashMap entitiesTemp = @@ -42,21 +42,7 @@ class _AddScenePageState extends State { }); } - List entitiesWithActionsToActionsByVendor() => - entitiesWithActions - .map( - (e) => RequestActionObject( - entityIds: HashSet.from([e.entity.getCbjEntityId]), - property: e.property, - actionType: e.action, - ), - ) - .toList(); - Future _sendSceneToHub() async { - final List actions = - entitiesWithActionsToActionsByVendor(); - final SceneCbjEntity scene = SceneCbjEntity( uniqueId: UniqueId(), name: SceneCbjName(sceneName), @@ -73,7 +59,7 @@ class _AddScenePageState extends State { senderId: SceneCbjSenderId(''), compUuid: SceneCbjCompUuid(''), entityStateGRPC: SceneCbjDeviceStateGRPC(EntityStateGRPC.ack.name), - actions: actions, + actions: entitiesWithActions.toList(), areaPurposeType: AreaPurposesTypes.undefined, entitiesWithAutomaticPurpose: EntitiesWithAutomaticPurpose(HashSet()), ); @@ -81,23 +67,12 @@ class _AddScenePageState extends State { ConnectionsService.instance.addScene(scene); } - Future _addFullAction(EntityActionObject value) async { + Future _addFullAction(RequestActionObject value) async { setState(() { entitiesWithActions.add(value); }); } - // Set>> - // smartDevicesWithActionToAdd, - // required String actionsName, - // required Set allDevices, - // required Set>> - // allDevicesWithNewAction, - // required Set> allEntityActions, - // required bool showErrorMessages, - // required bool isSubmitting, - // required Option> authFailureOrSuccessOption, - @override Widget build(BuildContext context) { if (entities == null) { @@ -118,7 +93,6 @@ class _AddScenePageState extends State { prefixIcon: FaIcon(FontAwesomeIcons.fileSignature), labelText: 'Scene Name', ), - style: const TextStyle(color: Colors.black), onChanged: (value) => sceneName = value, ), SizedBox( @@ -127,25 +101,30 @@ class _AddScenePageState extends State { child: ListView.builder( itemCount: entitiesWithActions.length, itemBuilder: (BuildContext context, int index) { - final EntityActionObject currentDevice = + final RequestActionObject currentDevice = entitiesWithActions.elementAt(index); + final DeviceEntityBase? entity = + entities![currentDevice.entityIds.first]; + if (entity == null) { + return const SizedBox(); + } return Container( margin: const EdgeInsets.symmetric(vertical: 1), child: ColoredBox( color: Colors.blue.withOpacity(0.3), child: ListTile( - leading: const FaIcon( - FontAwesomeIcons.lightbulb, - color: Colors.yellow, + leading: FaIcon( + EntitiesUtils.iconOfDeviceType( + entity.entityTypes.type, + ), ), title: AutoSizeText( - '${currentDevice.entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', + '${entity.cbjEntityName.getOrCrash()!} - ${currentDevice.property.name}', maxLines: 2, ), trailing: AutoSizeText( - currentDevice.action.name, - style: const TextStyle(color: Colors.black), + currentDevice.actionType.name, ), ), ), @@ -157,7 +136,6 @@ class _AddScenePageState extends State { DecoratedBox( decoration: BoxDecoration( color: Colors.lightBlueAccent.withOpacity(0.5), - // Red border with the width is equal to 5 border: Border.all(), ), child: TextButton( @@ -174,8 +152,8 @@ class _AddScenePageState extends State { ), ), onPressed: (_) async { - final EntityActionObject? actionList = - await context.router.push( + final RequestActionObject? actionList = + await context.router.push( AddActionRoute(entities: entities!), ); if (actionList != null) { @@ -191,12 +169,10 @@ class _AddScenePageState extends State { fontSize: 23, ), ), - onPressed: (_) { - SnackBarService().show( - context, - 'Adding service action will be added in the future', - ); - }, + onPressed: (_) => SnackBarService().show( + context, + 'Adding service action will be added in the future', + ), ), BottomSheetAction( title: const TextAtom( @@ -206,12 +182,10 @@ class _AddScenePageState extends State { fontSize: 23, ), ), - onPressed: (_) { - SnackBarService().show( - context, - 'Adding time based action will be added in the future', - ); - }, + onPressed: (_) => SnackBarService().show( + context, + 'Adding time based action will be added in the future', + ), ), ], ); @@ -228,6 +202,8 @@ class _AddScenePageState extends State { ), child: TextButton( onPressed: () { + context.router.pop(); + SnackBarService().show( context, 'Adding Scene',