diff --git a/lib/infrastructure/connection_service/demo_connection_service.dart b/lib/infrastructure/connection_service/demo_connection_service.dart index eb4c8165..f23916c0 100644 --- a/lib/infrastructure/connection_service/demo_connection_service.dart +++ b/lib/infrastructure/connection_service/demo_connection_service.dart @@ -57,5 +57,6 @@ class _DemoConnectionService implements ConnectionsService { Future loginVendor(VendorLoginEntity value) async {} @override - Future> getVendors() async => []; + Future> getVendors() async => + IcSynchronizer().getVendors(); } diff --git a/lib/presentation/atoms/atoms.dart b/lib/presentation/atoms/atoms.dart index 862f071d..35d15099 100644 --- a/lib/presentation/atoms/atoms.dart +++ b/lib/presentation/atoms/atoms.dart @@ -9,3 +9,4 @@ export 'scene_atom.dart'; export 'separator_atom.dart'; export 'switch_atom.dart'; export 'text_atom.dart'; +export 'text_form_field_atom.dart'; diff --git a/lib/presentation/atoms/text_form_field_atom.dart b/lib/presentation/atoms/text_form_field_atom.dart new file mode 100644 index 00000000..98124560 --- /dev/null +++ b/lib/presentation/atoms/text_form_field_atom.dart @@ -0,0 +1,26 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; + +class TextFormFieldAtom extends StatelessWidget { + const TextFormFieldAtom({ + required this.onChanged, + this.labelText, + this.prefixIcon, + }); + + final Function(String) onChanged; + final String? labelText; + final Widget? prefixIcon; + + @override + Widget build(BuildContext context) { + return TextFormField( + decoration: InputDecoration( + prefixIcon: prefixIcon, + labelText: labelText?.tr(), + ), + autocorrect: false, + onChanged: onChanged, + ); + } +} diff --git a/lib/presentation/molecules/device_name_row.dart b/lib/presentation/molecules/device_name_row_molecule.dart similarity index 81% rename from lib/presentation/molecules/device_name_row.dart rename to lib/presentation/molecules/device_name_row_molecule.dart index bf383ef4..8c28ee58 100644 --- a/lib/presentation/molecules/device_name_row.dart +++ b/lib/presentation/molecules/device_name_row_molecule.dart @@ -2,8 +2,8 @@ import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -class DeviceNameRow extends StatelessWidget { - const DeviceNameRow(this.name, this.second); +class DeviceNameRowMolecule extends StatelessWidget { + const DeviceNameRowMolecule(this.name, this.second); final String name; final Widget second; diff --git a/lib/presentation/molecules/devices/ac_molecule.dart b/lib/presentation/molecules/devices/ac_molecule.dart index fdef8ed9..53d4c71c 100644 --- a/lib/presentation/molecules/devices/ac_molecule.dart +++ b/lib/presentation/molecules/devices/ac_molecule.dart @@ -74,7 +74,7 @@ class _AcMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.ac, diff --git a/lib/presentation/molecules/devices/blind_molecule.dart b/lib/presentation/molecules/devices/blind_molecule.dart index 3e2aa0f9..4795a196 100644 --- a/lib/presentation/molecules/devices/blind_molecule.dart +++ b/lib/presentation/molecules/devices/blind_molecule.dart @@ -100,7 +100,7 @@ class _BlindMoleculeState extends State { } } - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, Row( children: [ diff --git a/lib/presentation/molecules/devices/boiler_molecule.dart b/lib/presentation/molecules/devices/boiler_molecule.dart index cdd8583c..2987f8cd 100644 --- a/lib/presentation/molecules/devices/boiler_molecule.dart +++ b/lib/presentation/molecules/devices/boiler_molecule.dart @@ -74,7 +74,7 @@ class _BoilerMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.boiler, diff --git a/lib/presentation/molecules/devices/dimmable_light_molecule.dart b/lib/presentation/molecules/devices/dimmable_light_molecule.dart index e410d97f..e7a5e3da 100644 --- a/lib/presentation/molecules/devices/dimmable_light_molecule.dart +++ b/lib/presentation/molecules/devices/dimmable_light_molecule.dart @@ -21,15 +21,36 @@ class DimmableLightMolecule extends StatefulWidget { class _DimmableLightMoleculeState extends State { double brightness = 100; + @override + void initState() { + super.initState(); + _initialized(); + } + + Future _initialized() async { + final GenericDimmableLightDE rgbwLightDe = widget.entity; + + double lightBrightness = + double.parse(rgbwLightDe.lightBrightness.getOrCrash()); + + if (lightBrightness > 100) { + lightBrightness = 100; + } + + setState(() { + brightness = lightBrightness; + }); + } + Future _changeBrightness(double value) async { setState(() { brightness = value; }); - final HashMap hashValue = - HashMap() + final HashMap hashValue = + HashMap() ..addEntries([ - MapEntry(ActionValues.brightness, value.round().toString()), + MapEntry(ActionValues.brightness, value.round()), ]); setEntityState( @@ -86,7 +107,7 @@ class _DimmableLightMoleculeState extends State { return Column( children: [ - DeviceNameRow( + DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.light, diff --git a/lib/presentation/molecules/devices/light_molecule.dart b/lib/presentation/molecules/devices/light_molecule.dart index 5ed44e2d..62539a5e 100644 --- a/lib/presentation/molecules/devices/light_molecule.dart +++ b/lib/presentation/molecules/devices/light_molecule.dart @@ -45,7 +45,7 @@ class LightMolecule extends StatelessWidget { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.light, diff --git a/lib/presentation/molecules/devices/printer_molecule.dart b/lib/presentation/molecules/devices/printer_molecule.dart index a6e4efcb..49637125 100644 --- a/lib/presentation/molecules/devices/printer_molecule.dart +++ b/lib/presentation/molecules/devices/printer_molecule.dart @@ -33,7 +33,7 @@ class _PrinterMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, TextButton( style: ButtonStyle( diff --git a/lib/presentation/molecules/devices/rgb_light_molecule.dart b/lib/presentation/molecules/devices/rgb_light_molecule.dart index b06e2c2e..bff49486 100644 --- a/lib/presentation/molecules/devices/rgb_light_molecule.dart +++ b/lib/presentation/molecules/devices/rgb_light_molecule.dart @@ -111,7 +111,7 @@ class _RgbwLightMoleculeState extends State { return Column( children: [ - DeviceNameRow( + DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.light, diff --git a/lib/presentation/molecules/devices/security_camera_molecule.dart b/lib/presentation/molecules/devices/security_camera_molecule.dart index a0d481b8..f530314a 100644 --- a/lib/presentation/molecules/devices/security_camera_molecule.dart +++ b/lib/presentation/molecules/devices/security_camera_molecule.dart @@ -33,7 +33,7 @@ class _SecurityCameraMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, TextButton( style: ButtonStyle( diff --git a/lib/presentation/molecules/devices/smart_computer_molecule.dart b/lib/presentation/molecules/devices/smart_computer_molecule.dart index d1059909..f30f7c3a 100644 --- a/lib/presentation/molecules/devices/smart_computer_molecule.dart +++ b/lib/presentation/molecules/devices/smart_computer_molecule.dart @@ -48,7 +48,7 @@ class _SmartComputerMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/presentation/molecules/devices/smart_plug_molecule.dart b/lib/presentation/molecules/devices/smart_plug_molecule.dart index 2e648141..a215944c 100644 --- a/lib/presentation/molecules/devices/smart_plug_molecule.dart +++ b/lib/presentation/molecules/devices/smart_plug_molecule.dart @@ -55,7 +55,7 @@ class _SmartPlugsMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.smartPlug, diff --git a/lib/presentation/molecules/devices/smart_tv_molecule.dart b/lib/presentation/molecules/devices/smart_tv_molecule.dart index 52429214..750c5d80 100644 --- a/lib/presentation/molecules/devices/smart_tv_molecule.dart +++ b/lib/presentation/molecules/devices/smart_tv_molecule.dart @@ -280,7 +280,7 @@ class _SmartTvMoleculeState extends State { Widget build(BuildContext context) { return Column( children: [ - DeviceNameRow( + DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, const SizedBox(), ), diff --git a/lib/presentation/molecules/devices/switch_molecule.dart b/lib/presentation/molecules/devices/switch_molecule.dart index 77bee751..af5f09ed 100644 --- a/lib/presentation/molecules/devices/switch_molecule.dart +++ b/lib/presentation/molecules/devices/switch_molecule.dart @@ -55,7 +55,7 @@ class _SwitchMoleculeState extends State { @override Widget build(BuildContext context) { - return DeviceNameRow( + return DeviceNameRowMolecule( widget.entity.cbjEntityName.getOrCrash()!, SwitchAtom( variant: SwitchVariant.switchVariant, diff --git a/lib/presentation/molecules/insert_login_molecule.dart b/lib/presentation/molecules/insert_login_molecule.dart new file mode 100644 index 00000000..bf48c770 --- /dev/null +++ b/lib/presentation/molecules/insert_login_molecule.dart @@ -0,0 +1,104 @@ +import 'package:cbj_integrations_controller/integrations_controller.dart'; +import 'package:cybearjinni/presentation/atoms/atoms.dart'; +import 'package:flutter/material.dart'; + +class InsertLoginMolecule extends StatefulWidget { + const InsertLoginMolecule({ + required this.type, + required this.vendorsAndServices, + required this.onChange, + }); + + final InsertloginMoleculeType type; + final VendorsAndServices vendorsAndServices; + final Function(VendorLoginEntity) onChange; + + @override + State createState() => _InsertLoginMoleculeState(); +} + +class _InsertLoginMoleculeState extends State { + late VendorLoginEntity loginEntity; + + @override + void initState() { + super.initState(); + loginEntity = VendorLoginEntity(widget.vendorsAndServices); + } + + void onEmailChange(String value) { + loginEntity = loginEntityCopyWith(loginEntity: loginEntity, email: value); + + widget.onChange(loginEntity); + } + + void onPasswordChange(String value) { + loginEntity = + loginEntityCopyWith(loginEntity: loginEntity, password: value); + + widget.onChange(loginEntity); + } + + void onApiKeyChange(String value) { + loginEntity = loginEntityCopyWith(loginEntity: loginEntity, apiKey: value); + + widget.onChange(loginEntity); + } + + void onAuthTokenChange(String value) { + loginEntity = + loginEntityCopyWith(loginEntity: loginEntity, authToken: value); + + widget.onChange(loginEntity); + } + + VendorLoginEntity loginEntityCopyWith({ + required VendorLoginEntity loginEntity, + String? apiKey, + String? authToken, + String? email, + String? password, + }) => + VendorLoginEntity( + loginEntity.vendor, + apiKey: apiKey ?? loginEntity.apiKey, + authToken: authToken ?? loginEntity.authToken, + email: email ?? loginEntity.email, + password: password ?? loginEntity.password, + ); + + @override + Widget build(BuildContext context) { + switch (widget.type) { + case InsertloginMoleculeType.authToken: + return TextFormFieldAtom( + onChanged: onAuthTokenChange, + labelText: 'Auth Token', + ); + case InsertloginMoleculeType.apiKey: + return TextFormFieldAtom( + onChanged: onApiKeyChange, + labelText: 'Api Key', + ); + case InsertloginMoleculeType.emailAndPassword: + return Column( + children: [ + TextFormFieldAtom( + onChanged: onEmailChange, + labelText: 'Email', + ), + TextFormFieldAtom( + onChanged: onPasswordChange, + labelText: 'Password', + ), + ], + ); + } + } +} + +enum InsertloginMoleculeType { + authToken, + apiKey, + emailAndPassword, +} diff --git a/lib/presentation/molecules/molecules.dart b/lib/presentation/molecules/molecules.dart index f90f49b3..fedd80a8 100644 --- a/lib/presentation/molecules/molecules.dart +++ b/lib/presentation/molecules/molecules.dart @@ -1,6 +1,6 @@ export 'bottom_navigation_bar_molecule.dart'; export 'device_by_type_molecule.dart'; -export 'device_name_row.dart'; +export 'device_name_row_molecule.dart'; export 'devices/ac_molecule.dart'; export 'devices/blind_molecule.dart'; export 'devices/blinds_card_molecule.dart'; @@ -15,8 +15,9 @@ export 'devices/smart_computer_molecule.dart'; export 'devices/smart_plug_molecule.dart'; export 'devices/smart_tv_molecule.dart'; export 'devices/switch_molecule.dart'; +export 'insert_login_molecule.dart'; export 'list_tile_molecule.dart'; export 'list_view_molecule.dart'; export 'loading_page_molecule.dart'; -export 'scenes_grid.dart'; +export 'scenes_grid_molecule.dart'; export 'top_bar_molecule.dart'; diff --git a/lib/presentation/molecules/scenes_grid.dart b/lib/presentation/molecules/scenes_grid_molecule.dart similarity index 82% rename from lib/presentation/molecules/scenes_grid.dart rename to lib/presentation/molecules/scenes_grid_molecule.dart index 131fbb10..3fcb78b1 100644 --- a/lib/presentation/molecules/scenes_grid.dart +++ b/lib/presentation/molecules/scenes_grid_molecule.dart @@ -2,16 +2,16 @@ import 'package:cbj_integrations_controller/integrations_controller.dart'; import 'package:cybearjinni/presentation/atoms/atoms.dart'; import 'package:flutter/material.dart'; -class ScenesGrid extends StatefulWidget { - const ScenesGrid({required this.scenes}); +class ScenesGridMolecule extends StatefulWidget { + const ScenesGridMolecule({required this.scenes}); final List scenes; @override - State createState() => _ScenesGridState(); + State createState() => _ScenesGridMoleculeState(); } -class _ScenesGridState extends State { +class _ScenesGridMoleculeState extends State { late AreaEntity folderOfScenes; @override 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/scenes_in_folders_tab.dart index 577f77a2..dce8ec8f 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/scenes_in_folders_tab.dart @@ -97,7 +97,7 @@ class ScenesInFoldersTab extends StatelessWidget { leftIconFunction: (BuildContext context) {}, ), Expanded( - child: ScenesGrid( + child: ScenesGridMolecule( scenes: scenes!.values.toList(), ), ), diff --git a/lib/presentation/pages/login_vendor_page.dart b/lib/presentation/pages/login_vendor_page.dart index 6d89125a..beffa50d 100644 --- a/lib/presentation/pages/login_vendor_page.dart +++ b/lib/presentation/pages/login_vendor_page.dart @@ -3,8 +3,8 @@ 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/snack_bar_service.dart'; +import 'package:cybearjinni/presentation/molecules/molecules.dart'; import 'package:flutter/material.dart'; -import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:url_launcher/url_launcher.dart'; @RoutePage() @@ -18,23 +18,44 @@ class LoginVendorPage extends StatefulWidget { } class _LoginVendorPageState extends State { - String? apiKey; + VendorLoginEntity? loginEntity; Future _signInWithApiKey() async { + if (loginEntity == null) { + return; + } + SnackBarService().show( context, 'Sign in to ${widget.vendorInformation.displayName}, devices will appear in the shortly', ); - ConnectionsService.instance.loginVendor( - VendorLoginEntity( - widget.vendorInformation.vendorsAndServices, - apiKey: apiKey, - ), - ); + ConnectionsService.instance.loginVendor(loginEntity!); context.router.pop(); } + Widget authTypeWidget() { + InsertloginMoleculeType type; + switch (widget.vendorInformation.loginType) { + case VendorLoginTypes.notNeeded: + return const TextAtom('Not needed'); + case VendorLoginTypes.authToken: + type = InsertloginMoleculeType.authToken; + case VendorLoginTypes.apiKey: + type = InsertloginMoleculeType.apiKey; + + case VendorLoginTypes.emailAndPassword: + type = InsertloginMoleculeType.emailAndPassword; + } + return InsertLoginMolecule( + type: type, + vendorsAndServices: widget.vendorInformation.vendorsAndServices, + onChange: (VendorLoginEntity value) { + loginEntity = value; + }, + ); + } + @override Widget build(BuildContext context) { final Size screenSize = MediaQuery.of(context).size; @@ -72,16 +93,7 @@ class _LoginVendorPageState extends State { const SizedBox( height: 8, ), - TextFormField( - decoration: const InputDecoration( - prefixIcon: FaIcon(FontAwesomeIcons.key), - labelText: 'value', - ), - autocorrect: false, - onChanged: (value) { - apiKey = value; - }, - ), + authTypeWidget(), const SizedBox( height: 8, ), @@ -107,8 +119,11 @@ class _LoginVendorPageState extends State { backgroundColor: MaterialStateProperty.all(Colors.pink), ), onPressed: () { - launchUrl(Uri.parse( - widget.vendorInformation.urlToLoginCredantials!)); + launchUrl( + Uri.parse( + widget.vendorInformation.urlToLoginCredantials!, + ), + ); }, child: TextAtom( widget.vendorInformation.loginType.name, diff --git a/lib/presentation/pages/scenes/scenes_page.dart b/lib/presentation/pages/scenes/scenes_page.dart index 12ab9dcf..6e77c17a 100644 --- a/lib/presentation/pages/scenes/scenes_page.dart +++ b/lib/presentation/pages/scenes/scenes_page.dart @@ -107,7 +107,7 @@ class _ScenesPageState extends State { // rightSecondIcon: FontAwesomeIcons.magnifyingGlass, ), Expanded( - child: ScenesGrid( + child: ScenesGridMolecule( scenes: scenes!.values.toList(), ), ),