Skip to content

Commit

Permalink
Added room support
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Jan 3, 2024
1 parent 9478271 commit a7c785b
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 359 deletions.
8 changes: 8 additions & 0 deletions lib/domain/connections_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ abstract interface class ConnectionsService {
HashMap<ActionValues, dynamic>? value,
});

Future setEtitiesToArea(String areaId, HashSet<String> entities);

Future<HashMap<String, DeviceEntityBase>> get getAllEntities;

Future<HashMap<String, AreaEntity>> get getAllAreas;

Stream<MapEntry<String, DeviceEntityBase>> watchEntities();

Stream<MapEntry<String, AreaEntity>> watchAreas();

Future dispose();

Future setNewArea(AreaEntity area);
}
23 changes: 20 additions & 3 deletions lib/infrastructure/connection_service/app_connection_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ class _AppConnectionService implements ConnectionsService {

@override
Future<HashMap<String, DeviceEntityBase>> get getAllEntities async =>
EntitiesService().getEntities();
IcSynchronizer().getEntities();

@override
Future<HashMap<String, AreaEntity>> get getAllAreas async =>
IcSynchronizer().getAreas();

@override
Future searchDevices() =>
searchDevicesInstance.startSearchIsolate(NetworkUtilitiesFlutter());

@override
Stream<MapEntry<String, DeviceEntityBase>> watchEntities() =>
EntitiesService().watchEntities();
IcSynchronizer().entitiesChangesStream.stream;

@override
Stream<MapEntry<String, AreaEntity>> watchAreas() =>
IcSynchronizer().areasChangesStream.stream;

@override
void setEntityState({
Expand All @@ -27,7 +35,7 @@ class _AppConnectionService implements ConnectionsService {
required EntityActions actionType,
HashMap<ActionValues, dynamic>? value,
}) =>
EntitiesService().setEntityState(
IcSynchronizer().setEntityState(
uniqueIdByVendor: uniqueIdByVendor,
action: actionType,
property: property,
Expand All @@ -36,4 +44,13 @@ class _AppConnectionService implements ConnectionsService {

@override
Future dispose() async => searchDevicesInstance.dispose();

@override
Future setNewArea(AreaEntity area) async {
IcSynchronizer().setNewArea(area);
}

@override
Future setEtitiesToArea(String areaId, HashSet<String> entities) =>
IcSynchronizer().setEtitiesToArea(areaId, entities);
}
29 changes: 24 additions & 5 deletions lib/infrastructure/connection_service/demo_connection_service.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
part of 'package:cybearjinni/domain/connections_service.dart';

class _DemoConnectionService implements ConnectionsService {
StreamController<MapEntry<String, DeviceEntityBase>>? stream;
StreamController<MapEntry<String, DeviceEntityBase>>? entitiesStream;
StreamController<MapEntry<String, AreaEntity>>? areasStream;

@override
Future dispose() async {
stream?.close();
entitiesStream?.close();
}

@override
Future<HashMap<String, DeviceEntityBase>> get getAllEntities async =>
DemoConnectionController.getAllEntities();

@override
Future<HashMap<String, AreaEntity>> get getAllAreas async => HashMap();

@override
Future searchDevices() async {}

Expand All @@ -24,9 +29,23 @@ class _DemoConnectionService implements ConnectionsService {

@override
Stream<MapEntry<String, DeviceEntityBase>> watchEntities() {
stream?.close();
entitiesStream?.close();

stream = StreamController.broadcast();
return stream!.stream;
entitiesStream = StreamController.broadcast();
return entitiesStream!.stream;
}

@override
Stream<MapEntry<String, AreaEntity>> watchAreas() {
areasStream?.close();

areasStream = StreamController.broadcast();
return areasStream!.stream;
}

@override
Future setNewArea(AreaEntity area) async {}

@override
Future setEtitiesToArea(String areaId, HashSet entities) async {}
}
28 changes: 23 additions & 5 deletions lib/infrastructure/connection_service/none_connection_service.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
part of 'package:cybearjinni/domain/connections_service.dart';

class _NoneConnectionService implements ConnectionsService {
StreamController<MapEntry<String, DeviceEntityBase>>? stream;
StreamController<MapEntry<String, DeviceEntityBase>>? entitiesStream;
StreamController<MapEntry<String, AreaEntity>>? areasStream;

@override
Future dispose() async {
stream?.close();
entitiesStream?.close();
}

@override
Future<HashMap<String, DeviceEntityBase>> get getAllEntities async =>
HashMap();

@override
Future<HashMap<String, AreaEntity>> get getAllAreas async => HashMap();

@override
Future searchDevices() async {}

Expand All @@ -25,9 +29,23 @@ class _NoneConnectionService implements ConnectionsService {

@override
Stream<MapEntry<String, DeviceEntityBase>> watchEntities() {
stream?.close();
entitiesStream?.close();

entitiesStream = StreamController.broadcast();
return entitiesStream!.stream;
}

@override
Stream<MapEntry<String, AreaEntity>> watchAreas() {
areasStream?.close();

stream = StreamController.broadcast();
return stream!.stream;
areasStream = StreamController.broadcast();
return areasStream!.stream;
}

@override
Future setNewArea(AreaEntity area) async {}

@override
Future setEtitiesToArea(String areaId, HashSet entities) async {}
}
1 change: 1 addition & 0 deletions lib/presentation/atoms/card_atom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CardAtom extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.zero,
child: child,
);
}
Expand Down
6 changes: 0 additions & 6 deletions lib/presentation/molecules/devices/blind_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class _BlindMoleculeState extends State<BlindMolecule> {
).show(context);

setEntityState(EntityActions.moveUp);
// IDeviceRepository.instance.moveUpStateDevices(devicesId: blindsIdToTurnUp);
}

void setEntityState(EntityActions action) {
Expand Down Expand Up @@ -64,8 +63,6 @@ class _BlindMoleculeState extends State<BlindMolecule> {
).show(context);

setEntityState(EntityActions.stop);

// IDeviceRepository.instance.stopStateDevices(devicesId: blindsIdToStop);
}

Future<void> _moveDownAllBlinds(List<String> blindsIdToTurnDown) async {
Expand All @@ -75,9 +72,6 @@ class _BlindMoleculeState extends State<BlindMolecule> {
).show(context);

setEntityState(EntityActions.moveDown);

// IDeviceRepository.instance
// .moveDownStateDevices(devicesId: blindsIdToTurnDown);
}

@override
Expand Down
6 changes: 5 additions & 1 deletion lib/presentation/molecules/list_view_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ListViewMolecule extends StatelessWidget {
this.reverse = false,
this.physics,
this.shrinkWrap = false,
this.separatorVariant = SeparatorVariant.reletedElements,
});

final int itemCount;
Expand All @@ -20,6 +21,7 @@ class ListViewMolecule extends StatelessWidget {
final ScrollPhysics? physics;
final bool shrinkWrap;
final ListViewVeriant veriant;
final SeparatorVariant separatorVariant;

@override
Widget build(BuildContext context) {
Expand All @@ -31,6 +33,7 @@ class ListViewMolecule extends StatelessWidget {
itemCount: itemCount,
scrollDirection: scrollDirection,
reverse: reverse,
padding: EdgeInsets.zero,
itemBuilder: (BuildContext context, int index) =>
itemBuilder(context, index),
);
Expand All @@ -41,10 +44,11 @@ class ListViewMolecule extends StatelessWidget {
itemCount: itemCount,
scrollDirection: scrollDirection,
reverse: reverse,
padding: EdgeInsets.zero,
itemBuilder: (BuildContext context, int index) =>
itemBuilder(context, index),
separatorBuilder: (context, index) =>
const SeparatorAtom(variant: SeparatorVariant.reletedElements),
SeparatorAtom(variant: separatorVariant),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/organisms/devices_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class DevicesListView extends StatelessWidget {

if (numberOfType == 1) {
headline = firstEntityOfType.cbjEntityName.getOrCrash();
supportingText = firstEntityOfType.entityStateGRPC.getOrCrash();
supportingText = firstEntityOfType.entityStateGRPC.state.name;
} else {
headline = '$numberOfType ${type}s';
headline = '$numberOfType ${type.name}s';
supportingText = '';
}

Expand Down
41 changes: 21 additions & 20 deletions lib/presentation/pages/add_new_area_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:auto_route/auto_route.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/snack_bar_service.dart';
import 'package:dartz/dartz.dart' as dartz;
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Expand Down Expand Up @@ -35,15 +35,14 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
'https://live.staticflickr.com/5220/5486044345_f67abff3e9_h.jpg',
);
AreaTypes areaTypes = AreaTypes(const {});
AreaDevicesId areaDevicesId = AreaDevicesId(const {});
AreaEntitiesId areaDevicesId = AreaEntitiesId(const {});
AreaScenesId areaScenesId = AreaScenesId(const {});
AreaRoutinesId areaRoutinesId = AreaRoutinesId(const {});
AreaBindingsId areaBindingsId = AreaBindingsId(const {});
AreaMostUsedBy areaMostUsedBy = AreaMostUsedBy(const {});
AreaPermissions areaPermissions = AreaPermissions(const {});
bool showErrorMessages = false;
bool isSubmitting = false;
dartz.Option authFailureOrSuccessOption = dartz.none();

// Future<void> _initialized() async {
// IAreaRepository.instance.getAllAreas().fold((l) => null, (r) {
Expand All @@ -62,33 +61,31 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
// }

Future<void> _createArea() async {
// final AreaEntity areaEntity = AreaEntity(
// uniqueId: AreaUniqueId.fromUniqueString(areaUniqueId.getOrCrash()),
// cbjEntityName: AreaDefaultName(cbjEntityName.getOrCrash()),
// background: AreaBackground(background.getOrCrash()),
// areaTypes: AreaTypes(areaTypes.getOrCrash()),
// areaDevicesId: AreaDevicesId(areaDevicesId.getOrCrash()),
// areaScenesId: AreaScenesId(areaScenesId.getOrCrash()),
// areaRoutinesId: AreaRoutinesId(areaRoutinesId.getOrCrash()),
// areaBindingsId: AreaBindingsId(areaBindingsId.getOrCrash()),
// areaMostUsedBy: AreaMostUsedBy(areaMostUsedBy.getOrCrash()),
// areaPermissions: AreaPermissions(areaPermissions.getOrCrash()),
// );
final AreaEntity areaEntity = AreaEntity(
uniqueId: AreaUniqueId.fromUniqueString(areaUniqueId.getOrCrash()),
cbjEntityName: AreaDefaultName(cbjEntityName.getOrCrash()),
background: AreaBackground(background.getOrCrash()),
areaTypes: AreaTypes(areaTypes.getOrCrash()),
entitiesId: AreaEntitiesId(areaDevicesId.getOrCrash()),
areaScenesId: AreaScenesId(areaScenesId.getOrCrash()),
areaRoutinesId: AreaRoutinesId(areaRoutinesId.getOrCrash()),
areaBindingsId: AreaBindingsId(areaBindingsId.getOrCrash()),
areaMostUsedBy: AreaMostUsedBy(areaMostUsedBy.getOrCrash()),
areaPermissions: AreaPermissions(areaPermissions.getOrCrash()),
);

// IAreaRepository.instance.create(areaEntity);
ConnectionsService.instance.setNewArea(areaEntity);
}

Future<void> _defaultNameChanged(String value) async {
setState(() {
cbjEntityName = AreaDefaultName(value);
authFailureOrSuccessOption = dartz.none();
});
}

Future<void> _areaTypesChanged(Set<String> value) async {
setState(() {
areaTypes = AreaTypes(value);
authFailureOrSuccessOption = dartz.none();
});
}

Expand Down Expand Up @@ -173,12 +170,16 @@ class _AddNewAreaFormState extends State<AddNewAreaForm> {
children: [
Expanded(
child: TextButton(
onPressed: () {
_createArea();
onPressed: () async {
SnackBarService().show(
context,
'Adding area',
);
await _createArea();
if (!mounted) {
return;
}

context.router.pop();
},
child: const TextAtom('ADD'),
Expand Down
Loading

0 comments on commit a7c785b

Please sign in to comment.