Skip to content

Commit

Permalink
Added support for more login types
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 12, 2024
1 parent 8bbb82f commit 0b5af4b
Show file tree
Hide file tree
Showing 22 changed files with 215 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ class _DemoConnectionService implements ConnectionsService {
Future<void> loginVendor(VendorLoginEntity value) async {}

@override
Future<List<VendorEntityInformation>> getVendors() async => [];
Future<List<VendorEntityInformation>> getVendors() async =>
IcSynchronizer().getVendors();
}
1 change: 1 addition & 0 deletions lib/presentation/atoms/atoms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
26 changes: 26 additions & 0 deletions lib/presentation/atoms/text_form_field_atom.dart
Original file line number Diff line number Diff line change
@@ -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,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/ac_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _AcMoleculeState extends State<AcMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.ac,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/blind_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class _BlindMoleculeState extends State<BlindMolecule> {
}
}

return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
Row(
children: [
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/boiler_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _BoilerMoleculeState extends State<BoilerMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.boiler,
Expand Down
29 changes: 25 additions & 4 deletions lib/presentation/molecules/devices/dimmable_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,36 @@ class DimmableLightMolecule extends StatefulWidget {
class _DimmableLightMoleculeState extends State<DimmableLightMolecule> {
double brightness = 100;

@override
void initState() {
super.initState();
_initialized();
}

Future<void> _initialized() async {
final GenericDimmableLightDE rgbwLightDe = widget.entity;

double lightBrightness =
double.parse(rgbwLightDe.lightBrightness.getOrCrash());

if (lightBrightness > 100) {
lightBrightness = 100;
}

setState(() {
brightness = lightBrightness;
});
}

Future<void> _changeBrightness(double value) async {
setState(() {
brightness = value;
});

final HashMap<ActionValues, String> hashValue =
HashMap<ActionValues, String>()
final HashMap<ActionValues, dynamic> hashValue =
HashMap<ActionValues, dynamic>()
..addEntries([
MapEntry(ActionValues.brightness, value.round().toString()),
MapEntry(ActionValues.brightness, value.round()),
]);

setEntityState(
Expand Down Expand Up @@ -86,7 +107,7 @@ class _DimmableLightMoleculeState extends State<DimmableLightMolecule> {

return Column(
children: [
DeviceNameRow(
DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.light,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LightMolecule extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.light,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/printer_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _PrinterMoleculeState extends State<PrinterMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
TextButton(
style: ButtonStyle(
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/rgb_light_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _RgbwLightMoleculeState extends State<RgbwLightMolecule> {

return Column(
children: [
DeviceNameRow(
DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.light,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _SecurityCameraMoleculeState extends State<SecurityCameraMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
TextButton(
style: ButtonStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _SmartComputerMoleculeState extends State<SmartComputerMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
Row(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _SmartPlugsMoleculeState extends State<SmartPlugsMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.smartPlug,
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/smart_tv_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class _SmartTvMoleculeState extends State<SmartTvMolecule> {
Widget build(BuildContext context) {
return Column(
children: [
DeviceNameRow(
DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
const SizedBox(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/molecules/devices/switch_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _SwitchMoleculeState extends State<SwitchMolecule> {

@override
Widget build(BuildContext context) {
return DeviceNameRow(
return DeviceNameRowMolecule(
widget.entity.cbjEntityName.getOrCrash()!,
SwitchAtom(
variant: SwitchVariant.switchVariant,
Expand Down
104 changes: 104 additions & 0 deletions lib/presentation/molecules/insert_login_molecule.dart
Original file line number Diff line number Diff line change
@@ -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<InsertLoginMolecule> createState() => _InsertLoginMoleculeState();
}

class _InsertLoginMoleculeState extends State<InsertLoginMolecule> {
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,
}
5 changes: 3 additions & 2 deletions lib/presentation/molecules/molecules.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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<SceneCbjEntity> scenes;

@override
State<ScenesGrid> createState() => _ScenesGridState();
State<ScenesGridMolecule> createState() => _ScenesGridMoleculeState();
}

class _ScenesGridState extends State<ScenesGrid> {
class _ScenesGridMoleculeState extends State<ScenesGridMolecule> {
late AreaEntity folderOfScenes;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ScenesInFoldersTab extends StatelessWidget {
leftIconFunction: (BuildContext context) {},
),
Expanded(
child: ScenesGrid(
child: ScenesGridMolecule(
scenes: scenes!.values.toList(),
),
),
Expand Down
Loading

0 comments on commit 0b5af4b

Please sign in to comment.